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);
}
}
}
}
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);
}
}
}
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;
}
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();
}
}
Aggregations