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.global.dto;
006:
007: import java.util.logging.Logger;
008:
009: /**
010: * Represents most of a xs:element for an XMLSchema.
011: *
012: * <p>
013: * we have three types of information to store, Schema defined types,
014: * references and extentions on types. If the type represented is either a
015: * reference or a Schema defined type then isRef should be true.
016: * </p>
017: *
018: * <p>
019: * Non-complex types are of the form:
020: * </p>
021: *
022: * <ul>
023: * <li>
024: * <code>{element name='test' type='xs:string'/}</code>
025: * </li>
026: * <li>
027: * <code>{element name='test' type='gml:PointType'/}</code>
028: * </li>
029: * </ul>
030: *
031: * <p>
032: * For complex types such as <code>{element
033: * name='test'}{xs:complexContent}{xs:extension
034: * base="gml:AbstractFeatureType"}{xs:sequence}{xs:element name="id"
035: * type="xs:string" minOccurs="0"/}{xs:element ref="gml:pointProperty"
036: * minOccurs="0"/}{/xs:sequence}{/xs:extension}{/xs:complexContent}{/element}</code>
037: * The type contains a similar XML fragment.
038: * </p>
039: *
040: * <p>
041: * minOccurs, maxOccurs and nillable are all attributes for all cases. There is
042: * more stuff in the XMLSchema spec but we don't care.
043: * </p>
044: *
045: * @author dzwiers, Refractions Research, Inc.
046: * @version $Id: AttributeTypeInfoDTO.java 7746 2007-11-13 15:38:35Z aaime $
047: */
048: public class AttributeTypeInfoDTO implements DataTransferObject {
049: /** For debugging */
050: private static final Logger LOGGER = org.geotools.util.logging.Logging
051: .getLogger("org.vfny.geoserver.global.dto");
052:
053: /** attribute name */
054: private String name;
055:
056: /** attribute min occurs */
057: private int minOccurs = 0;
058:
059: /** attribute max occurs */
060: private int maxOccurs = 1;
061:
062: /** true when nillable */
063: private boolean nillable = true;
064:
065: /**
066: * if is ref and a name is specified, then treat like a simple type (same
067: * thing ...) otherwise this is a complex type.
068: */
069: private String type;
070:
071: /**
072: * This is true when type is complex.
073: *
074: * <p>
075: * This is used to denote that type proerty is an XML fragment, rather than
076: * type a type declaration. type declaration must be from
077: * GMLUtils.xmlSchemaType or gmlTypes but not baseGMLTypes.
078: * </p>
079: *
080: * <p>
081: * baseGMLTypes can only be used in your XML fragment.
082: * </p>
083: */
084: private boolean isComplex = false;
085:
086: /**
087: * AttributeTypeInfoDTO constructor, see DataTransferObjectFactory.
088: *
089: * <p>
090: * Default constructor, does nothing
091: * </p>
092: */
093: public AttributeTypeInfoDTO() {
094: }
095:
096: /**
097: * AttributeTypeInfoDTO constructor, see DataTransferObjectFactory.
098: *
099: * <p>
100: * Copies the data from the specified DTO to this one.
101: * </p>
102: *
103: * @param dto AttributeTypeInfoDTO The data source to copy from.
104: */
105: public AttributeTypeInfoDTO(AttributeTypeInfoDTO dto) {
106: name = dto.getName();
107: type = dto.getType();
108: minOccurs = dto.getMinOccurs();
109: maxOccurs = dto.getMaxOccurs();
110: nillable = dto.isNillable();
111: isComplex = dto.isComplex();
112: }
113:
114: /**
115: * Implement equals.
116: *
117: * <p>
118: * true when the data contained inside the objects is the same.
119: * </p>
120: *
121: * @param obj an instance of AttributeTypeInfoDTO to compare
122: *
123: * @return true when they are the same, false otherwise
124: *
125: * @see java.lang.Object#equals(java.lang.Object)
126: */
127: public boolean equals(Object obj) {
128: boolean r = true;
129:
130: if ((obj == null) || !(obj instanceof AttributeTypeInfoDTO)) {
131: return false;
132: }
133:
134: AttributeTypeInfoDTO dto = (AttributeTypeInfoDTO) obj;
135: r = r && (name == dto.getName());
136: r = r && (type == dto.getType());
137: r = r && (minOccurs == dto.getMinOccurs());
138: r = r && (maxOccurs == dto.getMaxOccurs());
139: r = r && (nillable == dto.isNillable());
140: r = r && (isComplex == dto.isComplex());
141:
142: return r;
143: }
144:
145: /**
146: * Implement hashCode.
147: *
148: * <p>
149: * The hashcode for this object.
150: * </p>
151: *
152: * @return a hashcode value.
153: *
154: * @see java.lang.Object#hashCode()
155: */
156: public int hashCode() {
157: return name.hashCode() * type.hashCode();
158: }
159:
160: /**
161: * Implement clone.
162: *
163: * <p>
164: * An instance of AttributeTypeInfoDTO which is the same as this one.
165: * </p>
166: *
167: * @return Object a copy of this object.
168: *
169: * @see java.lang.Object#clone()
170: */
171: public Object clone() {
172: AttributeTypeInfoDTO dto = new AttributeTypeInfoDTO();
173: dto.setMaxOccurs(maxOccurs);
174: dto.setMinOccurs(minOccurs);
175: dto.setName(name);
176: dto.setNillable(nillable);
177: dto.setComplex(isComplex);
178: dto.setType(type);
179:
180: return dto;
181: }
182:
183: /**
184: * isRef purpose.
185: *
186: * <p>
187: * Returns is this is a reference element type or a document defined type.
188: * </p>
189: *
190: * @return true when either a ref or XMLSchema type.
191: */
192: public boolean isComplex() {
193: return isComplex;
194: }
195:
196: /**
197: * getMaxOccurs purpose.
198: *
199: * <p>
200: * The max number of occurences for this element.
201: * </p>
202: *
203: * @return max number of occurences
204: */
205: public int getMaxOccurs() {
206: return maxOccurs;
207: }
208:
209: /**
210: * getMinOccurs purpose.
211: *
212: * <p>
213: * the min number of occurences for this element
214: * </p>
215: *
216: * @return min number of occurences
217: */
218: public int getMinOccurs() {
219: return minOccurs;
220: }
221:
222: /**
223: * getName purpose.
224: *
225: * <p>
226: * returns the element name
227: * </p>
228: *
229: * @return the element name
230: */
231: public String getName() {
232: return name;
233: }
234:
235: /**
236: * isNillable purpose.
237: *
238: * <p>
239: * Description ...
240: * </p>
241: *
242: * @return
243: */
244: public boolean isNillable() {
245: return nillable;
246: }
247:
248: /**
249: * getType purpose.
250: *
251: * <p>
252: * returns the element type. This is an XML fragment if isRef() returns
253: * false.
254: * </p>
255: *
256: * @return the element type. This is an XML fragment if isRef() returns
257: * false.
258: */
259: public String getType() {
260: return type;
261: }
262:
263: /**
264: * setRef purpose.
265: *
266: * <p>
267: * Sets whether this is a reference type element or not
268: * </p>
269: *
270: * @param b true when this is a reference type element.
271: */
272: public void setComplex(boolean b) {
273: isComplex = b;
274: }
275:
276: /**
277: * setMaxOccurs purpose.
278: *
279: * <p>
280: * Stores the max occurs for the element
281: * </p>
282: *
283: * @param i the max occurs for the element
284: */
285: public void setMaxOccurs(int i) {
286: maxOccurs = i;
287: }
288:
289: /**
290: * setMinOccurs purpose.
291: *
292: * <p>
293: * Stores the min occurs for the element
294: * </p>
295: *
296: * @param i the min occurs for the element
297: */
298: public void setMinOccurs(int i) {
299: minOccurs = i;
300: }
301:
302: /**
303: * setName purpose.
304: *
305: * <p>
306: * Stores the name for the element
307: * </p>
308: *
309: * @param string the name for the element
310: */
311: public void setName(String string) {
312: name = string;
313: }
314:
315: /**
316: * setNillable purpose.
317: *
318: * <p>
319: * Stores if this element is nillable
320: * </p>
321: *
322: * @param b true when this element is nillable
323: */
324: public void setNillable(boolean b) {
325: nillable = b;
326: }
327:
328: /**
329: * setType purpose.
330: *
331: * <p>
332: * Stores the type for this element. This is an XML fragment when isRef()
333: * returns false.
334: * </p>
335: *
336: * @param string type for this element. This is an XML fragment when
337: * isRef() returns false.
338: */
339: public void setType(String string) {
340: type = string;
341: }
342:
343: public String toString() {
344: return "[AttributeTypeInfoDTO " + name + " minOccurs="
345: + minOccurs + " maxOccurs=" + maxOccurs + " nillable="
346: + nillable + " type=" + type + " isComplex="
347: + isComplex + "]";
348: }
349: }
|