in xbean-blueprint/src/main/java/org/apache/xbean/blueprint/context/impl/XBeanNamespaceHandler.java [332:422]
private void nestedProperties(MutableBeanMetadata beanMetadata, Element element, String beanTypeName, String className, ParserContext parserContext) {
NodeList nodes = element.getChildNodes();
for (int i = 0; i < nodes.getLength(); i++) {
Node node = nodes.item(i);
if (node instanceof Element) {
Element child = (Element) node;
String childName = child.getLocalName();
String namespace = child.getNamespaceURI();
if (!this.namespace.equals(namespace)) {
BeanProperty prop = parserContext.parseElement(BeanProperty.class, beanMetadata, child);
beanMetadata.addProperty(prop);
continue;
}
Metadata childMetadata = null;
PropertyDescriptor pd = getPropertyDescriptor(mappingMetaData.getClassName(beanTypeName), childName);
Class propertyType = pd == null ? null : pd.getPropertyType();
String propertyName = mappingMetaData.getNestedListProperty(beanTypeName, childName);
boolean isList = false;
//explicit list
if (propertyName != null || isCollectionType(propertyType)) {
propertyName = propertyName == null ? childName : propertyName;
childMetadata = parserContext.parseElement(CollectionMetadata.class, beanMetadata, child);
} else if ((propertyName = mappingMetaData.getFlatCollectionProperty(beanTypeName, childName)) != null) {
//flat collection
Metadata elementMetadata = parse(child, parserContext);
BeanProperty list = propertyByName(propertyName, beanMetadata);
MutableCollectionMetadata listMeta;
if (list == null) {
listMeta = parserContext.createMetadata(MutableCollectionMetadata.class);
childMetadata = listMeta;
} else {
listMeta = (MutableCollectionMetadata) list.getValue();
}
isList = true;
listMeta.addValue(elementMetadata);
} else if ((propertyName = mappingMetaData.getNestedProperty(beanTypeName, childName)) != null) {
// lets find the first child bean that parses fine
childMetadata = parseChildExtensionBean(child, beanMetadata, parserContext);
} else if (mappingMetaData.isFlatProperty(beanTypeName, childName)) {
propertyName = childName;
String flatClassName = getPropertyDescriptor(mappingMetaData.getClassName(beanTypeName), childName).getPropertyType().getName();
childMetadata = parseInternal(child, parserContext, childName, flatClassName);
} else {
childMetadata = tryParseNestedPropertyViaIntrospection(beanMetadata, className, child, parserContext);
propertyName = childName;
}
if (childMetadata == null && !isList) {
String text = getElementText(child);
if (text != null) {
MutableValueMetadata m = parserContext.createMetadata(MutableValueMetadata.class);
m.setStringValue(text.trim());
childMetadata = m;
}
// propertyName = mappingMetaData.getPropertyName(beanTypeName, childName);
// NodeList childNodes = child.getChildNodes();
// StringBuilder buf = new StringBuilder();
// for (int j = 0; j < childNodes.getLength(); j++) {
// Node childNode = childNodes.item(j);
// if (childNode instanceof Element) {
// Element childElement = (Element) childNode;
// if (namespace.equals(childElement.getNamespaceURI())) {
// childMetadata = parse(childElement, parserContext);
// } else {
// try {
// childMetadata = parserContext.parseElement(BeanMetadata.class, beanMetaData, childElement);
// } catch (Exception e) {
// childMetadata = parserContext.parseElement(ValueMetadata.class, beanMetaData, childElement);
// }
// }
//
// break;
// } else if (childNode instanceof Text) {
// String value = childNode.getNodeValue();
// buf.append(value);
// }
// }
// if (childMetadata == null) {
// MutableValueMetadata m = parserContext.createMetadata(MutableValueMetadata.class);
// m.setStringValue(buf.toString().trim());
// childMetadata = m;
// }
}
if (childMetadata != null) {
beanMetadata.addProperty(propertyName, childMetadata);
}
}
}
}