Search in sources :

Example 41 with ComponentMetadata

use of org.osgi.service.blueprint.reflect.ComponentMetadata in project aries by apache.

the class Parser method parseBeanArgument.

private BeanArgument parseBeanArgument(ComponentMetadata enclosingComponent, Element element) {
    int index = element.hasAttribute(INDEX_ATTRIBUTE) ? Integer.parseInt(element.getAttribute(INDEX_ATTRIBUTE)) : -1;
    String type = element.hasAttribute(TYPE_ATTRIBUTE) ? element.getAttribute(TYPE_ATTRIBUTE) : null;
    Metadata value = parseArgumentOrPropertyValue(element, enclosingComponent);
    return new BeanArgumentImpl(value, type, index);
}
Also used : BeanArgumentImpl(org.apache.aries.blueprint.reflect.BeanArgumentImpl) CollectionMetadata(org.osgi.service.blueprint.reflect.CollectionMetadata) ValueMetadata(org.osgi.service.blueprint.reflect.ValueMetadata) ServiceMetadata(org.osgi.service.blueprint.reflect.ServiceMetadata) NonNullMetadata(org.osgi.service.blueprint.reflect.NonNullMetadata) RefMetadata(org.osgi.service.blueprint.reflect.RefMetadata) ServiceReferenceMetadata(org.osgi.service.blueprint.reflect.ServiceReferenceMetadata) BeanMetadata(org.osgi.service.blueprint.reflect.BeanMetadata) NullMetadata(org.osgi.service.blueprint.reflect.NullMetadata) Metadata(org.osgi.service.blueprint.reflect.Metadata) PropsMetadata(org.osgi.service.blueprint.reflect.PropsMetadata) ComponentMetadata(org.osgi.service.blueprint.reflect.ComponentMetadata) IdRefMetadata(org.osgi.service.blueprint.reflect.IdRefMetadata) ReferenceMetadata(org.osgi.service.blueprint.reflect.ReferenceMetadata) MapMetadata(org.osgi.service.blueprint.reflect.MapMetadata) ReferenceListMetadata(org.osgi.service.blueprint.reflect.ReferenceListMetadata)

Example 42 with ComponentMetadata

use of org.osgi.service.blueprint.reflect.ComponentMetadata in project aries by apache.

the class BlueprintBeanFactory method registerBeanDefinition.

@Override
public void registerBeanDefinition(String beanName, BeanDefinition beanDefinition) throws BeanDefinitionStoreException {
    ComponentDefinitionRegistry registry = container.getComponentDefinitionRegistry();
    ComponentMetadata metadata = registry.getComponentDefinition(beanName);
    if (metadata != null && !(metadata instanceof SpringMetadata)) {
        throw new BeanDefinitionStoreException(beanDefinition.getResourceDescription(), beanName, "Cannot register bean definition [" + beanDefinition + "] for bean '" + beanName + "': There is already bound.");
    }
    super.registerBeanDefinition(beanName, beanDefinition);
    if (!beanDefinition.isAbstract()) {
        registry.registerComponentDefinition(new SpringMetadata(beanName));
    }
}
Also used : ComponentDefinitionRegistry(org.apache.aries.blueprint.ComponentDefinitionRegistry) BeanDefinitionStoreException(org.springframework.beans.factory.BeanDefinitionStoreException) ComponentMetadata(org.osgi.service.blueprint.reflect.ComponentMetadata)

Example 43 with ComponentMetadata

use of org.osgi.service.blueprint.reflect.ComponentMetadata in project aries by apache.

the class Parser method parseService.

private ComponentMetadata parseService(Element element, boolean topElement) {
    ServiceMetadataImpl service = new ServiceMetadataImpl();
    boolean hasInterfaceNameAttribute = false;
    if (topElement) {
        service.setId(getId(element));
        service.setActivation(parseActivation(element));
    } else {
        service.setActivation(ComponentMetadata.ACTIVATION_LAZY);
    }
    if (element.hasAttribute(INTERFACE_ATTRIBUTE)) {
        service.setInterfaceNames(Collections.singletonList(element.getAttribute(INTERFACE_ATTRIBUTE)));
        hasInterfaceNameAttribute = true;
    }
    if (element.hasAttribute(REF_ATTRIBUTE)) {
        service.setServiceComponent(new RefMetadataImpl(element.getAttribute(REF_ATTRIBUTE)));
    }
    if (element.hasAttribute(DEPENDS_ON_ATTRIBUTE)) {
        service.setDependsOn(parseList(element.getAttribute(DEPENDS_ON_ATTRIBUTE)));
    }
    String autoExport = element.hasAttribute(AUTO_EXPORT_ATTRIBUTE) ? element.getAttribute(AUTO_EXPORT_ATTRIBUTE) : AUTO_EXPORT_DEFAULT;
    if (AUTO_EXPORT_DISABLED.equals(autoExport)) {
        service.setAutoExport(ServiceMetadata.AUTO_EXPORT_DISABLED);
    } else if (AUTO_EXPORT_INTERFACES.equals(autoExport)) {
        service.setAutoExport(ServiceMetadata.AUTO_EXPORT_INTERFACES);
    } else if (AUTO_EXPORT_CLASS_HIERARCHY.equals(autoExport)) {
        service.setAutoExport(ServiceMetadata.AUTO_EXPORT_CLASS_HIERARCHY);
    } else if (AUTO_EXPORT_ALL.equals(autoExport)) {
        service.setAutoExport(ServiceMetadata.AUTO_EXPORT_ALL_CLASSES);
    } else {
        throw new ComponentDefinitionException("Illegal value (" + autoExport + ") for " + AUTO_EXPORT_ATTRIBUTE + " attribute");
    }
    String ranking = element.hasAttribute(RANKING_ATTRIBUTE) ? element.getAttribute(RANKING_ATTRIBUTE) : RANKING_DEFAULT;
    try {
        service.setRanking(Integer.parseInt(ranking));
    } catch (NumberFormatException e) {
        throw new ComponentDefinitionException("Attribute " + RANKING_ATTRIBUTE + " must be a valid integer (was: " + ranking + ")");
    }
    // Parse elements
    NodeList nl = element.getChildNodes();
    for (int i = 0; i < nl.getLength(); i++) {
        Node node = nl.item(i);
        if (node instanceof Element) {
            Element e = (Element) node;
            if (isBlueprintNamespace(e.getNamespaceURI())) {
                if (nodeNameEquals(e, INTERFACES_ELEMENT)) {
                    if (hasInterfaceNameAttribute) {
                        throw new ComponentDefinitionException("Only one of " + INTERFACE_ATTRIBUTE + " attribute or " + INTERFACES_ELEMENT + " element must be used");
                    }
                    service.setInterfaceNames(parseInterfaceNames(e));
                } else if (nodeNameEquals(e, SERVICE_PROPERTIES_ELEMENT)) {
                    List<MapEntry> entries = parseServiceProperties(e, service).getEntries();
                    service.setServiceProperties(entries);
                } else if (nodeNameEquals(e, REGISTRATION_LISTENER_ELEMENT)) {
                    service.addRegistrationListener(parseRegistrationListener(e, service));
                } else if (nodeNameEquals(e, BEAN_ELEMENT)) {
                    if (service.getServiceComponent() != null) {
                        throw new ComponentDefinitionException("Only one of " + REF_ATTRIBUTE + " attribute, " + BEAN_ELEMENT + " element, " + REFERENCE_ELEMENT + " element or " + REF_ELEMENT + " element can be set");
                    }
                    service.setServiceComponent((Target) parseBeanMetadata(e, false));
                } else if (nodeNameEquals(e, REF_ELEMENT)) {
                    if (service.getServiceComponent() != null) {
                        throw new ComponentDefinitionException("Only one of " + REF_ATTRIBUTE + " attribute, " + BEAN_ELEMENT + " element, " + REFERENCE_ELEMENT + " element or " + REF_ELEMENT + " element can be set");
                    }
                    String component = e.getAttribute(COMPONENT_ID_ATTRIBUTE);
                    if (component == null || component.length() == 0) {
                        throw new ComponentDefinitionException("Element " + REF_ELEMENT + " must have a valid " + COMPONENT_ID_ATTRIBUTE + " attribute");
                    }
                    service.setServiceComponent(new RefMetadataImpl(component));
                } else if (nodeNameEquals(e, REFERENCE_ELEMENT)) {
                    if (service.getServiceComponent() != null) {
                        throw new ComponentDefinitionException("Only one of " + REF_ATTRIBUTE + " attribute, " + BEAN_ELEMENT + " element, " + REFERENCE_ELEMENT + " element or " + REF_ELEMENT + " element can be set");
                    }
                    service.setServiceComponent((Target) parseReference(e, false));
                }
            }
        }
    }
    // Check service
    if (service.getServiceComponent() == null) {
        throw new ComponentDefinitionException("One of " + REF_ATTRIBUTE + " attribute, " + BEAN_ELEMENT + " element, " + REFERENCE_ELEMENT + " element or " + REF_ELEMENT + " element must be set");
    }
    // Check interface
    if (service.getAutoExport() == ServiceMetadata.AUTO_EXPORT_DISABLED && service.getInterfaces().isEmpty()) {
        throw new ComponentDefinitionException(INTERFACE_ATTRIBUTE + " attribute or " + INTERFACES_ELEMENT + " element must be set when " + AUTO_EXPORT_ATTRIBUTE + " is set to " + AUTO_EXPORT_DISABLED);
    }
    // Check for non-disabled auto-exports and interfaces
    if (service.getAutoExport() != ServiceMetadata.AUTO_EXPORT_DISABLED && !service.getInterfaces().isEmpty()) {
        throw new ComponentDefinitionException(INTERFACE_ATTRIBUTE + " attribute or  " + INTERFACES_ELEMENT + " element must not be set when " + AUTO_EXPORT_ATTRIBUTE + " is set to anything else than " + AUTO_EXPORT_DISABLED);
    }
    ComponentMetadata s = service;
    // Parse custom attributes
    s = handleCustomAttributes(element.getAttributes(), s);
    // Parse custom elements;
    s = handleCustomElements(element, s);
    return s;
}
Also used : ComponentDefinitionException(org.osgi.service.blueprint.container.ComponentDefinitionException) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element) ComponentMetadata(org.osgi.service.blueprint.reflect.ComponentMetadata) Target(org.osgi.service.blueprint.reflect.Target) ServiceMetadataImpl(org.apache.aries.blueprint.reflect.ServiceMetadataImpl) List(java.util.List) ArrayList(java.util.ArrayList) NodeList(org.w3c.dom.NodeList) RefMetadataImpl(org.apache.aries.blueprint.reflect.RefMetadataImpl) IdRefMetadataImpl(org.apache.aries.blueprint.reflect.IdRefMetadataImpl)

Example 44 with ComponentMetadata

use of org.osgi.service.blueprint.reflect.ComponentMetadata in project aries by apache.

the class Parser method parseBeanProperty.

public BeanProperty parseBeanProperty(ComponentMetadata enclosingComponent, Element element) {
    String name = element.hasAttribute(NAME_ATTRIBUTE) ? element.getAttribute(NAME_ATTRIBUTE) : null;
    Metadata value = parseArgumentOrPropertyValue(element, enclosingComponent);
    return new BeanPropertyImpl(name, value);
}
Also used : BeanPropertyImpl(org.apache.aries.blueprint.reflect.BeanPropertyImpl) CollectionMetadata(org.osgi.service.blueprint.reflect.CollectionMetadata) ValueMetadata(org.osgi.service.blueprint.reflect.ValueMetadata) ServiceMetadata(org.osgi.service.blueprint.reflect.ServiceMetadata) NonNullMetadata(org.osgi.service.blueprint.reflect.NonNullMetadata) RefMetadata(org.osgi.service.blueprint.reflect.RefMetadata) ServiceReferenceMetadata(org.osgi.service.blueprint.reflect.ServiceReferenceMetadata) BeanMetadata(org.osgi.service.blueprint.reflect.BeanMetadata) NullMetadata(org.osgi.service.blueprint.reflect.NullMetadata) Metadata(org.osgi.service.blueprint.reflect.Metadata) PropsMetadata(org.osgi.service.blueprint.reflect.PropsMetadata) ComponentMetadata(org.osgi.service.blueprint.reflect.ComponentMetadata) IdRefMetadata(org.osgi.service.blueprint.reflect.IdRefMetadata) ReferenceMetadata(org.osgi.service.blueprint.reflect.ReferenceMetadata) MapMetadata(org.osgi.service.blueprint.reflect.MapMetadata) ReferenceListMetadata(org.osgi.service.blueprint.reflect.ReferenceListMetadata)

Example 45 with ComponentMetadata

use of org.osgi.service.blueprint.reflect.ComponentMetadata in project aries by apache.

the class BlueprintMetadata method getComponentMetadata.

public CompositeData getComponentMetadata(long containerServiceId, String componentId) throws IOException {
    BlueprintContainer container = getBlueprintContainer(containerServiceId);
    ComponentMetadata componentMetadata = container.getComponentMetadata(componentId);
    BPMetadata metadata = Util.metadata2BPMetadata(componentMetadata);
    return metadata.asCompositeData();
}
Also used : BlueprintContainer(org.osgi.service.blueprint.container.BlueprintContainer) BPMetadata(org.apache.aries.jmx.blueprint.codec.BPMetadata) ComponentMetadata(org.osgi.service.blueprint.reflect.ComponentMetadata)

Aggregations

ComponentMetadata (org.osgi.service.blueprint.reflect.ComponentMetadata)45 BeanMetadata (org.osgi.service.blueprint.reflect.BeanMetadata)22 RefMetadata (org.osgi.service.blueprint.reflect.RefMetadata)17 ServiceMetadata (org.osgi.service.blueprint.reflect.ServiceMetadata)17 Metadata (org.osgi.service.blueprint.reflect.Metadata)16 CollectionMetadata (org.osgi.service.blueprint.reflect.CollectionMetadata)15 ValueMetadata (org.osgi.service.blueprint.reflect.ValueMetadata)15 ComponentDefinitionException (org.osgi.service.blueprint.container.ComponentDefinitionException)14 MapMetadata (org.osgi.service.blueprint.reflect.MapMetadata)14 ServiceReferenceMetadata (org.osgi.service.blueprint.reflect.ServiceReferenceMetadata)13 NullMetadata (org.osgi.service.blueprint.reflect.NullMetadata)12 ReferenceListMetadata (org.osgi.service.blueprint.reflect.ReferenceListMetadata)12 ReferenceMetadata (org.osgi.service.blueprint.reflect.ReferenceMetadata)12 Node (org.w3c.dom.Node)12 ArrayList (java.util.ArrayList)11 IdRefMetadata (org.osgi.service.blueprint.reflect.IdRefMetadata)11 Element (org.w3c.dom.Element)11 PropsMetadata (org.osgi.service.blueprint.reflect.PropsMetadata)10 NodeList (org.w3c.dom.NodeList)10 NonNullMetadata (org.osgi.service.blueprint.reflect.NonNullMetadata)9