001 /*
002 * Copyright 2011 The Kuali Foundation.
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package org.kuali.kfs.sys.spring.datadictionary;
017
018 import org.springframework.beans.factory.support.BeanDefinitionBuilder;
019 import org.springframework.beans.factory.xml.ParserContext;
020 import org.springframework.util.StringUtils;
021 import org.w3c.dom.Element;
022
023 public class FieldBeanDefinitionParser extends KualiBeanDefinitionParserBase {
024
025 @Override
026 protected String getBaseBeanTypeParent(Element element) {
027 return "FieldDefinition";
028 }
029
030 @Override
031 protected void doParse(Element element, ParserContext context, BeanDefinitionBuilder bean) {
032 // get all attributes
033 String attributeName = element.getAttribute("attributeName");
034 String required = element.getAttribute("required");
035 String inquiry = element.getAttribute("inquiry");
036 String lookup = element.getAttribute("lookup");
037 String defaultValue = element.getAttribute("defaultValue");
038 String defaultValueFinderClass = element.getAttribute("defaultValueFinderClass");
039 String maxLength = element.getAttribute("maxLength");
040 String useShortLabel = element.getAttribute("useShortLabel");
041 String hidden = element.getAttribute("hidden");
042 String readOnly = element.getAttribute("readOnly");
043
044 // now, set on the bean definition
045 if ( StringUtils.hasText(attributeName) ) {
046 bean.addPropertyValue("attributeName", attributeName);
047 }
048 if ( StringUtils.hasText(required) ) {
049 bean.addPropertyValue("required", Boolean.parseBoolean(required));
050 }
051 if ( StringUtils.hasText(defaultValue) ) {
052 bean.addPropertyValue("defaultValue", defaultValue);
053 } else if ( StringUtils.hasText(defaultValueFinderClass) ) {
054 bean.addPropertyValue("defaultValueFinderClass", defaultValueFinderClass);
055 }
056 if ( StringUtils.hasText(maxLength) ) {
057 bean.addPropertyValue("maxLength", Integer.parseInt(maxLength));
058 }
059 if ( inquiry.equals( "no" ) ) {
060 bean.addPropertyValue("noInquiry", Boolean.TRUE);
061 } else if ( inquiry.equals( "force" ) ) {
062 bean.addPropertyValue("forceInquiry", Boolean.TRUE);
063 }
064 if ( lookup.equals( "no" ) ) {
065 bean.addPropertyValue("noLookup", Boolean.TRUE);
066 } else if ( lookup.equals( "force" ) ) {
067 bean.addPropertyValue("forceLookup", Boolean.TRUE);
068 }
069 if ( StringUtils.hasText(useShortLabel) ) {
070 bean.addPropertyValue("useShortLabel", Boolean.parseBoolean(useShortLabel));
071 }
072 if ( StringUtils.hasText(hidden)) {
073 bean.addPropertyValue("hidden", Boolean.parseBoolean(hidden));
074 }
075 if ( StringUtils.hasText(readOnly)) {
076 bean.addPropertyValue("readOnly", Boolean.parseBoolean(readOnly));
077 }
078
079 // handle any other simple child properties
080 parseEmbeddedPropertyElements(element, bean);
081 }
082
083
084 }