List of usage examples for org.springframework.beans.factory.xml BeanDefinitionParserDelegate parsePropertyElement
public void parsePropertyElement(Element ele, BeanDefinition bd)
From source file:org.kuali.rice.krad.datadictionary.parse.CustomSchemaParser.java
/** * Parses the xml bean into a standard bean definition format and fills the information in the passed in definition * builder/*from w w w. j ava2 s . c o m*/ * * @param element - The xml bean being parsed. * @param parserContext - Provided information and functionality regarding current bean set. * @param bean - A definition builder used to build a new spring bean from the information it is filled with. */ @Override protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder bean) { // Retrieve custom schema information build from the annotations Map<String, Map<String, BeanTagAttributeInfo>> attributeProperties = CustomTagAnnotations .getAttributeProperties(); Map<String, BeanTagAttributeInfo> entries = attributeProperties.get(element.getLocalName()); // Log error if there are no attributes found for the bean tag if (entries == null) { LOG.error("Bean Tag not found " + element.getLocalName()); } if (element.getTagName().equals(INC_TAG)) { String parentId = element.getAttribute("compId"); bean.setParentName(parentId); return; } if (element.getTagName().equals("content")) { bean.setParentName("Uif-Content"); String markup = nodesToString(element.getChildNodes()); bean.addPropertyValue("markup", markup); return; } // Retrieve the information for the new bean tag and fill in the default parent if needed BeanTagInfo tagInfo = CustomTagAnnotations.getBeanTags().get(element.getLocalName()); String elementParent = element.getAttribute("parent"); if (StringUtils.isNotBlank(elementParent) && !StringUtils.equals(elementParent, tagInfo.getParent())) { bean.setParentName(elementParent); } else if (StringUtils.isNotBlank(tagInfo.getParent())) { bean.setParentName(tagInfo.getParent()); } // Create the map for the attributes found in the tag and process them in to the definition builder. NamedNodeMap attributes = element.getAttributes(); for (int i = 0; i < attributes.getLength(); i++) { processSingleValue(attributes.item(i).getNodeName(), attributes.item(i).getNodeValue(), entries, bean); } ArrayList<Element> children = (ArrayList<Element>) DomUtils.getChildElements(element); // Process the children found in the xml tag for (int i = 0; i < children.size(); i++) { String tag = children.get(i).getLocalName(); BeanTagAttributeInfo info = entries.get(tag); if (children.get(i).getTagName().equals("spring:property") || children.get(i).getTagName().equals("property")) { BeanDefinitionParserDelegate delegate = parserContext.getDelegate(); delegate.parsePropertyElement(children.get(i), bean.getBeanDefinition()); continue; } // Sets the property name to be used when adding the property value String propertyName; BeanTagAttribute.AttributeType type = null; if (info == null) { propertyName = CustomTagAnnotations.findPropertyByType(element.getLocalName(), tag); if (StringUtils.isNotBlank(propertyName)) { bean.addPropertyValue(propertyName, parseBean(children.get(i), bean, parserContext)); continue; } else { // If the tag is not in the schema map let spring handle the value by forwarding the tag as the // propertyName propertyName = tag; type = findBeanType(children.get(i)); } } else { // If the tag is found in the schema map use the connected name stored in the attribute information propertyName = info.getPropertyName(); type = info.getType(); } // Process the information stored in the child bean ArrayList<Element> grandChildren = (ArrayList<Element>) DomUtils.getChildElements(children.get(i)); if (type == BeanTagAttribute.AttributeType.SINGLEVALUE) { String propertyValue = DomUtils.getTextValue(children.get(i)); bean.addPropertyValue(propertyName, propertyValue); } else if (type == BeanTagAttribute.AttributeType.ANY) { String propertyValue = nodesToString(children.get(i).getChildNodes()); bean.addPropertyValue(propertyName, propertyValue); } else if ((type == BeanTagAttribute.AttributeType.DIRECT) || (type == BeanTagAttribute.AttributeType.DIRECTORBYTYPE)) { boolean isPropertyTag = false; if ((children.get(i).getAttributes().getLength() == 0) && (grandChildren.size() == 1)) { String grandChildTag = grandChildren.get(0).getLocalName(); Class<?> valueClass = info.getValueType(); if (valueClass.isInterface()) { try { valueClass = Class.forName(valueClass.getName() + "Base"); } catch (ClassNotFoundException e) { throw new RuntimeException("Unable to find impl class for interface", e); } } Set<String> validTagNames = CustomTagAnnotations.getBeanTagsByClass(valueClass); if (validTagNames.contains(grandChildTag)) { isPropertyTag = true; } } if (isPropertyTag) { bean.addPropertyValue(propertyName, parseBean(grandChildren.get(0), bean, parserContext)); } else { bean.addPropertyValue(propertyName, parseBean(children.get(i), bean, parserContext)); } } else if ((type == BeanTagAttribute.AttributeType.SINGLEBEAN) || (type == BeanTagAttribute.AttributeType.BYTYPE)) { bean.addPropertyValue(propertyName, parseBean(grandChildren.get(0), bean, parserContext)); } else if (type == BeanTagAttribute.AttributeType.LISTBEAN) { bean.addPropertyValue(propertyName, parseList(grandChildren, children.get(i), bean, parserContext)); } else if (type == BeanTagAttribute.AttributeType.LISTVALUE) { bean.addPropertyValue(propertyName, parseList(grandChildren, children.get(i), bean, parserContext)); } else if (type == BeanTagAttribute.AttributeType.MAPVALUE) { bean.addPropertyValue(propertyName, parseMap(grandChildren, children.get(i), bean, parserContext)); } else if (type == BeanTagAttribute.AttributeType.MAPBEAN) { bean.addPropertyValue(propertyName, parseMap(grandChildren, children.get(i), bean, parserContext)); } else if (type == BeanTagAttribute.AttributeType.SETVALUE) { bean.addPropertyValue(propertyName, parseSet(grandChildren, children.get(i), bean, parserContext)); } else if (type == BeanTagAttribute.AttributeType.SETBEAN) { bean.addPropertyValue(propertyName, parseSet(grandChildren, children.get(i), bean, parserContext)); } } }