001: /*
002: * Copyright 2005-2006 The Kuali Foundation.
003: *
004: * Licensed under the Educational Community License, Version 1.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/ecl1.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.core.datadictionary.exporter;
017:
018: import java.math.BigDecimal;
019: import java.util.Iterator;
020: import java.util.Map;
021:
022: import org.kuali.core.datadictionary.AttributeDefinition;
023: import org.kuali.core.datadictionary.DataDictionaryEntryBase;
024: import org.kuali.core.datadictionary.control.ControlDefinition;
025: import org.kuali.core.datadictionary.control.CurrencyControlDefinition;
026:
027: /**
028: * AttributesMapBuilder
029: *
030: *
031: */
032: public class AttributesMapBuilder {
033:
034: /**
035: * Default constructor
036: */
037: public AttributesMapBuilder() {
038: }
039:
040: /**
041: * @param entry
042: * @return ExportMap containing the standard entries for the entry's AttributesDefinition
043: */
044: public ExportMap buildAttributesMap(DataDictionaryEntryBase entry) {
045: ExportMap attributesMap = new ExportMap("attributes");
046:
047: for (Iterator i = entry.getAttributes().entrySet().iterator(); i
048: .hasNext();) {
049: Map.Entry e = (Map.Entry) i.next();
050:
051: AttributeDefinition attribute = (AttributeDefinition) e
052: .getValue();
053: attributesMap.set(buildAttributeMap(attribute, entry
054: .getFullClassName()));
055: }
056:
057: return attributesMap;
058: }
059:
060: private ExportMap buildAttributeMap(AttributeDefinition attribute,
061: String fullClassName) {
062: ExportMap attributeMap = new ExportMap(attribute.getName());
063:
064: // simple properties
065: attributeMap.set("name", attribute.getName());
066: attributeMap.set("forceUppercase", attribute
067: .getForceUppercase().toString());
068: attributeMap.set("label", attribute.getLabel());
069: attributeMap.set("shortLabel", attribute.getShortLabel());
070: attributeMap.set("maxLength", attribute.getMaxLength()
071: .toString());
072: final BigDecimal exclusiveMin = attribute.getExclusiveMin();
073: if (exclusiveMin != null) {
074: attributeMap.set("exclusiveMin", exclusiveMin.toString());
075: }
076: final BigDecimal exclusiveMax = attribute.getInclusiveMax();
077: if (exclusiveMax != null) {
078: attributeMap.set("exclusiveMax", exclusiveMax.toString());
079: }
080:
081: attributeMap.set("required", attribute.isRequired().toString());
082: if (attribute.getSummary() != null) {
083: attributeMap.set("summary", attribute.getSummary());
084: }
085: if (attribute.getDescription() != null) {
086: attributeMap.set("description", attribute.getDescription());
087: }
088: if (attribute.hasFormatterClass()) {
089: attributeMap.set("formatterClass", attribute
090: .getFormatterClass().getName());
091: }
092:
093: // complex properties
094: if (attribute.hasValidationPattern()) {
095: attributeMap.set(attribute.getValidationPattern()
096: .buildExportMap("validationPattern"));
097: }
098:
099: if (attribute.hasDisplayMask()) {
100: attributeMap.set("displayWorkgroup", attribute
101: .getDisplayWorkgroup());
102: attributeMap.set("displayMaskClass", attribute
103: .getDisplayMask().getClass().toString());
104: }
105:
106: attributeMap.set(buildControlMap(attribute));
107: attributeMap.set("fullClassName", fullClassName);
108:
109: return attributeMap;
110: }
111:
112: private ExportMap buildControlMap(AttributeDefinition attribute) {
113: ControlDefinition control = attribute.getControl();
114: ExportMap controlMap = new ExportMap("control");
115:
116: if (control.isCheckbox()) {
117: controlMap.set("checkbox", "true");
118: } else if (control.isHidden()) {
119: controlMap.set("hidden", "true");
120: } else if (control.isKualiUser()) {
121: controlMap.set("kualiUser", "true");
122: } else if (control.isRadio()) {
123: controlMap.set("radio", "true");
124: controlMap.set("valuesFinder", control
125: .getValuesFinderClass().getName());
126: } else if (control.isSelect()) {
127: controlMap.set("select", "true");
128: controlMap.set("valuesFinder", control
129: .getValuesFinderClass().getName());
130: } else if (control.isText()) {
131: controlMap.set("text", "true");
132: controlMap.set("size", control.getSize().toString());
133: } else if (control.isTextarea()) {
134: controlMap.set("textarea", "true");
135: controlMap.set("rows", control.getRows().toString());
136: controlMap.set("cols", control.getCols().toString());
137: } else if (control.isCurrency()) {
138: controlMap.set("currency", "true");
139: controlMap.set("size", control.getSize().toString());
140: controlMap.set("formattedMaxLength",
141: ((CurrencyControlDefinition) control)
142: .getFormattedMaxLength().toString());
143: } else if (control.isLookupHidden()) {
144: controlMap.set("lookupHidden", "true");
145: } else if (control.isLookupReadonly()) {
146: controlMap.set("lookupReadonly", "true");
147: }
148:
149: return controlMap;
150: }
151: }
|