Search in sources :

Example 6 with ComponentMetadata

use of org.apache.felix.scr.impl.metadata.ComponentMetadata in project felix by apache.

the class ConfiguredComponentHolderTest method createComponentMetadata.

private static ComponentMetadata createComponentMetadata(String name) {
    final ComponentMetadata metadata = new ComponentMetadata(DSVersion.DS11);
    metadata.setName(name);
    metadata.setImplementationClassName(Object.class.getName());
    metadata.validate(null);
    return metadata;
}
Also used : ComponentMetadata(org.apache.felix.scr.impl.metadata.ComponentMetadata)

Example 7 with ComponentMetadata

use of org.apache.felix.scr.impl.metadata.ComponentMetadata in project felix by apache.

the class ActivateMethodTest method newContainer.

private ComponentContainer newContainer() {
    final ComponentMetadata metadata = newMetadata();
    ComponentContainer container = new ComponentContainer() {

        @Override
        public ComponentActivator getActivator() {
            final ComponentActivator ca = Mockito.mock(ComponentActivator.class);
            Mockito.when(ca.getBundleContext()).thenReturn(Mockito.mock(BundleContext.class));
            return ca;
        }

        @Override
        public ComponentMetadata getComponentMetadata() {
            return metadata;
        }

        @Override
        public void disposed(SingleComponentManager component) {
        }

        public boolean isEnabled() {
            return false;
        }

        @Override
        public ComponentLogger getLogger() {
            return new MockComponentLogger();
        }
    };
    return container;
}
Also used : SingleComponentManager(org.apache.felix.scr.impl.manager.SingleComponentManager) ComponentActivator(org.apache.felix.scr.impl.manager.ComponentActivator) ComponentContainer(org.apache.felix.scr.impl.manager.ComponentContainer) MockComponentLogger(org.apache.felix.scr.impl.logger.MockComponentLogger) ComponentMetadata(org.apache.felix.scr.impl.metadata.ComponentMetadata) BundleContext(org.osgi.framework.BundleContext)

Example 8 with ComponentMetadata

use of org.apache.felix.scr.impl.metadata.ComponentMetadata in project felix by apache.

the class ActivateMethodTest method newMetadata.

private ComponentMetadata newMetadata() {
    ComponentMetadata metadata = new ComponentMetadata(DSVersion.DS11);
    metadata.setName("foo");
    metadata.setImplementationClassName(Object.class.getName());
    metadata.validate();
    return metadata;
}
Also used : Level1Object(org.apache.felix.scr.impl.metadata.instances.Level1Object) BaseObject(org.apache.felix.scr.impl.metadata.instances.BaseObject) Level3Object(org.apache.felix.scr.impl.metadata.instances.Level3Object) Level2Object(org.apache.felix.scr.impl.metadata.instances2.Level2Object) ComponentMetadata(org.apache.felix.scr.impl.metadata.ComponentMetadata)

Example 9 with ComponentMetadata

use of org.apache.felix.scr.impl.metadata.ComponentMetadata in project felix by apache.

the class ServiceComponentRuntimeImpl method holderToDescription.

private ComponentDescriptionDTO holderToDescription(ComponentHolder<?> holder) {
    ComponentDescriptionDTO dto = new ComponentDescriptionDTO();
    ComponentMetadata m = holder.getComponentMetadata();
    dto.activate = m.getActivate();
    dto.bundle = bundleToDTO(holder.getActivator().getBundleContext());
    // immediately return if bundle is not active anymore
    if (dto.bundle == null) {
        return null;
    }
    dto.configurationPid = m.getConfigurationPid().toArray(new String[m.getConfigurationPid().size()]);
    dto.configurationPolicy = m.getConfigurationPolicy();
    dto.deactivate = m.getDeactivate();
    dto.defaultEnabled = m.isEnabled();
    dto.factory = m.getFactoryIdentifier();
    dto.immediate = m.isImmediate();
    dto.implementationClass = m.getImplementationClassName();
    dto.modified = m.getModified();
    dto.name = m.getName();
    dto.properties = deepCopy(m.getProperties());
    dto.references = refsToDTO(m.getDependencies());
    dto.scope = m.getServiceMetadata() == null ? null : m.getServiceMetadata().getScope().name();
    dto.serviceInterfaces = m.getServiceMetadata() == null ? EMPTY : m.getServiceMetadata().getProvides();
    return dto;
}
Also used : ComponentDescriptionDTO(org.osgi.service.component.runtime.dto.ComponentDescriptionDTO) ComponentMetadata(org.apache.felix.scr.impl.metadata.ComponentMetadata)

Example 10 with ComponentMetadata

use of org.apache.felix.scr.impl.metadata.ComponentMetadata in project felix by apache.

the class XmlHandler method startElement.

/**
 * Method called when a tag opens
 *
 * @param   uri
 * @param   localName
 * @param   attributes
 * @exception   ParseException
 */
public void startElement(String uri, String localName, Attributes attributes) throws ParseException {
    // So we check this for the first element, we receive.
    if (firstElement) {
        firstElement = false;
        if (localName.equals("component") && "".equals(uri)) {
            overrideNamespace = NAMESPACE_URI;
        }
    }
    if (overrideNamespace != null && "".equals(uri)) {
        uri = overrideNamespace;
    }
    // the namespace - we allow both: with or without namespace!
    if (this.isComponent && "".equals(uri)) {
        uri = NAMESPACE_URI;
    }
    // get the namespace code for the namespace uri
    DSVersion namespaceCode = NAMESPACE_CODE_MAP.get(uri);
    // from now on uri points to the namespace
    if (namespaceCode != null) {
        try {
            // 112.4.3 Component Element
            if (localName.equals("component")) {
                this.isComponent = true;
                // Create a new ComponentMetadata
                m_currentComponent = new ComponentMetadata(namespaceCode);
                // name attribute is optional (since DS 1.1)
                if (attributes.getAttribute("name") != null) {
                    m_currentComponent.setName(attributes.getAttribute("name"));
                }
                // enabled attribute is optional
                if (attributes.getAttribute("enabled") != null) {
                    m_currentComponent.setEnabled(attributes.getAttribute("enabled").equals("true"));
                }
                // immediate attribute is optional
                if (attributes.getAttribute("immediate") != null) {
                    m_currentComponent.setImmediate(attributes.getAttribute("immediate").equals("true"));
                }
                // factory attribute is optional
                if (attributes.getAttribute("factory") != null) {
                    m_currentComponent.setFactoryIdentifier(attributes.getAttribute("factory"));
                }
                // configuration-policy is optional (since DS 1.1)
                if (attributes.getAttribute("configuration-policy") != null) {
                    m_currentComponent.setConfigurationPolicy(attributes.getAttribute("configuration-policy"));
                }
                // activate attribute is optional (since DS 1.1)
                if (attributes.getAttribute("activate") != null) {
                    m_currentComponent.setActivate(attributes.getAttribute("activate"));
                }
                // deactivate attribute is optional (since DS 1.1)
                if (attributes.getAttribute("deactivate") != null) {
                    m_currentComponent.setDeactivate(attributes.getAttribute("deactivate"));
                }
                // modified attribute is optional (since DS 1.1)
                if (attributes.getAttribute("modified") != null) {
                    m_currentComponent.setModified(attributes.getAttribute("modified"));
                }
                // configuration-pid attribute is optional (since DS 1.2)
                String configurationPidString = attributes.getAttribute("configuration-pid");
                if (configurationPidString != null) {
                    String[] configurationPid = configurationPidString.split(" ");
                    m_currentComponent.setConfigurationPid(configurationPid);
                }
                m_currentComponent.setConfigurableServiceProperties("true".equals(attributes.getAttribute(NAMESPACE_URI_1_0_FELIX_EXTENSIONS, CONFIGURABLE_SERVICE_PROPERTIES)));
                m_currentComponent.setPersistentFactoryComponent("true".equals(attributes.getAttribute(NAMESPACE_URI_1_0_FELIX_EXTENSIONS, PERSISTENT_FACTORY_COMPONENT)));
                m_currentComponent.setDeleteCallsModify("true".equals(attributes.getAttribute(NAMESPACE_URI_1_0_FELIX_EXTENSIONS, DELETE_CALLS_MODIFY)));
                if (attributes.getAttribute(NAMESPACE_URI_1_0_FELIX_EXTENSIONS, OBSOLETE_FACTORY_COMPONENT_FACTORY) != null) {
                    m_currentComponent.setObsoleteFactoryComponentFactory("true".equals(attributes.getAttribute(NAMESPACE_URI_1_0_FELIX_EXTENSIONS, OBSOLETE_FACTORY_COMPONENT_FACTORY)));
                } else if (!namespaceCode.isDS13()) {
                    m_currentComponent.setObsoleteFactoryComponentFactory(m_globalObsoleteFactoryComponentFactory);
                }
                m_currentComponent.setConfigureWithInterfaces("true".equals(attributes.getAttribute(NAMESPACE_URI_1_0_FELIX_EXTENSIONS, CONFIGURE_WITH_INTERFACES)));
                m_currentComponent.setDelayedKeepInstances(m_globalDelayedKeepInstances || "true".equals(attributes.getAttribute(NAMESPACE_URI_1_0_FELIX_EXTENSIONS, DELAYED_KEEP_INSTANCES)));
                // Add this component to the list
                m_components.add(m_currentComponent);
            } else // not inside a component element, ignore current element
            if (!this.isComponent) {
                m_logger.log(LogService.LOG_DEBUG, "Not currently parsing a component; ignoring element {0} (bundle {1})", new Object[] { localName, m_bundle.getLocation() }, null, null, null);
            } else // 112.4.4 Implementation
            if (localName.equals("implementation")) {
                // Set the implementation class name (mandatory)
                m_currentComponent.setImplementationClassName(attributes.getAttribute("class"));
            } else // 112.4.5 [...] Property Elements
            if (localName.equals("property")) {
                PropertyMetadata prop = new PropertyMetadata();
                // name attribute is mandatory
                prop.setName(attributes.getAttribute("name"));
                // type attribute is optional
                if (attributes.getAttribute("type") != null) {
                    prop.setType(attributes.getAttribute("type"));
                }
                // 112.4.5: If the value attribute is specified, the body of the element is ignored.
                if (attributes.getAttribute("value") != null) {
                    prop.setValue(attributes.getAttribute("value"));
                    m_currentComponent.addProperty(prop);
                } else {
                    // hold the metadata pending
                    m_pendingProperty = prop;
                }
            } else // 112.4.5 Properties [...] Elements
            if (localName.equals("properties")) {
                readPropertiesEntry(attributes.getAttribute("entry"));
            } else // 112.4.6 Service Element
            if (localName.equals("service")) {
                m_currentService = new ServiceMetadata();
                // servicefactory attribute is optional
                if (attributes.getAttribute("servicefactory") != null) {
                    m_currentService.setServiceFactory(attributes.getAttribute("servicefactory").equals("true"));
                }
                if (attributes.getAttribute("scope") != null) {
                    m_currentService.setScope(attributes.getAttribute("scope"));
                }
                m_currentComponent.setService(m_currentService);
            } else if (localName.equals("provide")) {
                m_currentService.addProvide(attributes.getAttribute("interface"));
            } else // 112.4.7 Reference element
            if (localName.equals("reference")) {
                ReferenceMetadata ref = new ReferenceMetadata();
                // name attribute is optional (since DS 1.1)
                if (attributes.getAttribute("name") != null) {
                    ref.setName(attributes.getAttribute("name"));
                }
                ref.setInterface(attributes.getAttribute("interface"));
                // Cardinality
                if (attributes.getAttribute("cardinality") != null) {
                    ref.setCardinality(attributes.getAttribute("cardinality"));
                }
                if (attributes.getAttribute("policy") != null) {
                    ref.setPolicy(attributes.getAttribute("policy"));
                }
                if (attributes.getAttribute("policy-option") != null) {
                    ref.setPolicyOption(attributes.getAttribute("policy-option"));
                }
                if (attributes.getAttribute("scope") != null) {
                    ref.setScope(attributes.getAttribute("scope"));
                }
                if (attributes.getAttribute("target") != null) {
                    ref.setTarget(attributes.getAttribute("target"));
                    PropertyMetadata prop = new PropertyMetadata();
                    prop.setName((ref.getName() == null ? ref.getInterface() : ref.getName()) + ".target");
                    prop.setValue(attributes.getAttribute("target"));
                    m_currentComponent.addProperty(prop);
                }
                // method reference
                ref.setBind(attributes.getAttribute("bind"));
                ref.setUpdated(attributes.getAttribute("updated"));
                ref.setUnbind(attributes.getAttribute("unbind"));
                // field reference
                ref.setField(attributes.getAttribute("field"));
                ref.setFieldOption(attributes.getAttribute("field-option"));
                ref.setFieldCollectionType(attributes.getAttribute("field-collection-type"));
                m_currentComponent.addDependency(ref);
            } else // used by the Maven SCR Plugin, which is just silently ignored)
            if (!localName.equals("components")) {
                m_logger.log(LogService.LOG_DEBUG, "Ignoring unsupported element {0} (bundle {1})", new Object[] { localName, m_bundle.getLocation() }, null, null, null);
            }
        } catch (Exception ex) {
            throw new ParseException("Exception during parsing", ex);
        }
    } else // used by the Maven SCR Plugin, which is just silently ignored)
    if (!localName.equals("components")) {
        m_logger.log(LogService.LOG_DEBUG, "Ignoring unsupported element '{'{0}'}'{1} (bundle {2})", new Object[] { uri, localName, m_bundle.getLocation() }, null, null, null);
    }
}
Also used : DSVersion(org.apache.felix.scr.impl.metadata.DSVersion) PropertyMetadata(org.apache.felix.scr.impl.metadata.PropertyMetadata) ParseException(org.apache.felix.scr.impl.parser.ParseException) ComponentMetadata(org.apache.felix.scr.impl.metadata.ComponentMetadata) ServiceMetadata(org.apache.felix.scr.impl.metadata.ServiceMetadata) ReferenceMetadata(org.apache.felix.scr.impl.metadata.ReferenceMetadata) IOException(java.io.IOException) ParseException(org.apache.felix.scr.impl.parser.ParseException)

Aggregations

ComponentMetadata (org.apache.felix.scr.impl.metadata.ComponentMetadata)17 ComponentContainer (org.apache.felix.scr.impl.manager.ComponentContainer)3 SingleComponentManager (org.apache.felix.scr.impl.manager.SingleComponentManager)3 Bundle (org.osgi.framework.Bundle)3 BundleContext (org.osgi.framework.BundleContext)3 IOException (java.io.IOException)2 Field (java.lang.reflect.Field)2 Dictionary (java.util.Dictionary)2 Hashtable (java.util.Hashtable)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 ComponentMethodsImpl (org.apache.felix.scr.impl.inject.ComponentMethodsImpl)2 TargetedPID (org.apache.felix.scr.impl.metadata.TargetedPID)2 BaseObject (org.apache.felix.scr.impl.metadata.instances.BaseObject)2 Level1Object (org.apache.felix.scr.impl.metadata.instances.Level1Object)2 Level3Object (org.apache.felix.scr.impl.metadata.instances.Level3Object)2 Level2Object (org.apache.felix.scr.impl.metadata.instances2.Level2Object)2 Test (org.junit.Test)2 ServiceRegistration (org.osgi.framework.ServiceRegistration)2 ComponentException (org.osgi.service.component.ComponentException)2 BufferedReader (java.io.BufferedReader)1