Search in sources :

Example 11 with CollectionMetadata

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

the class QNameHelper method coerceNamespaceAwarePropertyValues.

public static void coerceNamespaceAwarePropertyValues(MutableBeanMetadata bd, Element element, PropertyDescriptor descriptor, ParserContext parserContext) {
    // When the property is an indexed property, the getPropertyType can return null.
    if (descriptor.getPropertyType() == null) {
        return;
    }
    if (descriptor.getPropertyType().isAssignableFrom(QName.class)) {
        String name = descriptor.getName();
        BeanProperty propertyValue = XBeanNamespaceHandler.propertyByName(name, bd);
        if (propertyValue != null) {
            Metadata value = propertyValue.getValue();
            if (value instanceof ValueMetadata) {
                bd.removeProperty(propertyValue);
                Metadata valueMetadata = createQNameMetadata(element, ((ValueMetadata) value).getStringValue(), parserContext);
                bd.addProperty(name, valueMetadata);
            }
        // else??
        }
    } else if (descriptor.getPropertyType().isAssignableFrom(QName[].class)) {
        String name = descriptor.getName();
        BeanProperty propertyValue = XBeanNamespaceHandler.propertyByName(name, bd);
        if (propertyValue != null) {
            Object value = propertyValue.getValue();
            if (value instanceof CollectionMetadata) {
                List<Metadata> values = ((CollectionMetadata) value).getValues();
                MutableCollectionMetadata newValue = parserContext.createMetadata(MutableCollectionMetadata.class);
                for (Metadata v : values) {
                    if (v instanceof ValueMetadata) {
                        newValue.addValue(createQNameMetadata(element, ((ValueMetadata) v).getStringValue(), parserContext));
                    } else {
                        newValue.addValue(v);
                    }
                }
                bd.removeProperty(propertyValue);
                bd.addProperty(name, newValue);
            }
        }
    }
}
Also used : CollectionMetadata(org.osgi.service.blueprint.reflect.CollectionMetadata) MutableCollectionMetadata(org.apache.aries.blueprint.mutable.MutableCollectionMetadata) ValueMetadata(org.osgi.service.blueprint.reflect.ValueMetadata) MutableValueMetadata(org.apache.aries.blueprint.mutable.MutableValueMetadata) CollectionMetadata(org.osgi.service.blueprint.reflect.CollectionMetadata) ValueMetadata(org.osgi.service.blueprint.reflect.ValueMetadata) Metadata(org.osgi.service.blueprint.reflect.Metadata) MutableCollectionMetadata(org.apache.aries.blueprint.mutable.MutableCollectionMetadata) MutableBeanMetadata(org.apache.aries.blueprint.mutable.MutableBeanMetadata) MutableValueMetadata(org.apache.aries.blueprint.mutable.MutableValueMetadata) List(java.util.List) MutableCollectionMetadata(org.apache.aries.blueprint.mutable.MutableCollectionMetadata) BeanProperty(org.osgi.service.blueprint.reflect.BeanProperty)

Example 12 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 13 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 : 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) ExtendedValueMetadata(org.apache.aries.blueprint.ExtendedValueMetadata) MutableCollectionMetadata(org.apache.aries.blueprint.mutable.MutableCollectionMetadata) MutableBeanMetadata(org.apache.aries.blueprint.mutable.MutableBeanMetadata) MutableMapMetadata(org.apache.aries.blueprint.mutable.MutableMapMetadata) ArrayList(java.util.ArrayList) MutableCollectionMetadata(org.apache.aries.blueprint.mutable.MutableCollectionMetadata)

Example 14 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) ExtendedValueMetadata(org.apache.aries.blueprint.ExtendedValueMetadata) MapMetadata(org.osgi.service.blueprint.reflect.MapMetadata) MutableMapMetadata(org.apache.aries.blueprint.mutable.MutableMapMetadata)

Aggregations

CollectionMetadata (org.osgi.service.blueprint.reflect.CollectionMetadata)14 BeanMetadata (org.osgi.service.blueprint.reflect.BeanMetadata)11 ValueMetadata (org.osgi.service.blueprint.reflect.ValueMetadata)10 MapMetadata (org.osgi.service.blueprint.reflect.MapMetadata)9 Metadata (org.osgi.service.blueprint.reflect.Metadata)9 ComponentMetadata (org.osgi.service.blueprint.reflect.ComponentMetadata)7 RefMetadata (org.osgi.service.blueprint.reflect.RefMetadata)7 ServiceMetadata (org.osgi.service.blueprint.reflect.ServiceMetadata)6 MapEntry (org.osgi.service.blueprint.reflect.MapEntry)5 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 BeanMetadataImpl (org.apache.aries.blueprint.reflect.BeanMetadataImpl)4 BeanProperty (org.osgi.service.blueprint.reflect.BeanProperty)4 WrappedServiceMetadata (org.apache.aries.application.modelling.WrappedServiceMetadata)3 MutableBeanMetadata (org.apache.aries.blueprint.mutable.MutableBeanMetadata)3 MutableCollectionMetadata (org.apache.aries.blueprint.mutable.MutableCollectionMetadata)3 MutableMapMetadata (org.apache.aries.blueprint.mutable.MutableMapMetadata)3 NullMetadata (org.osgi.service.blueprint.reflect.NullMetadata)3