protected void addNestedPropertyElements()

in xbean-spring/src/main/java/org/apache/xbean/spring/context/v2c/XBeanNamespaceHandler.java [490:567]


    protected void addNestedPropertyElements(BeanDefinitionHolder definition, MappingMetaData metadata,
            String className, Element element) {
        NodeList nl = element.getChildNodes();

        for (int i = 0; i < nl.getLength(); i++) {
            Node node = nl.item(i);
            if (node instanceof Element) {
                Element childElement = (Element) node;
                String uri = childElement.getNamespaceURI();
                String localName = childElement.getLocalName();

                if (!isDefaultNamespace(uri) || !reservedElementNames.contains(localName)) {
                    // we could be one of the following
                    // * the child element maps to a <property> tag with inner
                    // tags being the bean
                    // * the child element maps to a <property><list> tag with
                    // inner tags being the contents of the list
                    // * the child element maps to a <property> tag and is the
                    // bean tag too
                    // * the child element maps to a <property> tag and is a simple
                    // type (String, Class, int, etc).
                    Object value = null;
                    String propertyName = metadata.getNestedListProperty(getLocalName(element), localName);
                    if (propertyName != null) {
                        value = parseListElement(childElement, propertyName);
                    }
                    else {
                        propertyName = metadata.getFlatCollectionProperty(getLocalName(element), localName);
                        if (propertyName != null) {
                            Object def = parserContext.getDelegate().parseCustomElement(childElement);
                            PropertyValue pv = definition.getBeanDefinition().getPropertyValues().getPropertyValue(propertyName);
                            if (pv != null) {
                                Collection l = (Collection) pv.getValue();
                                l.add(def);
                                continue;
                            } else {
                                ManagedList l = new ManagedList();
                                l.add(def);
                                value = l;
                            }
                        } else {
                            propertyName = metadata.getNestedProperty(getLocalName(element), localName);
                            if (propertyName != null) {
                                // lets find the first child bean that parses fine
                                value = parseChildExtensionBean(childElement);
                            }
                        }
                    }

                    if (propertyName == null && metadata.isFlatProperty(getLocalName(element), localName)) {
                       value = parseBeanFromExtensionElement(childElement, className, localName);
                       propertyName = localName;
                    }

                    if (propertyName == null) {
                        value = tryParseNestedPropertyViaIntrospection(metadata, className, childElement);
                        propertyName = localName;
                    }

                    if (value != null) {
                        definition.getBeanDefinition().getPropertyValues().addPropertyValue(propertyName, value);
                    }
                    else
                    {
                        /**
                         * In this case there is no nested property, so just do a normal
                         * addProperty like we do with attributes.
                         */
                        String text = getElementText(childElement);

                        if (text != null) {
                            addProperty(definition, metadata, element, localName, text);
                        }
                    }
                }
            }
        }
    }