001/*
002 * Copyright 2008 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 */
016package org.kuali.ole.sys.spring.datadictionary;
017
018import org.springframework.beans.factory.support.BeanDefinitionBuilder;
019import org.springframework.beans.factory.xml.ParserContext;
020import org.springframework.util.StringUtils;
021import org.w3c.dom.Element;
022
023public class MaintenanceFieldBeanDefinitionParser extends KualiBeanDefinitionParserBase {
024
025    @Override
026    protected String getBaseBeanTypeParent(Element element) {
027        return "MaintainableFieldDefinition";
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 unconditionallyReadOnly = element.getAttribute("unconditionallyReadOnly");
036        String defaultValue = element.getAttribute("defaultValue");
037        String defaultValueFinderClass = element.getAttribute("defaultValueFinderClass");
038        String javascriptLeaveFieldFunction = element.getAttribute("javascriptLeaveFieldFunction");
039        String javascriptLeaveFieldCallbackFunction = element.getAttribute("javascriptLeaveFieldCallbackFunction");
040
041        // now, set on the bean definition
042        if ( StringUtils.hasText(attributeName) ) {
043            bean.addPropertyValue("name", attributeName);
044        }
045        if ( StringUtils.hasText(required) ) {
046            bean.addPropertyValue("required", Boolean.parseBoolean(required));
047        }
048        if ( StringUtils.hasText(unconditionallyReadOnly) ) {
049            bean.addPropertyValue("unconditionallyReadOnly", Boolean.parseBoolean(unconditionallyReadOnly));
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(javascriptLeaveFieldFunction) ) {
057            bean.addPropertyValue("webUILeaveFieldFunction", javascriptLeaveFieldFunction);
058        }
059        if ( StringUtils.hasText(javascriptLeaveFieldCallbackFunction) ) {
060            bean.addPropertyValue("webUILeaveFieldCallbackFunction", javascriptLeaveFieldCallbackFunction);
061        }
062        
063        // handle any other simple child properties
064        parseEmbeddedPropertyElements(element, bean);
065    }
066
067    
068}