Search in sources :

Example 1 with ServiceReferenceMetadata

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

the class BlueprintContainerImpl method getMetadata.

private <T extends ComponentMetadata> void getMetadata(Class<T> clazz, Metadata component, Collection<T> metadatas) {
    if (component == null) {
        return;
    }
    if (clazz.isInstance(component)) {
        metadatas.add(clazz.cast(component));
    }
    if (component instanceof BeanMetadata) {
        getMetadata(clazz, ((BeanMetadata) component).getFactoryComponent(), metadatas);
        for (BeanArgument arg : ((BeanMetadata) component).getArguments()) {
            getMetadata(clazz, arg.getValue(), metadatas);
        }
        for (BeanProperty prop : ((BeanMetadata) component).getProperties()) {
            getMetadata(clazz, prop.getValue(), metadatas);
        }
    }
    if (component instanceof CollectionMetadata) {
        for (Metadata m : ((CollectionMetadata) component).getValues()) {
            getMetadata(clazz, m, metadatas);
        }
    }
    if (component instanceof MapMetadata) {
        for (MapEntry m : ((MapMetadata) component).getEntries()) {
            getMetadata(clazz, m.getKey(), metadatas);
            getMetadata(clazz, m.getValue(), metadatas);
        }
    }
    if (component instanceof PropsMetadata) {
        for (MapEntry m : ((PropsMetadata) component).getEntries()) {
            getMetadata(clazz, m.getKey(), metadatas);
            getMetadata(clazz, m.getValue(), metadatas);
        }
    }
    if (component instanceof ServiceReferenceMetadata) {
        for (ReferenceListener l : ((ServiceReferenceMetadata) component).getReferenceListeners()) {
            getMetadata(clazz, l.getListenerComponent(), metadatas);
        }
    }
    if (component instanceof ServiceMetadata) {
        getMetadata(clazz, ((ServiceMetadata) component).getServiceComponent(), metadatas);
        for (MapEntry m : ((ServiceMetadata) component).getServiceProperties()) {
            getMetadata(clazz, m.getKey(), metadatas);
            getMetadata(clazz, m.getValue(), metadatas);
        }
        for (RegistrationListener l : ((ServiceMetadata) component).getRegistrationListeners()) {
            getMetadata(clazz, l.getListenerComponent(), metadatas);
        }
    }
}
Also used : BeanArgument(org.osgi.service.blueprint.reflect.BeanArgument) PropsMetadata(org.osgi.service.blueprint.reflect.PropsMetadata) RegistrationListener(org.osgi.service.blueprint.reflect.RegistrationListener) CollectionMetadata(org.osgi.service.blueprint.reflect.CollectionMetadata) MapEntry(org.osgi.service.blueprint.reflect.MapEntry) ExtendedBeanMetadata(org.apache.aries.blueprint.ExtendedBeanMetadata) BeanMetadata(org.osgi.service.blueprint.reflect.BeanMetadata) CollectionMetadata(org.osgi.service.blueprint.reflect.CollectionMetadata) Metadata(org.osgi.service.blueprint.reflect.Metadata) PropsMetadata(org.osgi.service.blueprint.reflect.PropsMetadata) 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) ExtendedBeanMetadata(org.apache.aries.blueprint.ExtendedBeanMetadata) BeanMetadata(org.osgi.service.blueprint.reflect.BeanMetadata) MapMetadata(org.osgi.service.blueprint.reflect.MapMetadata) ReferenceListener(org.osgi.service.blueprint.reflect.ReferenceListener) MapMetadata(org.osgi.service.blueprint.reflect.MapMetadata) ServiceReferenceMetadata(org.osgi.service.blueprint.reflect.ServiceReferenceMetadata) ServiceMetadata(org.osgi.service.blueprint.reflect.ServiceMetadata) BeanProperty(org.osgi.service.blueprint.reflect.BeanProperty)

Example 2 with ServiceReferenceMetadata

use of org.osgi.service.blueprint.reflect.ServiceReferenceMetadata in project geronimo-xbean by apache.

the class XBeanNamespaceHandler method equals.

private boolean equals(NonNullMetadata key1, NonNullMetadata key2) {
    if (key1 == key2)
        return true;
    if (key1.getClass() != key2.getClass())
        return false;
    if (key1 instanceof RefMetadata)
        return ((RefMetadata) key1).getComponentId().equals(((RefMetadata) key2).getComponentId());
    if (key1 instanceof ReferenceMetadata) {
        if (((ReferenceMetadata) key1).getTimeout() != ((ReferenceMetadata) key2).getTimeout())
            return false;
    }
    if (key1 instanceof ServiceReferenceMetadata) {
        ServiceReferenceMetadata sr1 = (ServiceReferenceMetadata) key1;
        ServiceReferenceMetadata sr2 = (ServiceReferenceMetadata) key2;
        return sr1.getAvailability() == sr2.getAvailability() && sr1.getInterface().equals(sr2.getInterface()) && sr1.getComponentName().equals(sr2.getComponentName()) && sr1.getFilter().equals(sr2.getFilter()) && sr1.getReferenceListeners().equals(sr2.getReferenceListeners()) && sr1.getId().equals(sr2.getId()) && sr1.getActivation() == sr2.getActivation() && sr1.getDependsOn().equals(sr2.getDependsOn());
    }
    if (key1 instanceof ValueMetadata) {
        ValueMetadata v1 = (ValueMetadata) key1;
        ValueMetadata v2 = (ValueMetadata) key2;
        if (v1.getStringValue() != null ? v1.getStringValue().equals(v2.getStringValue()) : v2.getStringValue() == null && v1.getType() != null ? v1.getType().equals(v2.getType()) : v2.getType() == null) {
            return true;
        }
    }
    return false;
}
Also used : RefMetadata(org.osgi.service.blueprint.reflect.RefMetadata) MutableRefMetadata(org.apache.aries.blueprint.mutable.MutableRefMetadata) ValueMetadata(org.osgi.service.blueprint.reflect.ValueMetadata) MutableValueMetadata(org.apache.aries.blueprint.mutable.MutableValueMetadata) ServiceReferenceMetadata(org.osgi.service.blueprint.reflect.ServiceReferenceMetadata) ServiceReferenceMetadata(org.osgi.service.blueprint.reflect.ServiceReferenceMetadata) ReferenceMetadata(org.osgi.service.blueprint.reflect.ReferenceMetadata)

Example 3 with ServiceReferenceMetadata

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

the class AbstractParserProxy method parseCDRForReferences.

/**
 * Extract References metadata from a ComponentDefinitionRegistry.
 * @param cdr                       ComponentDefinitionRegistry
 * @return List<WrappedReferenceMetadata>
 * @throws InvalidAttributeException
 */
private List<ImportedService> parseCDRForReferences(ComponentDefinitionRegistry cdr) throws InvalidAttributeException {
    _logger.debug(LOG_ENTRY, "parseCDRForReferences", new Object[] { cdr });
    List<ImportedService> result = new ArrayList<ImportedService>();
    for (ComponentMetadata compMetadata : findAllComponents(cdr)) {
        if (compMetadata instanceof ServiceReferenceMetadata) {
            ServiceReferenceMetadata referenceMetadata = (ServiceReferenceMetadata) compMetadata;
            boolean optional = referenceMetadata.getAvailability() == ServiceReferenceMetadata.AVAILABILITY_OPTIONAL;
            String iface = referenceMetadata.getInterface();
            String compName = referenceMetadata.getComponentName();
            String blueprintFilter = referenceMetadata.getFilter();
            String id = referenceMetadata.getId();
            boolean isMultiple = (referenceMetadata instanceof ReferenceListMetadata);
            // For now we blacklist certain objectClasses and filters - this is a pretty dreadful thing to do.
            if (!isBlacklisted(iface, blueprintFilter)) {
                ImportedService ref = _modellingManager.getImportedService(optional, iface, compName, blueprintFilter, id, isMultiple);
                result.add(ref);
            }
        }
    }
    _logger.debug(LOG_EXIT, "parseCDRForReferences", new Object[] { result });
    return result;
}
Also used : ReferenceListMetadata(org.osgi.service.blueprint.reflect.ReferenceListMetadata) ArrayList(java.util.ArrayList) ImportedService(org.apache.aries.application.modelling.ImportedService) ComponentMetadata(org.osgi.service.blueprint.reflect.ComponentMetadata) ServiceReferenceMetadata(org.osgi.service.blueprint.reflect.ServiceReferenceMetadata)

Example 4 with ServiceReferenceMetadata

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

the class AbstractParserProxy method traverseComponent.

/**
 * Traverse {@link ComponentMetadata} instances to find all nested {@link ComponentMetadata} instances
 * @param component
 * @param output
 */
private void traverseComponent(ComponentMetadata component, Set<ComponentMetadata> output) {
    if (!!!output.add(component))
        return;
    if (component instanceof BeanMetadata) {
        BeanMetadata bean = (BeanMetadata) component;
        traverse(bean.getFactoryComponent(), output);
        for (BeanArgument argument : bean.getArguments()) {
            traverse(argument.getValue(), output);
        }
        for (BeanProperty property : bean.getProperties()) {
            traverse(property.getValue(), output);
        }
    } else if (component instanceof ServiceMetadata) {
        ServiceMetadata service = (ServiceMetadata) component;
        traverse(service.getServiceComponent(), output);
        for (RegistrationListener listener : service.getRegistrationListeners()) {
            traverse(listener.getListenerComponent(), output);
        }
        for (MapEntry e : service.getServiceProperties()) {
            traverse(e.getKey(), output);
            traverse(e.getValue(), output);
        }
    } else if (component instanceof ServiceReferenceMetadata) {
        ServiceReferenceMetadata reference = (ServiceReferenceMetadata) component;
        for (ReferenceListener listener : reference.getReferenceListeners()) {
            traverse(listener.getListenerComponent(), output);
        }
    }
}
Also used : BeanArgument(org.osgi.service.blueprint.reflect.BeanArgument) RegistrationListener(org.osgi.service.blueprint.reflect.RegistrationListener) MapEntry(org.osgi.service.blueprint.reflect.MapEntry) BeanMetadata(org.osgi.service.blueprint.reflect.BeanMetadata) ReferenceListener(org.osgi.service.blueprint.reflect.ReferenceListener) ServiceReferenceMetadata(org.osgi.service.blueprint.reflect.ServiceReferenceMetadata) WrappedServiceMetadata(org.apache.aries.application.modelling.WrappedServiceMetadata) ServiceMetadata(org.osgi.service.blueprint.reflect.ServiceMetadata) BeanProperty(org.osgi.service.blueprint.reflect.BeanProperty)

Aggregations

ServiceReferenceMetadata (org.osgi.service.blueprint.reflect.ServiceReferenceMetadata)4 BeanArgument (org.osgi.service.blueprint.reflect.BeanArgument)2 BeanMetadata (org.osgi.service.blueprint.reflect.BeanMetadata)2 BeanProperty (org.osgi.service.blueprint.reflect.BeanProperty)2 ComponentMetadata (org.osgi.service.blueprint.reflect.ComponentMetadata)2 MapEntry (org.osgi.service.blueprint.reflect.MapEntry)2 RefMetadata (org.osgi.service.blueprint.reflect.RefMetadata)2 ReferenceListener (org.osgi.service.blueprint.reflect.ReferenceListener)2 RegistrationListener (org.osgi.service.blueprint.reflect.RegistrationListener)2 ServiceMetadata (org.osgi.service.blueprint.reflect.ServiceMetadata)2 ArrayList (java.util.ArrayList)1 ImportedService (org.apache.aries.application.modelling.ImportedService)1 WrappedServiceMetadata (org.apache.aries.application.modelling.WrappedServiceMetadata)1 ExtendedBeanMetadata (org.apache.aries.blueprint.ExtendedBeanMetadata)1 MutableRefMetadata (org.apache.aries.blueprint.mutable.MutableRefMetadata)1 MutableValueMetadata (org.apache.aries.blueprint.mutable.MutableValueMetadata)1 CollectionMetadata (org.osgi.service.blueprint.reflect.CollectionMetadata)1 MapMetadata (org.osgi.service.blueprint.reflect.MapMetadata)1 Metadata (org.osgi.service.blueprint.reflect.Metadata)1 PropsMetadata (org.osgi.service.blueprint.reflect.PropsMetadata)1