001: /*
002: * GeoTools - OpenSource mapping toolkit
003: * http://geotools.org
004: * (C) 2004-2006, Geotools Project Managment Committee (PMC)
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or (at your option) any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * Created on Jul 30, 2004
017: */
018: package org.geotools.data.vpf;
019:
020: import org.geotools.data.vpf.ifc.DataTypesDefinition;
021: import org.geotools.data.vpf.io.TripletId;
022: import org.geotools.data.vpf.util.DataUtils;
023: import org.geotools.feature.AttributeType;
024: import org.geotools.feature.AttributeTypeFactory;
025: import org.geotools.feature.GeometryAttributeType;
026: import org.geotools.feature.IllegalAttributeException;
027: import org.opengis.filter.Filter;
028:
029: import com.vividsolutions.jts.geom.Geometry;
030:
031: /**
032: * A column in a VPF File.
033: *
034: * @author <a href="mailto:jeff@ionicenterprise.com">Jeff Yutzler</a>
035: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/unsupported/vpf/src/main/java/org/geotools/data/vpf/VPFColumn.java $
036: */
037: public class VPFColumn implements AttributeType, DataTypesDefinition {
038: /**
039: * If the value is a short integer, that often means it has
040: * an accompanying value in a string lookup table.
041: */
042: private boolean attemptLookup = false;
043: /**
044: * The contained attribute type.
045: * AttributeType operations are delegated to this object.
046: */
047: private final AttributeType attribute;
048:
049: /** Describe variable <code>elementsNumber</code> here. */
050: private final int elementsNumber;
051:
052: /** Describe variable <code>narrTable</code> here. */
053: private final String narrTable;
054:
055: /** Describe variable <code>keyType</code> here. */
056: private final char keyType;
057:
058: /** Describe variable <code>colDesc</code> here. */
059: private final String colDesc;
060:
061: /** Describe variable <code>thematicIdx</code> here. */
062: private final String thematicIdx;
063:
064: /** Describe variable <code>type</code> here. */
065: private final char typeChar;
066:
067: /** Describe variable <code>valDescTableName</code> here. */
068: private final String valDescTableName;
069:
070: /**
071: * Constructor with all of the elements of a VPF column
072: * @param name
073: * @param type
074: * @param elementsNumber
075: * @param keyType
076: * @param colDesc
077: * @param valDescTableName
078: * @param thematicIdx
079: * @param narrTable
080: */
081: public VPFColumn(String name, char type, int elementsNumber,
082: char keyType, String colDesc, String valDescTableName,
083: String thematicIdx, String narrTable) {
084: this .typeChar = type;
085: this .elementsNumber = elementsNumber;
086: this .keyType = keyType;
087: this .colDesc = colDesc;
088: this .valDescTableName = valDescTableName;
089: this .thematicIdx = thematicIdx;
090: this .narrTable = narrTable;
091: attribute = AttributeTypeFactory.newAttributeType(name,
092: getColumnClass(), true, getColumnSize());
093: }
094:
095: /**
096: * Retrieves the class for the column,
097: * based on a char value.
098: * @return the class
099: */
100: public Class getColumnClass() {
101: Class columnClass;
102:
103: switch (typeChar) {
104: case DATA_LONG_INTEGER:
105: columnClass = Integer.class;
106:
107: break;
108:
109: case DATA_SHORT_FLOAT:
110: columnClass = Float.class;
111:
112: break;
113:
114: case DATA_LONG_FLOAT:
115: columnClass = Double.class;
116:
117: break;
118:
119: case DATA_2_COORD_F:
120: case DATA_2_COORD_R:
121: case DATA_3_COORD_F:
122: case DATA_3_COORD_R:
123: columnClass = Geometry.class;
124:
125: break;
126:
127: case DATA_TRIPLET_ID:
128: columnClass = TripletId.class;
129:
130: break;
131:
132: // Short integers are usually coded values
133: case DATA_SHORT_INTEGER:
134: attemptLookup = true;
135: // Fall through
136: case DATA_TEXT:
137: case DATA_NULL_FIELD:
138: case DATA_LEVEL1_TEXT:
139: case DATA_LEVEL2_TEXT:
140: case DATA_LEVEL3_TEXT:
141:
142: default:
143: columnClass = String.class;
144:
145: break;
146: }
147:
148: return columnClass;
149: }
150:
151: /* (non-Javadoc)
152: * @see org.geotools.feature.AttributeType#createDefaultValue()
153: */
154: public Object createDefaultValue() {
155: return attribute.createDefaultValue();
156: }
157:
158: /* (non-Javadoc)
159: * @see org.geotools.feature.AttributeType#duplicate(java.lang.Object)
160: */
161: public Object duplicate(Object src)
162: throws IllegalAttributeException {
163: return attribute.duplicate(src);
164: }
165:
166: /**
167: * Gets the size of the column in bytes
168: * @return the size
169: */
170: private int getColumnSize() {
171: return DataUtils.getDataTypeSize(typeChar) * elementsNumber;
172: }
173:
174: // no longer in ft
175: // /* (non-Javadoc)
176: // * @see org.geotools.feature.AttributeType#getFieldLength()
177: // */
178: // public int getFieldLength() {
179: // return attribute.getFieldLength();
180: // }
181:
182: /* (non-Javadoc)
183: * @see org.geotools.feature.AttributeType#getName()
184: */
185: public String getName() {
186: return attribute.getName();
187: }
188:
189: /**
190: * {@inheritDoc}
191: */
192: public String getLocalName() {
193: return attribute.getLocalName();
194: }
195:
196: /**
197: * Gets the value of narrTable
198: *
199: * @return the value of narrTable
200: */
201: public String getNarrTable() {
202: return this .narrTable;
203: }
204:
205: /**
206: * Gets the value of thematicIdx
207: *
208: * @return the value of thematicIdx
209: */
210: public String getThematicIdx() {
211: return this .thematicIdx;
212: }
213:
214: /* (non-Javadoc)
215: * @see org.geotools.feature.AttributeType#getType()
216: */
217: public Class getType() {
218: return attribute.getType();
219: }
220:
221: /**
222: * {@inheritDoc}
223: */
224: public Class getBinding() {
225: return attribute.getBinding();
226: }
227:
228: /**
229: * Gets the value of valDescTableName
230: *
231: * @return the value of valDescTableName
232: */
233: public String getValDescTableName() {
234: return valDescTableName;
235: }
236:
237: /* (non-Javadoc)
238: * @see org.geotools.feature.AttributeType#isGeometry()
239: */
240: public boolean isGeometry() {
241: return attribute instanceof Geometry;
242: }
243:
244: // no longer needed
245: // /* (non-Javadoc)
246: // * @see org.geotools.feature.AttributeType#isNested()
247: // */
248: // public boolean isNested() {
249: // return attribute.isNested();
250: // }
251:
252: /* (non-Javadoc)
253: * @see org.geotools.feature.AttributeType#isNillable()
254: */
255: public boolean isNillable() {
256: return attribute.isNillable();
257: }
258:
259: /* (non-Javadoc)
260: * @see org.geotools.feature.AttributeType#parse(java.lang.Object)
261: */
262: public Object parse(Object value) throws IllegalArgumentException {
263: return attribute.parse(value);
264: }
265:
266: /* (non-Javadoc)
267: * @see org.geotools.feature.AttributeType#validate(java.lang.Object)
268: */
269: public void validate(Object obj) throws IllegalArgumentException {
270: attribute.validate(obj);
271: }
272:
273: /**
274: * Returns the typeChar field
275: *
276: * @return Returns the typeChar.
277: */
278: public char getTypeChar() {
279: return typeChar;
280: }
281:
282: /**
283: * Returns the elementsNumber field
284: *
285: * @return Returns the elementsNumber.
286: */
287: public int getElementsNumber() {
288: return elementsNumber;
289: }
290:
291: /**
292: * Identifies and returns the GeometryAttributeType,
293: * or null if none exists.
294: * @return The <code>GeometryAttributeType</code> value
295: */
296: public GeometryAttributeType getGeometryAttributeType() {
297: GeometryAttributeType result = null;
298:
299: if (isGeometry()) {
300: result = (GeometryAttributeType) attribute;
301: }
302:
303: return result;
304: }
305:
306: /**
307: * @return Returns the attemptLookup.
308: */
309: public boolean isAttemptLookup() {
310: return attemptLookup;
311: }
312:
313: /* (non-Javadoc)
314: * @see org.geotools.feature.AttributeType#getRestriction()
315: */
316: public Filter getRestriction() {
317: return attribute.getRestriction();
318: }
319:
320: /* (non-Javadoc)
321: * @see org.geotools.feature.AttributeType#getMinOccurs()
322: */
323: public int getMinOccurs() {
324: return 1;
325: }
326:
327: /* (non-Javadoc)
328: * @see org.geotools.feature.AttributeType#getMaxOccurs()
329: */
330: public int getMaxOccurs() {
331: return 1;
332: }
333:
334: public boolean equals(Object obj) {
335: return attribute.equals(obj);
336: }
337:
338: public int hashCode() {
339: return attribute.hashCode();
340: }
341: }
|