public String[] getServices() { if (m_componentMetadata.getServiceMetadata() != null) { return m_componentMetadata.getServiceMetadata().getProvides(); } return null; }
private List<DependencyManager<S, ?>> loadDependencyManagers(ComponentMetadata metadata) { List<DependencyManager<S, ?>> depMgrList = new ArrayList<DependencyManager<S, ?>>(metadata.getDependencies().size()); // If this component has got dependencies, create dependency managers for each one of them. if (metadata.getDependencies().size() != 0) { int index = 0; for (ReferenceMetadata currentdependency : metadata.getDependencies()) { DependencyManager<S, ?> depmanager = new DependencyManager(this, currentdependency, index++); depMgrList.add(depmanager); } } return depMgrList; }
/** * Method to actually emit the log message. If the LogService is available, the message will be * logged through the LogService. Otherwise the message is logged to stdout (or stderr in case of * LOG_ERROR level messages), * * @param level The log level to log the message at * @param message The message to log * @param ex An optional <code>Throwable</code> whose stack trace is written, or <code>null</code> * to not log a stack trace. */ public void log(int level, String message, ComponentMetadata metadata, Throwable ex) { if (isLogEnabled(level)) { // prepend the metadata name to the message if (metadata != null) { message = "[" + metadata.getName() + "] " + message; } Object logger = m_logService.getService(); if (logger == null) { Activator.log(level, getBundleContext().getBundle(), message, ex); } else { ((LogService) logger).log(level, message, ex); } } }
private void loadDescriptor(final URL descriptorURL) { // simple path for log messages final String descriptorLocation = descriptorURL.getPath(); InputStream stream = null; try { stream = descriptorURL.openStream(); BufferedReader in = new BufferedReader(new InputStreamReader(stream)); XmlHandler handler = new XmlHandler(m_context.getBundle(), this); KXml2SAXParser parser; parser = new KXml2SAXParser(in); parser.parseXML(handler); // 112.4.2 Component descriptors may contain a single, root component element // or one or more component elements embedded in a larger document Iterator i = handler.getComponentMetadataList().iterator(); while (i.hasNext()) { ComponentMetadata metadata = (ComponentMetadata) i.next(); try { // check and reserve the component name m_componentRegistry.checkComponentName(metadata.getName()); // validate the component metadata metadata.validate(this); // Request creation of the component manager ComponentHolder holder = m_componentRegistry.createComponentHolder(this, metadata); // register the component after validation m_componentRegistry.registerComponentHolder(metadata.getName(), holder); m_managers.add(holder); // enable the component if (metadata.isEnabled()) { holder.enableComponents(); } } catch (Throwable t) { // There is a problem with this particular component, we'll log the error // and proceed to the next one log(LogService.LOG_ERROR, "Cannot register Component", metadata, t); // make sure the name is not reserved any more m_componentRegistry.unregisterComponentHolder(metadata.getName()); } } } catch (IOException ex) { // 112.4.1 If an XML document specified by the header cannot be located in the bundle and its // attached // fragments, SCR must log an error message with the Log Service, if present, and continue. log( LogService.LOG_ERROR, "Problem reading descriptor entry ''{0}''", new Object[] {descriptorLocation}, null, ex); } catch (Exception ex) { log( LogService.LOG_ERROR, "General problem with descriptor entry ''{0}''", new Object[] {descriptorLocation}, null, ex); } finally { if (stream != null) { try { stream.close(); } catch (IOException ignore) { } } } }
public boolean isServiceFactory() { return m_componentMetadata.getServiceMetadata() != null && m_componentMetadata.getServiceMetadata().isServiceFactory(); }
public boolean isConfigurationPidDeclared() { return m_componentMetadata.isConfigurationPidDeclared(); }
public String getConfigurationPid() { return m_componentMetadata.getConfigurationPid(); }
public String getModified() { return m_componentMetadata.getModified(); }
public boolean isDeactivateDeclared() { return m_componentMetadata.isDeactivateDeclared(); }
public String getDeactivate() { return m_componentMetadata.getDeactivate(); }
public boolean isDefaultEnabled() { return m_componentMetadata.isEnabled(); }
public boolean isImmediate() { return m_componentMetadata.isImmediate(); }
public String getFactory() { return m_componentMetadata.getFactoryIdentifier(); }
public String getClassName() { return m_componentMetadata.getImplementationClassName(); }
public String getName() { return m_componentMetadata.getName(); }
protected AbstractComponentManager( BundleComponentActivator activator, ComponentMetadata metadata, ComponentMethods componentMethods, boolean factoryInstance) { m_factoryInstance = factoryInstance; m_activator = activator; m_componentMetadata = metadata; this.m_componentMethods = componentMethods; m_componentId = -1; m_dependencyManagers = loadDependencyManagers(metadata); m_stateLock = new ReentrantLock(true); // dump component details if (isLogEnabled(LogService.LOG_DEBUG)) { log( LogService.LOG_DEBUG, "Component {0} created: DS={1}, implementation={2}, immediate={3}, default-enabled={4}, factory={5}, configuration-policy={6}, activate={7}, deactivate={8}, modified={9} configuration-pid={10}", new Object[] { metadata.getName(), metadata.getNamespaceCode(), metadata.getImplementationClassName(), metadata.isImmediate(), metadata.isEnabled(), metadata.getFactoryIdentifier(), metadata.getConfigurationPolicy(), metadata.getActivate(), metadata.getDeactivate(), metadata.getModified(), metadata.getConfigurationPid() }, null); if (metadata.getServiceMetadata() != null) { log( LogService.LOG_DEBUG, "Component {0} Services: servicefactory={1}, services={2}", new Object[] { metadata.getName(), Boolean.valueOf(metadata.getServiceMetadata().isServiceFactory()), Arrays.asList(metadata.getServiceMetadata().getProvides()) }, null); } if (metadata.getProperties() != null) { log( LogService.LOG_DEBUG, "Component {0} Properties: {1}", new Object[] {metadata.getName(), metadata.getProperties()}, null); } } }