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 org.springframework.beans.factory.support.BeanDefinitionBuilder;
19  import org.springframework.beans.factory.xml.ParserContext;
20  import org.springframework.util.StringUtils;
21  import org.w3c.dom.Element;
22  
23  public class FieldBeanDefinitionParser extends KualiBeanDefinitionParserBase {
24  
25      @Override
26      protected String getBaseBeanTypeParent(Element element) {
27          return "FieldDefinition";
28      }
29      
30      @Override
31      protected void doParse(Element element, ParserContext context, BeanDefinitionBuilder bean) {
32          // get all attributes
33          String attributeName = element.getAttribute("attributeName");
34          String required = element.getAttribute("required");
35          String inquiry = element.getAttribute("inquiry");
36          String lookup = element.getAttribute("lookup");
37          String defaultValue = element.getAttribute("defaultValue");
38          String defaultValueFinderClass = element.getAttribute("defaultValueFinderClass");
39          String maxLength = element.getAttribute("maxLength");
40          String useShortLabel = element.getAttribute("useShortLabel");
41          String hidden = element.getAttribute("hidden");
42          String readOnly = element.getAttribute("readOnly");
43          
44          // now, set on the bean definition
45          if ( StringUtils.hasText(attributeName) ) {
46              bean.addPropertyValue("attributeName", attributeName);
47          }
48          if ( StringUtils.hasText(required) ) {
49              bean.addPropertyValue("required", Boolean.parseBoolean(required));
50          }
51          if ( StringUtils.hasText(defaultValue) ) {
52              bean.addPropertyValue("defaultValue", defaultValue);
53          } else if ( StringUtils.hasText(defaultValueFinderClass) ) {
54              bean.addPropertyValue("defaultValueFinderClass", defaultValueFinderClass);
55          }
56          if ( StringUtils.hasText(maxLength) ) {
57              bean.addPropertyValue("maxLength", Integer.parseInt(maxLength));
58          }
59          if ( inquiry.equals( "no" ) ) {
60              bean.addPropertyValue("noInquiry", Boolean.TRUE);
61          } else if ( inquiry.equals( "force" ) ) {
62              bean.addPropertyValue("forceInquiry", Boolean.TRUE);
63          }
64          if ( lookup.equals( "no" ) ) {
65              bean.addPropertyValue("noLookup", Boolean.TRUE);
66          } else if ( lookup.equals( "force" ) ) {
67              bean.addPropertyValue("forceLookup", Boolean.TRUE);
68          }
69          if ( StringUtils.hasText(useShortLabel) ) {
70              bean.addPropertyValue("useShortLabel", Boolean.parseBoolean(useShortLabel));
71          }
72          if ( StringUtils.hasText(hidden)) {
73              bean.addPropertyValue("hidden", Boolean.parseBoolean(hidden));
74          }
75          if ( StringUtils.hasText(readOnly)) {
76              bean.addPropertyValue("readOnly", Boolean.parseBoolean(readOnly));
77          }
78          
79          // handle any other simple child properties
80          parseEmbeddedPropertyElements(element, bean);
81      }
82  
83      
84  }