001: /* Copyright (c) 2001 - 2007 TOPP - www.openplans.org. All rights reserved.
002: * This code is licensed under the GPL 2.0 license, availible at the root
003: * application directory.
004: */
005: package org.vfny.geoserver.form.data;
006:
007: import org.geotools.feature.AttributeType;
008: import org.vfny.geoserver.config.AttributeTypeInfoConfig;
009: import org.vfny.geoserver.global.dto.AttributeTypeInfoDTO;
010: import org.vfny.geoserver.global.dto.DataTransferObjectFactory;
011: import org.vfny.geoserver.global.xml.NameSpaceElement;
012: import java.util.ArrayList;
013: import java.util.Iterator;
014: import java.util.List;
015:
016: /**
017: * Present Attribute information for user input.
018: */
019: public class AttributeForm {
020: private String name;
021: private boolean nillable;
022: private String minOccurs;
023: private String maxOccurs;
024: private String type;
025: private String fragment;
026: private AttributeType attributeType;
027:
028: public AttributeForm(AttributeTypeInfoConfig config,
029: AttributeType attribute) {
030: name = config.getName();
031: nillable = config.isNillable();
032:
033: minOccurs = String.valueOf(config.getMinOccurs());
034: maxOccurs = String.valueOf(config.getMaxOccurs());
035: type = config.getType();
036: fragment = config.getFragment();
037:
038: attributeType = attribute;
039: }
040:
041: public AttributeTypeInfoDTO toDTO() {
042: AttributeTypeInfoDTO dto = new AttributeTypeInfoDTO();
043: dto.setName(name);
044: dto.setNillable(nillable);
045: dto.setMinOccurs(Integer.parseInt(minOccurs));
046: dto.setMaxOccurs(Integer.parseInt(maxOccurs));
047:
048: if (AttributeTypeInfoConfig.TYPE_FRAGMENT.equals(type)) {
049: dto.setComplex(true);
050: dto.setType(fragment);
051: } else {
052: dto.setComplex(false);
053: dto.setType(type);
054: }
055:
056: return dto;
057: }
058:
059: public AttributeTypeInfoConfig toConfig() {
060: return new AttributeTypeInfoConfig(toDTO());
061: }
062:
063: /**
064: * @return Returns the fragment.
065: */
066: public String getFragment() {
067: return fragment;
068: }
069:
070: /**
071: * @param fragment The fragment to set.
072: */
073: public void setFragment(String fragment) {
074: this .fragment = fragment;
075: }
076:
077: /**
078: * @return Returns the maxOccurs.
079: */
080: public String getMaxOccurs() {
081: return maxOccurs;
082: }
083:
084: /**
085: * @param maxOccurs The maxOccurs to set.
086: */
087: public void setMaxOccurs(String maxOccurs) {
088: this .maxOccurs = maxOccurs;
089: }
090:
091: /**
092: * @return Returns the minOccurs.
093: */
094: public String getMinOccurs() {
095: return minOccurs;
096: }
097:
098: /**
099: * @param minOccurs The minOccurs to set.
100: */
101: public void setMinOccurs(String minOccurs) {
102: this .minOccurs = minOccurs;
103: }
104:
105: /**
106: * @return Returns the name.
107: */
108: public String getName() {
109: return name;
110: }
111:
112: /**
113: * @param name The name to set.
114: */
115: public void setName(String name) {
116: this .name = name;
117: }
118:
119: /**
120: * @return Returns the nillible.
121: */
122: public boolean isNillable() {
123: return nillable;
124: }
125:
126: /**
127: * @param nillible The nillible to set.
128: */
129: public void setNillable(boolean nillible) {
130: this .nillable = nillible;
131: }
132:
133: /**
134: * @return Returns the selectedType.
135: */
136: public String getType() {
137: return type;
138: }
139:
140: /**
141: * @param selectedType The selectedType to set.
142: */
143: public void setType(String selectedType) {
144: this .type = selectedType;
145: }
146:
147: /**
148: * AttributeType used to limit getType.
149: *
150: * @return AttributeType
151: */
152: public AttributeType getAttributeType() {
153: return attributeType;
154: }
155:
156: /**
157: * List of Types available for this attribtue.
158: * <p>
159: * The names are returned as references (like xs:string).
160: * </p>
161: */
162: public List getTypes() {
163: List elements = DataTransferObjectFactory.getElements(name,
164: attributeType.getType());
165: List list = new ArrayList(elements.size());
166:
167: for (Iterator i = elements.iterator(); i.hasNext();) {
168: NameSpaceElement element = (NameSpaceElement) i.next();
169:
170: if (!element.isAbstract()) {
171: list.add(element.getTypeDefName());
172: }
173: }
174:
175: list.add(AttributeTypeInfoConfig.TYPE_FRAGMENT);
176:
177: return list;
178: }
179: }
|