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.businessobject;
017
018import java.util.LinkedHashMap;
019
020import org.kuali.ole.sys.dataaccess.FieldMetaData;
021import org.kuali.rice.kns.datadictionary.BusinessObjectEntry;
022import org.kuali.rice.krad.bo.TransientBusinessObjectBase;
023import org.kuali.rice.krad.datadictionary.AttributeDefinition;
024
025public class DataMappingFieldDefinition extends TransientBusinessObjectBase {
026    private String namespaceCode;
027    private String componentClass;
028    private String propertyName;
029    private String tableName;
030    private String fieldName;
031    private FunctionalFieldDescription functionalFieldDescription;
032
033    private BusinessObjectEntry businessObjectEntry;
034    private AttributeDefinition attributeDefinition;
035    private FieldMetaData fieldMetaData;
036    private String propertyType;
037    private String referenceComponentLabel;
038
039    public DataMappingFieldDefinition() {
040    }
041
042    public DataMappingFieldDefinition(FunctionalFieldDescription functionalFieldDescription, BusinessObjectEntry businessObjectEntry, AttributeDefinition attributeDefinition, FieldMetaData fieldMetaData, String propertyType, String referenceComponentLabel) {
043        setNamespaceCode(functionalFieldDescription.getNamespaceCode());
044        setComponentClass(functionalFieldDescription.getComponentClass());
045        setPropertyName(functionalFieldDescription.getPropertyName());
046        setTableName(fieldMetaData.getTableName());
047        setFieldName(fieldMetaData.getColumnName());
048        setFunctionalFieldDescription(functionalFieldDescription);
049        this.businessObjectEntry = businessObjectEntry;
050        this.attributeDefinition = attributeDefinition;
051        this.fieldMetaData = fieldMetaData;
052        this.propertyType = propertyType;
053        this.referenceComponentLabel = referenceComponentLabel;
054    }
055
056    public String getDatabaseDataType() {
057        return fieldMetaData.getDataType();
058    }
059
060    public String getApplicationDataType() {
061        return propertyType;
062    }
063
064    public int getDatabaseDefinedLength() {
065        return fieldMetaData.getLength();
066    }
067
068    public int getApplicationDefinedLength() {
069        return attributeDefinition.getMaxLength();
070    }
071
072    public int getDecimalPlaces() {
073        return fieldMetaData.getDecimalPlaces();
074    }
075
076    public String getReferenceComponent() {
077        return referenceComponentLabel;
078    }
079
080    public boolean isRequired() {
081        return attributeDefinition.isRequired();
082    }
083
084    public String getValidationPattern() {
085        return new StringBuffer(attributeDefinition.getValidationPattern().getClass().getSimpleName()).append(" (").append(attributeDefinition.getValidationPattern().getRegexPattern().toString()).append(")").toString();
086    }
087    
088    public boolean isEncrypted() {
089        return fieldMetaData.isEncrypted();
090    }
091    
092    public String getMaskPattern() {
093        // TODO: see how to handle the multiple mask formatters that may appear on an AttributeSecurity object
094        /*if (attributeDefinition.getDisplayMask().getMaskFormatter() instanceof MaskFormatterLiteral) {
095            return ((MaskFormatterLiteral)attributeDefinition.getDisplayMask().getMaskFormatter()).getLiteral();
096        }
097        else if (attributeDefinition.getDisplayMask().getMaskFormatter() instanceof MaskFormatterSubString) {
098            return new StringBuffer(((MaskFormatterSubString)attributeDefinition.getDisplayMask().getMaskFormatter()).getMaskLength()).append(" ").append(((MaskFormatterSubString)attributeDefinition.getDisplayMask().getMaskFormatter()).getMaskCharacter()).append(" characters").toString();
099        }
100        else {*/
101            return "Unknown MaskFormatter";
102        //} 
103    }
104
105    public String getNamespaceCode() {
106        return namespaceCode;
107    }
108
109    public void setNamespaceCode(String namespaceCode) {
110        this.namespaceCode = namespaceCode;
111    }
112
113    public String getComponentClass() {
114        return componentClass;
115    }
116
117    public void setComponentClass(String componentClass) {
118        this.componentClass = componentClass;
119    }
120
121    public String getPropertyName() {
122        return propertyName;
123    }
124
125    public void setPropertyName(String propertyName) {
126        this.propertyName = propertyName;
127    }
128
129    public String getTableName() {
130        return tableName;
131    }
132
133    public void setTableName(String tableName) {
134        this.tableName = tableName;
135    }
136
137    public String getFieldName() {
138        return fieldName;
139    }
140
141    public void setFieldName(String fieldName) {
142        this.fieldName = fieldName;
143    }
144
145    public FunctionalFieldDescription getFunctionalFieldDescription() {
146        return functionalFieldDescription;
147    }
148
149    public void setFunctionalFieldDescription(FunctionalFieldDescription functionalFieldDescription) {
150        this.functionalFieldDescription = functionalFieldDescription;
151    }
152
153    
154    protected LinkedHashMap toStringMapper_RICE20_REFACTORME() {
155        return new LinkedHashMap();
156    }
157}