Search in sources :

Example 6 with CollectionMetadata

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

use of org.osgi.service.blueprint.reflect.CollectionMetadata 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 8 with CollectionMetadata

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

the class AbstractPropertyPlaceholder method processMetadata.

protected Metadata processMetadata(Metadata metadata) {
    try {
        if (metadata instanceof BeanMetadata) {
            BeanMetadata bmd = (BeanMetadata) metadata;
            processingStack.add("Bean named " + bmd.getId() + "->");
            return processBeanMetadata(bmd);
        } else if (metadata instanceof CollectionMetadata) {
            CollectionMetadata cmd = (CollectionMetadata) metadata;
            processingStack.add("Collection of type " + cmd.getCollectionClass() + "->");
            return processCollectionMetadata(cmd);
        } else if (metadata instanceof MapMetadata) {
            processingStack.add("Map->");
            return processMapMetadata((MapMetadata) metadata);
        } else if (metadata instanceof PropsMetadata) {
            processingStack.add("Properties->");
            return processPropsMetadata((PropsMetadata) metadata);
        } else if (metadata instanceof ValueMetadata) {
            processingStack.add("Value->");
            return processValueMetadata((ValueMetadata) metadata);
        } else {
            processingStack.add("Unknown Metadata " + metadata + "->");
            return metadata;
        }
    } finally {
        processingStack.removeLast();
    }
}
Also used : MutablePropsMetadata(org.apache.aries.blueprint.mutable.MutablePropsMetadata) PropsMetadata(org.osgi.service.blueprint.reflect.PropsMetadata) CollectionMetadata(org.osgi.service.blueprint.reflect.CollectionMetadata) MutableCollectionMetadata(org.apache.aries.blueprint.mutable.MutableCollectionMetadata) BeanMetadata(org.osgi.service.blueprint.reflect.BeanMetadata) MutableBeanMetadata(org.apache.aries.blueprint.mutable.MutableBeanMetadata) ValueMetadata(org.osgi.service.blueprint.reflect.ValueMetadata) MapMetadata(org.osgi.service.blueprint.reflect.MapMetadata) MutableMapMetadata(org.apache.aries.blueprint.mutable.MutableMapMetadata)

Example 9 with CollectionMetadata

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

Aggregations

BeanMetadata (org.osgi.service.blueprint.reflect.BeanMetadata)9 CollectionMetadata (org.osgi.service.blueprint.reflect.CollectionMetadata)9 MapMetadata (org.osgi.service.blueprint.reflect.MapMetadata)8 ValueMetadata (org.osgi.service.blueprint.reflect.ValueMetadata)8 ComponentMetadata (org.osgi.service.blueprint.reflect.ComponentMetadata)7 Metadata (org.osgi.service.blueprint.reflect.Metadata)7 RefMetadata (org.osgi.service.blueprint.reflect.RefMetadata)7 ServiceMetadata (org.osgi.service.blueprint.reflect.ServiceMetadata)6 PropsMetadata (org.osgi.service.blueprint.reflect.PropsMetadata)5 ReferenceListMetadata (org.osgi.service.blueprint.reflect.ReferenceListMetadata)5 ServiceReferenceMetadata (org.osgi.service.blueprint.reflect.ServiceReferenceMetadata)5 ArrayList (java.util.ArrayList)4 MapEntry (org.osgi.service.blueprint.reflect.MapEntry)4 WrappedServiceMetadata (org.apache.aries.application.modelling.WrappedServiceMetadata)3 MutableMapMetadata (org.apache.aries.blueprint.mutable.MutableMapMetadata)3 NullMetadata (org.osgi.service.blueprint.reflect.NullMetadata)3 ExtendedBeanMetadata (org.apache.aries.blueprint.ExtendedBeanMetadata)2 PassThroughMetadata (org.apache.aries.blueprint.PassThroughMetadata)2 MutableBeanMetadata (org.apache.aries.blueprint.mutable.MutableBeanMetadata)2 MutableCollectionMetadata (org.apache.aries.blueprint.mutable.MutableCollectionMetadata)2