Search in sources :

Example 11 with MapEntry

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

the class AbstractPropertyPlaceholder method processServiceMetadata.

protected Metadata processServiceMetadata(ServiceMetadata component) {
    try {
        if (component instanceof MutableServiceMetadata) {
            processingStack.add("Service Component->");
            ((MutableServiceMetadata) component).setServiceComponent((Target) processMetadata(component.getServiceComponent()));
        } else {
            printWarning(component, "Service Component");
            processingStack.add("Service Component->");
            processMetadata(component.getServiceComponent());
        }
    } finally {
        processingStack.removeLast();
    }
    List<MapEntry> entries = new ArrayList<MapEntry>(component.getServiceProperties());
    if (!!!entries.isEmpty()) {
        try {
            if (component instanceof MutableServiceMetadata) {
                processingStack.add("Service Properties->");
                MutableServiceMetadata msm = (MutableServiceMetadata) component;
                for (MapEntry entry : entries) {
                    msm.removeServiceProperty(entry);
                }
                for (MapEntry entry : processMapEntries(entries)) {
                    msm.addServiceProperty(entry);
                }
            } else {
                printWarning(component, "Service Properties");
                processingStack.add("Service Properties->");
                processMapEntries(entries);
            }
        } finally {
            processingStack.removeLast();
        }
    }
    for (RegistrationListener listener : component.getRegistrationListeners()) {
        Target listenerComponent = listener.getListenerComponent();
        try {
            processingStack.add("Registration Listener " + listenerComponent + "->");
            if (listener instanceof MutableRegistrationListener) {
                ((MutableRegistrationListener) listener).setListenerComponent((Target) processMetadata(listenerComponent));
            } else {
                //Say that we can't change this listener, but continue processing
                //If the value is mutable then we may be ok!
                printWarning(listener, "Service Registration Listener");
                processMetadata(listenerComponent);
            }
        } finally {
            processingStack.removeLast();
        }
    }
    return component;
}
Also used : MutableServiceMetadata(org.apache.aries.blueprint.mutable.MutableServiceMetadata) RegistrationListener(org.osgi.service.blueprint.reflect.RegistrationListener) MutableRegistrationListener(org.apache.aries.blueprint.mutable.MutableRegistrationListener) Target(org.osgi.service.blueprint.reflect.Target) MutableMapEntry(org.apache.aries.blueprint.mutable.MutableMapEntry) MapEntry(org.osgi.service.blueprint.reflect.MapEntry) ArrayList(java.util.ArrayList) MutableRegistrationListener(org.apache.aries.blueprint.mutable.MutableRegistrationListener)

Example 12 with MapEntry

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

the class AbstractPropertyPlaceholder method processMapEntries.

protected List<MapEntry> processMapEntries(List<MapEntry> entries) {
    for (MapEntry entry : entries) {
        try {
            processingStack.add("Map Entry Key: " + entry.getKey() + " Value: " + entry.getValue() + "->");
            if (entry instanceof MutableMapEntry) {
                ((MutableMapEntry) entry).setKey((NonNullMetadata) processMetadata(entry.getKey()));
                ((MutableMapEntry) entry).setValue(processMetadata(entry.getValue()));
            } else {
                printWarning(entry, "Map Entry");
                processMetadata(entry.getKey());
                processMetadata(entry.getValue());
            }
        } finally {
            processingStack.removeLast();
        }
    }
    return entries;
}
Also used : MutableMapEntry(org.apache.aries.blueprint.mutable.MutableMapEntry) MapEntry(org.osgi.service.blueprint.reflect.MapEntry) MutableMapEntry(org.apache.aries.blueprint.mutable.MutableMapEntry)

Example 13 with MapEntry

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

the class AbstractPropertyPlaceholder method processMapMetadata.

protected Metadata processMapMetadata(MapMetadata metadata) {
    List<MapEntry> entries = new ArrayList<MapEntry>(metadata.getEntries());
    if (!!!entries.isEmpty()) {
        try {
            if (metadata instanceof MutableMapMetadata) {
                processingStack.add("Map->");
                MutableMapMetadata mmm = (MutableMapMetadata) metadata;
                for (MapEntry entry : entries) {
                    mmm.removeEntry(entry);
                }
                for (MapEntry entry : processMapEntries(entries)) {
                    mmm.addEntry(entry);
                }
            } else {
                printWarning(metadata, "Map");
                processingStack.add("Map->");
                processMapEntries(entries);
            }
        } finally {
            processingStack.removeLast();
        }
    }
    return metadata;
}
Also used : MutableMapEntry(org.apache.aries.blueprint.mutable.MutableMapEntry) MapEntry(org.osgi.service.blueprint.reflect.MapEntry) ArrayList(java.util.ArrayList) MutableMapMetadata(org.apache.aries.blueprint.mutable.MutableMapMetadata)

Example 14 with MapEntry

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

the class Parser method parseProps.

public PropsMetadata parseProps(Element element) {
    // Parse elements
    List<MapEntry> entries = new ArrayList<MapEntry>();
    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()) && nodeNameEquals(e, PROP_ELEMENT)) {
                entries.add(parseProperty(e));
            }
        }
    }
    return new PropsMetadataImpl(entries);
}
Also used : PropsMetadataImpl(org.apache.aries.blueprint.reflect.PropsMetadataImpl) MapEntry(org.osgi.service.blueprint.reflect.MapEntry) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList)

Example 15 with MapEntry

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

the class Parser method parseMap.

public MapMetadata parseMap(Element element, ComponentMetadata enclosingComponent) {
    // Parse attributes
    String keyType = element.hasAttribute(KEY_TYPE_ATTRIBUTE) ? element.getAttribute(KEY_TYPE_ATTRIBUTE) : null;
    String valueType = element.hasAttribute(VALUE_TYPE_ATTRIBUTE) ? element.getAttribute(VALUE_TYPE_ATTRIBUTE) : null;
    // Parse elements
    List<MapEntry> entries = new ArrayList<MapEntry>();
    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, ENTRY_ELEMENT)) {
                entries.add(parseMapEntry(e, enclosingComponent, null, null));
            }
        }
    }
    return new MapMetadataImpl(keyType, valueType, entries);
}
Also used : MapEntry(org.osgi.service.blueprint.reflect.MapEntry) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) MapMetadataImpl(org.apache.aries.blueprint.reflect.MapMetadataImpl)

Aggregations

MapEntry (org.osgi.service.blueprint.reflect.MapEntry)15 ArrayList (java.util.ArrayList)7 BeanMetadata (org.osgi.service.blueprint.reflect.BeanMetadata)5 ServiceMetadata (org.osgi.service.blueprint.reflect.ServiceMetadata)5 MutableMapEntry (org.apache.aries.blueprint.mutable.MutableMapEntry)4 CollectionMetadata (org.osgi.service.blueprint.reflect.CollectionMetadata)4 ComponentMetadata (org.osgi.service.blueprint.reflect.ComponentMetadata)4 MapMetadata (org.osgi.service.blueprint.reflect.MapMetadata)4 Metadata (org.osgi.service.blueprint.reflect.Metadata)4 RefMetadata (org.osgi.service.blueprint.reflect.RefMetadata)4 ServiceReferenceMetadata (org.osgi.service.blueprint.reflect.ServiceReferenceMetadata)4 WrappedServiceMetadata (org.apache.aries.application.modelling.WrappedServiceMetadata)3 ReferenceListMetadata (org.osgi.service.blueprint.reflect.ReferenceListMetadata)3 ValueMetadata (org.osgi.service.blueprint.reflect.ValueMetadata)3 ExtendedBeanMetadata (org.apache.aries.blueprint.ExtendedBeanMetadata)2 ArrayRecipe (org.apache.aries.blueprint.di.ArrayRecipe)2 CollectionRecipe (org.apache.aries.blueprint.di.CollectionRecipe)2 ComponentFactoryRecipe (org.apache.aries.blueprint.di.ComponentFactoryRecipe)2 DependentComponentFactoryRecipe (org.apache.aries.blueprint.di.DependentComponentFactoryRecipe)2 IdRefRecipe (org.apache.aries.blueprint.di.IdRefRecipe)2