Search in sources :

Example 1 with MutableRegistrationListener

use of org.apache.aries.blueprint.mutable.MutableRegistrationListener 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)

Aggregations

ArrayList (java.util.ArrayList)1 MutableMapEntry (org.apache.aries.blueprint.mutable.MutableMapEntry)1 MutableRegistrationListener (org.apache.aries.blueprint.mutable.MutableRegistrationListener)1 MutableServiceMetadata (org.apache.aries.blueprint.mutable.MutableServiceMetadata)1 MapEntry (org.osgi.service.blueprint.reflect.MapEntry)1 RegistrationListener (org.osgi.service.blueprint.reflect.RegistrationListener)1 Target (org.osgi.service.blueprint.reflect.Target)1