Search in sources :

Example 21 with Metadata

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

the class CmNamespaceHandler method parsePropertyPlaceholder.

private ComponentMetadata parsePropertyPlaceholder(ParserContext context, Element element) {
    MutableBeanMetadata metadata = context.createMetadata(MutableBeanMetadata.class);
    metadata.setProcessor(true);
    metadata.setId(getId(context, element));
    metadata.setScope(BeanMetadata.SCOPE_SINGLETON);
    metadata.setRuntimeClass(CmPropertyPlaceholder.class);
    metadata.setInitMethod("init");
    metadata.setDestroyMethod("destroy");
    metadata.addProperty("blueprintContainer", createRef(context, "blueprintContainer"));
    metadata.addProperty("configAdmin", createConfigurationAdminRef(context));
    metadata.addProperty("persistentId", createValue(context, element.getAttribute(PERSISTENT_ID_ATTRIBUTE)));
    String prefix = element.hasAttribute(PLACEHOLDER_PREFIX_ATTRIBUTE) ? element.getAttribute(PLACEHOLDER_PREFIX_ATTRIBUTE) : "${";
    metadata.addProperty("placeholderPrefix", createValue(context, prefix));
    String suffix = element.hasAttribute(PLACEHOLDER_SUFFIX_ATTRIBUTE) ? element.getAttribute(PLACEHOLDER_SUFFIX_ATTRIBUTE) : "}";
    metadata.addProperty("placeholderSuffix", createValue(context, suffix));
    String defaultsRef = element.hasAttribute(DEFAULTS_REF_ATTRIBUTE) ? element.getAttribute(DEFAULTS_REF_ATTRIBUTE) : null;
    if (defaultsRef != null) {
        metadata.addProperty("defaultProperties", createRef(context, defaultsRef));
    }
    String ignoreMissingLocations = extractIgnoreMissingLocations(element);
    if (ignoreMissingLocations != null) {
        metadata.addProperty("ignoreMissingLocations", createValue(context, ignoreMissingLocations));
    }
    String systemProperties = extractSystemPropertiesAttribute(element);
    if (systemProperties == null) {
        systemProperties = SYSTEM_PROPERTIES_NEVER;
    }
    metadata.addProperty("systemProperties", createValue(context, systemProperties));
    String updateStrategy = element.getAttribute(UPDATE_STRATEGY_ATTRIBUTE);
    if (updateStrategy != null) {
        metadata.addProperty("updateStrategy", createValue(context, updateStrategy));
    }
    metadata.addProperty("managedObjectManager", createRef(context, MANAGED_OBJECT_MANAGER_NAME));
    // Parse elements
    List<String> locations = new ArrayList<String>();
    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 (isCmNamespace(e.getNamespaceURI())) {
                if (nodeNameEquals(e, DEFAULT_PROPERTIES_ELEMENT)) {
                    if (defaultsRef != null) {
                        throw new ComponentDefinitionException("Only one of " + DEFAULTS_REF_ATTRIBUTE + " attribute or " + DEFAULT_PROPERTIES_ELEMENT + " element is allowed");
                    }
                    Metadata props = parseDefaultProperties(context, metadata, e);
                    metadata.addProperty("defaultProperties", props);
                }
            } else if (isExtNamespace(e.getNamespaceURI())) {
                if (nodeNameEquals(e, LOCATION_ELEMENT)) {
                    locations.add(getTextValue(e));
                }
            }
        }
    }
    if (!locations.isEmpty()) {
        metadata.addProperty("locations", createList(context, locations));
    }
    PlaceholdersUtils.validatePlaceholder(metadata, context.getComponentDefinitionRegistry());
    return metadata;
}
Also used : MutableBeanMetadata(org.apache.aries.blueprint.mutable.MutableBeanMetadata) ComponentDefinitionException(org.osgi.service.blueprint.container.ComponentDefinitionException) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) CollectionMetadata(org.osgi.service.blueprint.reflect.CollectionMetadata) ValueMetadata(org.osgi.service.blueprint.reflect.ValueMetadata) Metadata(org.osgi.service.blueprint.reflect.Metadata) ServiceMetadata(org.osgi.service.blueprint.reflect.ServiceMetadata) RefMetadata(org.osgi.service.blueprint.reflect.RefMetadata) MutableReferenceMetadata(org.apache.aries.blueprint.mutable.MutableReferenceMetadata) ComponentMetadata(org.osgi.service.blueprint.reflect.ComponentMetadata) MutableRefMetadata(org.apache.aries.blueprint.mutable.MutableRefMetadata) IdRefMetadata(org.osgi.service.blueprint.reflect.IdRefMetadata) MutableIdRefMetadata(org.apache.aries.blueprint.mutable.MutableIdRefMetadata) MutableComponentMetadata(org.apache.aries.blueprint.mutable.MutableComponentMetadata) ReferenceMetadata(org.osgi.service.blueprint.reflect.ReferenceMetadata) BeanMetadata(org.osgi.service.blueprint.reflect.BeanMetadata) MapMetadata(org.osgi.service.blueprint.reflect.MapMetadata) MutableCollectionMetadata(org.apache.aries.blueprint.mutable.MutableCollectionMetadata) MutableBeanMetadata(org.apache.aries.blueprint.mutable.MutableBeanMetadata) MutableValueMetadata(org.apache.aries.blueprint.mutable.MutableValueMetadata) MutableMapMetadata(org.apache.aries.blueprint.mutable.MutableMapMetadata)

Example 22 with Metadata

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

the class AbstractParserProxy method traverse.

/**
	   * Traverse to find all nested {@link ComponentMetadata} instances
	   * @param metadata
	   * @param output
	   */
private void traverse(Metadata metadata, Set<ComponentMetadata> output) {
    if (metadata instanceof ComponentMetadata) {
        traverseComponent((ComponentMetadata) metadata, output);
    } else if (metadata instanceof CollectionMetadata) {
        CollectionMetadata collection = (CollectionMetadata) metadata;
        for (Metadata v : collection.getValues()) traverse(v, output);
    } else if (metadata instanceof MapMetadata) {
        MapMetadata map = (MapMetadata) metadata;
        for (MapEntry e : map.getEntries()) {
            traverse(e.getKey(), output);
            traverse(e.getValue(), output);
        }
    }
}
Also used : CollectionMetadata(org.osgi.service.blueprint.reflect.CollectionMetadata) MapEntry(org.osgi.service.blueprint.reflect.MapEntry) CollectionMetadata(org.osgi.service.blueprint.reflect.CollectionMetadata) ValueMetadata(org.osgi.service.blueprint.reflect.ValueMetadata) Metadata(org.osgi.service.blueprint.reflect.Metadata) WrappedServiceMetadata(org.apache.aries.application.modelling.WrappedServiceMetadata) ServiceMetadata(org.osgi.service.blueprint.reflect.ServiceMetadata) RefMetadata(org.osgi.service.blueprint.reflect.RefMetadata) ComponentMetadata(org.osgi.service.blueprint.reflect.ComponentMetadata) ServiceReferenceMetadata(org.osgi.service.blueprint.reflect.ServiceReferenceMetadata) BeanMetadata(org.osgi.service.blueprint.reflect.BeanMetadata) MapMetadata(org.osgi.service.blueprint.reflect.MapMetadata) ReferenceListMetadata(org.osgi.service.blueprint.reflect.ReferenceListMetadata) ComponentMetadata(org.osgi.service.blueprint.reflect.ComponentMetadata) MapMetadata(org.osgi.service.blueprint.reflect.MapMetadata)

Example 23 with Metadata

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

the class AbstractPropertyPlaceholder method processCollectionMetadata.

protected Metadata processCollectionMetadata(CollectionMetadata metadata) {
    List<Metadata> values = new ArrayList<Metadata>(metadata.getValues());
    if (!!!values.isEmpty()) {
        try {
            if (metadata instanceof MutableCollectionMetadata) {
                processingStack.add("Collection type: " + metadata.getValueType() + "->");
                MutableCollectionMetadata mcm = (MutableCollectionMetadata) metadata;
                for (Metadata value : values) {
                    mcm.removeValue(value);
                }
                for (Metadata value : values) {
                    mcm.addValue(processMetadata(value));
                }
            } else {
                printWarning(metadata, "Collection type: " + metadata.getValueType());
                processingStack.add("Collection type: " + metadata.getValueType() + "->");
                for (Metadata value : values) {
                    processMetadata(value);
                }
            }
        } finally {
            processingStack.removeLast();
        }
    }
    return metadata;
}
Also used : ArrayList(java.util.ArrayList) CollectionMetadata(org.osgi.service.blueprint.reflect.CollectionMetadata) ValueMetadata(org.osgi.service.blueprint.reflect.ValueMetadata) Metadata(org.osgi.service.blueprint.reflect.Metadata) MutablePropsMetadata(org.apache.aries.blueprint.mutable.MutablePropsMetadata) PropsMetadata(org.osgi.service.blueprint.reflect.PropsMetadata) PassThroughMetadata(org.apache.aries.blueprint.PassThroughMetadata) NonNullMetadata(org.osgi.service.blueprint.reflect.NonNullMetadata) BeanMetadata(org.osgi.service.blueprint.reflect.BeanMetadata) MapMetadata(org.osgi.service.blueprint.reflect.MapMetadata) MutableCollectionMetadata(org.apache.aries.blueprint.mutable.MutableCollectionMetadata) MutableBeanMetadata(org.apache.aries.blueprint.mutable.MutableBeanMetadata) MutableMapMetadata(org.apache.aries.blueprint.mutable.MutableMapMetadata) MutableCollectionMetadata(org.apache.aries.blueprint.mutable.MutableCollectionMetadata)

Example 24 with Metadata

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

the class Parser method parseRegistrationListener.

public RegistrationListener parseRegistrationListener(Element element, ComponentMetadata enclosingComponent) {
    RegistrationListenerImpl listener = new RegistrationListenerImpl();
    Metadata listenerComponent = null;
    // Parse attributes
    if (element.hasAttribute(REF_ATTRIBUTE)) {
        listenerComponent = new RefMetadataImpl(element.getAttribute(REF_ATTRIBUTE));
    }
    String registrationMethod = null;
    if (element.hasAttribute(REGISTRATION_METHOD_ATTRIBUTE)) {
        registrationMethod = element.getAttribute(REGISTRATION_METHOD_ATTRIBUTE);
        listener.setRegistrationMethod(registrationMethod);
    }
    String unregistrationMethod = null;
    if (element.hasAttribute(UNREGISTRATION_METHOD_ATTRIBUTE)) {
        unregistrationMethod = element.getAttribute(UNREGISTRATION_METHOD_ATTRIBUTE);
        listener.setUnregistrationMethod(unregistrationMethod);
    }
    if (registrationMethod == null && unregistrationMethod == null) {
        throw new ComponentDefinitionException("One of " + REGISTRATION_METHOD_ATTRIBUTE + " or " + UNREGISTRATION_METHOD_ATTRIBUTE + " must be set");
    }
    // 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, REF_ELEMENT)) {
                    if (listenerComponent != null) {
                        throw new ComponentDefinitionException("Only one of " + REF_ATTRIBUTE + " attribute, " + REF_ELEMENT + ", " + BEAN_ELEMENT + ", " + REFERENCE_ELEMENT + ", " + SERVICE_ELEMENT + " or custom 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");
                    }
                    listenerComponent = new RefMetadataImpl(component);
                } else if (nodeNameEquals(e, BEAN_ELEMENT)) {
                    if (listenerComponent != null) {
                        throw new ComponentDefinitionException("Only one of " + REF_ATTRIBUTE + " attribute, " + REF_ELEMENT + ", " + BEAN_ELEMENT + ", " + REFERENCE_ELEMENT + ", " + SERVICE_ELEMENT + " or custom element can be set");
                    }
                    listenerComponent = parseBeanMetadata(e, false);
                } else if (nodeNameEquals(e, REFERENCE_ELEMENT)) {
                    if (listenerComponent != null) {
                        throw new ComponentDefinitionException("Only one of " + REF_ATTRIBUTE + " attribute, " + REF_ELEMENT + ", " + BEAN_ELEMENT + ", " + REFERENCE_ELEMENT + ", " + SERVICE_ELEMENT + " or custom element can be set");
                    }
                    listenerComponent = parseReference(e, false);
                } else if (nodeNameEquals(e, SERVICE_ELEMENT)) {
                    if (listenerComponent != null) {
                        throw new ComponentDefinitionException("Only one of " + REF_ATTRIBUTE + " attribute, " + REF_ELEMENT + ", " + BEAN_ELEMENT + ", " + REFERENCE_ELEMENT + ", " + SERVICE_ELEMENT + " or custom element can be set");
                    }
                    listenerComponent = parseService(e, false);
                }
            } else {
                if (listenerComponent != null) {
                    throw new ComponentDefinitionException("Only one of " + REF_ATTRIBUTE + " attribute, " + REF_ELEMENT + ", " + BEAN_ELEMENT + ", " + REFERENCE_ELEMENT + ", " + SERVICE_ELEMENT + " or custom element can be set");
                }
                listenerComponent = parseCustomElement(e, enclosingComponent);
            }
        }
    }
    if (listenerComponent == null) {
        throw new ComponentDefinitionException("One of " + REF_ATTRIBUTE + " attribute, " + REF_ELEMENT + ", " + BEAN_ELEMENT + ", " + REFERENCE_ELEMENT + ", " + SERVICE_ELEMENT + " or custom element must be set");
    }
    listener.setListenerComponent((Target) listenerComponent);
    return listener;
}
Also used : ComponentDefinitionException(org.osgi.service.blueprint.container.ComponentDefinitionException) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element) 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) RegistrationListenerImpl(org.apache.aries.blueprint.reflect.RegistrationListenerImpl) RefMetadataImpl(org.apache.aries.blueprint.reflect.RefMetadataImpl) IdRefMetadataImpl(org.apache.aries.blueprint.reflect.IdRefMetadataImpl)

Example 25 with Metadata

use of org.osgi.service.blueprint.reflect.Metadata 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)

Aggregations

Metadata (org.osgi.service.blueprint.reflect.Metadata)30 ComponentMetadata (org.osgi.service.blueprint.reflect.ComponentMetadata)26 BeanMetadata (org.osgi.service.blueprint.reflect.BeanMetadata)23 RefMetadata (org.osgi.service.blueprint.reflect.RefMetadata)21 ServiceMetadata (org.osgi.service.blueprint.reflect.ServiceMetadata)17 CollectionMetadata (org.osgi.service.blueprint.reflect.CollectionMetadata)16 MapMetadata (org.osgi.service.blueprint.reflect.MapMetadata)16 ValueMetadata (org.osgi.service.blueprint.reflect.ValueMetadata)16 MutableBeanMetadata (org.apache.aries.blueprint.mutable.MutableBeanMetadata)12 ReferenceListMetadata (org.osgi.service.blueprint.reflect.ReferenceListMetadata)12 ReferenceMetadata (org.osgi.service.blueprint.reflect.ReferenceMetadata)12 ServiceReferenceMetadata (org.osgi.service.blueprint.reflect.ServiceReferenceMetadata)12 Element (org.w3c.dom.Element)12 IdRefMetadata (org.osgi.service.blueprint.reflect.IdRefMetadata)11 NonNullMetadata (org.osgi.service.blueprint.reflect.NonNullMetadata)11 NullMetadata (org.osgi.service.blueprint.reflect.NullMetadata)11 PropsMetadata (org.osgi.service.blueprint.reflect.PropsMetadata)11 MutableRefMetadata (org.apache.aries.blueprint.mutable.MutableRefMetadata)9 PassThroughMetadata (org.apache.aries.blueprint.PassThroughMetadata)8 Node (org.w3c.dom.Node)8