1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.sys.spring.datadictionary;
17
18 import java.util.ArrayList;
19
20 import org.kuali.rice.krad.datadictionary.PrimitiveAttributeDefinition;
21 import org.kuali.rice.krad.datadictionary.SupportAttributeDefinition;
22 import org.springframework.beans.factory.support.BeanDefinitionBuilder;
23 import org.springframework.beans.factory.xml.ParserContext;
24 import org.springframework.util.StringUtils;
25 import org.w3c.dom.Element;
26 import org.w3c.dom.NamedNodeMap;
27 import org.w3c.dom.Node;
28 import org.w3c.dom.NodeList;
29
30 public class RelationshipBeanDefinitionParser extends KualiBeanDefinitionParserBase {
31
32 @Override
33 protected String getBaseBeanTypeParent(Element element) {
34 return "RelationshipDefinition";
35 }
36
37 @Override
38 protected void doParse(Element element, ParserContext context, BeanDefinitionBuilder bean) {
39
40 String objectAttribute = element.getAttribute("objectAttribute");
41 String targetClass = element.getAttribute("targetClass");
42
43
44 if ( StringUtils.hasText(objectAttribute) ) {
45 bean.addPropertyValue("objectAttributeName", objectAttribute);
46 }
47 if ( StringUtils.hasText(targetClass) ) {
48 bean.addPropertyValue("targetClass", targetClass);
49 }
50
51 NodeList children = element.getChildNodes();
52 ArrayList<PrimitiveAttributeDefinition> pDefs = new ArrayList<PrimitiveAttributeDefinition>();
53 ArrayList<SupportAttributeDefinition> sDefs = new ArrayList<SupportAttributeDefinition>();
54
55 for ( int i = 0; i < children.getLength(); i++ ) {
56 Node child = children.item(i);
57 String nodeName = child.getLocalName();
58 if ( nodeName == null ) continue;
59
60 if ( nodeName.equals("primitiveAttribute") ) {
61 NamedNodeMap attributes = child.getAttributes();
62 String source = attributes.getNamedItem("source").getNodeValue();
63 String target = attributes.getNamedItem("target").getNodeValue();
64 PrimitiveAttributeDefinition pad = new PrimitiveAttributeDefinition();
65 pad.setSourceName(source);
66 pad.setTargetName(target);
67 pDefs.add(pad);
68 } else if ( nodeName.equals("supportAttribute") ) {
69 NamedNodeMap attributes = child.getAttributes();
70 String source = attributes.getNamedItem("source").getNodeValue();
71 String target = attributes.getNamedItem("target").getNodeValue();
72 boolean identifier = false;
73 String identifierStr = attributes.getNamedItem("identifier").getNodeValue();
74 if ( identifierStr != null ) {
75 identifier = Boolean.valueOf( identifierStr );
76 }
77 SupportAttributeDefinition pad = new SupportAttributeDefinition();
78 pad.setSourceName(source);
79 pad.setTargetName(target);
80 pad.setIdentifier(identifier);
81 sDefs.add(pad);
82 }
83 bean.addPropertyValue("primitiveAttributes", pDefs);
84 bean.addPropertyValue("supportAttributes", sDefs);
85 }
86 }
87
88
89 }