Search in sources :

Example 1 with MapEntryImpl

use of org.apache.aries.blueprint.reflect.MapEntryImpl in project aries by apache.

the class Parser method parseMapEntry.

private MapEntry parseMapEntry(Element element, ComponentMetadata enclosingComponent, String keyType, String valueType) {
    // Parse attributes
    String key = element.hasAttribute(KEY_ATTRIBUTE) ? element.getAttribute(KEY_ATTRIBUTE) : null;
    String keyRef = element.hasAttribute(KEY_REF_ATTRIBUTE) ? element.getAttribute(KEY_REF_ATTRIBUTE) : null;
    String value = element.hasAttribute(VALUE_ATTRIBUTE) ? element.getAttribute(VALUE_ATTRIBUTE) : null;
    String valueRef = element.hasAttribute(VALUE_REF_ATTRIBUTE) ? element.getAttribute(VALUE_REF_ATTRIBUTE) : null;
    // Parse elements
    NonNullMetadata keyValue = null;
    Metadata valValue = null;
    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 (nodeNameEquals(e, KEY_ELEMENT)) {
                keyValue = parseMapKeyEntry(e, enclosingComponent, keyType);
            } else {
                valValue = parseValueGroup(e, enclosingComponent, valueType, true);
            }
        }
    }
    // Check key
    if (keyValue != null && (key != null || keyRef != null) || (keyValue == null && key == null && keyRef == null)) {
        throw new ComponentDefinitionException("Only and only one of " + KEY_ATTRIBUTE + " attribute, " + KEY_REF_ATTRIBUTE + " attribute or " + KEY_ELEMENT + " element must be set");
    } else if (keyValue == null && key != null) {
        keyValue = new ValueMetadataImpl(key, keyType);
    } else if (keyValue == null) /*&& keyRef != null*/
    {
        keyValue = new RefMetadataImpl(keyRef);
    }
    // Check value
    if (valValue != null && (value != null || valueRef != null) || (valValue == null && value == null && valueRef == null)) {
        throw new ComponentDefinitionException("Only and only one of " + VALUE_ATTRIBUTE + " attribute, " + VALUE_REF_ATTRIBUTE + " attribute or sub element must be set");
    } else if (valValue == null && value != null) {
        valValue = new ValueMetadataImpl(value, valueType);
    } else if (valValue == null) /*&& valueRef != null*/
    {
        valValue = new RefMetadataImpl(valueRef);
    }
    return new MapEntryImpl(keyValue, valValue);
}
Also used : ValueMetadataImpl(org.apache.aries.blueprint.reflect.ValueMetadataImpl) ComponentDefinitionException(org.osgi.service.blueprint.container.ComponentDefinitionException) MapEntryImpl(org.apache.aries.blueprint.reflect.MapEntryImpl) 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) NonNullMetadata(org.osgi.service.blueprint.reflect.NonNullMetadata) RefMetadataImpl(org.apache.aries.blueprint.reflect.RefMetadataImpl) IdRefMetadataImpl(org.apache.aries.blueprint.reflect.IdRefMetadataImpl)

Example 2 with MapEntryImpl

use of org.apache.aries.blueprint.reflect.MapEntryImpl in project aries by apache.

the class Parser method parseProperty.

private MapEntry parseProperty(Element element) {
    // Parse attributes
    if (!element.hasAttribute(KEY_ATTRIBUTE)) {
        throw new ComponentDefinitionException(KEY_ATTRIBUTE + " attribute is required");
    }
    String value;
    if (element.hasAttribute(VALUE_ATTRIBUTE)) {
        value = element.getAttribute(VALUE_ATTRIBUTE);
    } else {
        value = getTextValue(element);
    }
    String key = element.getAttribute(KEY_ATTRIBUTE);
    return new MapEntryImpl(new ValueMetadataImpl(key), new ValueMetadataImpl(value));
}
Also used : ValueMetadataImpl(org.apache.aries.blueprint.reflect.ValueMetadataImpl) ComponentDefinitionException(org.osgi.service.blueprint.container.ComponentDefinitionException) MapEntryImpl(org.apache.aries.blueprint.reflect.MapEntryImpl)

Aggregations

MapEntryImpl (org.apache.aries.blueprint.reflect.MapEntryImpl)2 ValueMetadataImpl (org.apache.aries.blueprint.reflect.ValueMetadataImpl)2 ComponentDefinitionException (org.osgi.service.blueprint.container.ComponentDefinitionException)2 IdRefMetadataImpl (org.apache.aries.blueprint.reflect.IdRefMetadataImpl)1 RefMetadataImpl (org.apache.aries.blueprint.reflect.RefMetadataImpl)1 BeanMetadata (org.osgi.service.blueprint.reflect.BeanMetadata)1 CollectionMetadata (org.osgi.service.blueprint.reflect.CollectionMetadata)1 ComponentMetadata (org.osgi.service.blueprint.reflect.ComponentMetadata)1 IdRefMetadata (org.osgi.service.blueprint.reflect.IdRefMetadata)1 MapMetadata (org.osgi.service.blueprint.reflect.MapMetadata)1 Metadata (org.osgi.service.blueprint.reflect.Metadata)1 NonNullMetadata (org.osgi.service.blueprint.reflect.NonNullMetadata)1 NullMetadata (org.osgi.service.blueprint.reflect.NullMetadata)1 PropsMetadata (org.osgi.service.blueprint.reflect.PropsMetadata)1 RefMetadata (org.osgi.service.blueprint.reflect.RefMetadata)1 ReferenceListMetadata (org.osgi.service.blueprint.reflect.ReferenceListMetadata)1 ReferenceMetadata (org.osgi.service.blueprint.reflect.ReferenceMetadata)1 ServiceMetadata (org.osgi.service.blueprint.reflect.ServiceMetadata)1 ServiceReferenceMetadata (org.osgi.service.blueprint.reflect.ServiceReferenceMetadata)1 ValueMetadata (org.osgi.service.blueprint.reflect.ValueMetadata)1