View Javadoc
1   /*
2    * Copyright 2008 The Kuali Foundation
3    * 
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    * http://www.opensource.org/licenses/ecl2.php
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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          // get all attributes
40          String objectAttribute = element.getAttribute("objectAttribute");
41          String targetClass = element.getAttribute("targetClass");
42  
43          // now, set on the bean definition
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  }