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 Aug 5, 2004
017: */
018: package org.geotools.data.vpf;
019:
020: import java.net.URI;
021: import java.util.List;
022:
023: import org.geotools.feature.AttributeType;
024: import org.geotools.feature.Feature;
025: import org.geotools.feature.FeatureType;
026: import org.geotools.feature.GeometryAttributeType;
027: import org.geotools.feature.IllegalAttributeException;
028:
029: /**
030: * A VPF feature type. Note that feature classes may contain one
031: * or more feature types. However, all of the feature types of a
032: * feature class share the same schema. A feature type will therefore
033: * delegate its schema related operations to its feature class.
034: *
035: * @author <a href="mailto:jeff@ionicenterprise.com">Jeff Yutzler</a>
036: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/unsupported/vpf/src/main/java/org/geotools/data/vpf/VPFFeatureType.java $
037: */
038: public class VPFFeatureType implements FeatureType {
039: /**
040: * The feature class that this feature type belongs to
041: */
042: private final VPFFeatureClass featureClass;
043: /**
044: * The type name for this specific feature type
045: */
046: private final String typeName;
047: /**
048: * The FACC code, a two-letter, 3-number code
049: * identifying the feature type
050: */
051: private final String faccCode;
052:
053: /**
054: * Constructor
055: * @param cFeatureClass The owning feature class
056: * @param cFeature A <code>Feature</code> from the char.vdt file
057: * with more detailed information for this feature type
058: */
059: public VPFFeatureType(VPFFeatureClass cFeatureClass,
060: Feature cFeature) {
061: featureClass = cFeatureClass;
062: faccCode = cFeature.getAttribute("value").toString().trim();
063: String mainTableFileName = cFeature.getAttribute("table")
064: .toString().trim();
065:
066: String tempTypeName = cFeature.getAttribute("description")
067: .toString().trim();
068:
069: // This block helps us give tables a distinguishing suffix
070: try {
071: int index = mainTableFileName.lastIndexOf(".") + 1;
072: String dimensionality = mainTableFileName.substring(index,
073: index + 1).toLowerCase();
074: if (dimensionality.equals("a")) {
075: tempTypeName = tempTypeName.concat(" Area");
076: } else if (dimensionality.equals("l")) {
077: tempTypeName = tempTypeName.concat(" Line");
078: } else if (dimensionality.equals("p")) {
079: tempTypeName = tempTypeName.concat(" Point");
080: } else if (dimensionality.equals("t")) {
081: tempTypeName = tempTypeName.concat(" Text");
082: }
083: } catch (RuntimeException e) {
084: // If this does not work, no big deal
085: }
086: tempTypeName = tempTypeName.toUpperCase();
087: tempTypeName = tempTypeName.replace(' ', '_');
088: tempTypeName = tempTypeName.replace('/', '_');
089: tempTypeName = tempTypeName.replace('(', '_');
090: tempTypeName = tempTypeName.replace(')', '_');
091: typeName = tempTypeName;
092: }
093:
094: /**
095: * A constructor for feature types with no information
096: * in a char.vdt file.
097: * @param cFeatureClass The owning feature class
098: */
099: public VPFFeatureType(VPFFeatureClass cFeatureClass) {
100: featureClass = cFeatureClass;
101: faccCode = null;
102: typeName = cFeatureClass.getTypeName().toUpperCase();
103:
104: }
105:
106: /* (non-Javadoc)
107: * @see org.geotools.feature.FeatureFactory#create(java.lang.Object[])
108: */
109: public Feature create(Object[] attributes)
110: throws IllegalAttributeException {
111: return featureClass.create(attributes);
112: }
113:
114: /* (non-Javadoc)
115: * @see org.geotools.feature.FeatureFactory#create(java.lang.Object[], java.lang.String)
116: */
117: public Feature create(Object[] attributes, String featureID)
118: throws IllegalAttributeException {
119: return featureClass.create(attributes, featureID);
120: }
121:
122: /* (non-Javadoc)
123: * @see org.geotools.feature.FeatureType#duplicate(org.geotools.feature.Feature)
124: */
125: public Feature duplicate(Feature feature)
126: throws IllegalAttributeException {
127: return featureClass.duplicate(feature);
128: }
129:
130: /* (non-Javadoc)
131: * @see org.geotools.feature.FeatureType#find(org.geotools.feature.AttributeType)
132: */
133: public int find(AttributeType type) {
134: return featureClass.find(type);
135: }
136:
137: /* (non-Javadoc)
138: * @see org.geotools.feature.FeatureType#getAncestors()
139: */
140: public FeatureType[] getAncestors() {
141: return featureClass.getAncestors();
142: }
143:
144: /* (non-Javadoc)
145: * @see org.geotools.feature.FeatureType#getAttributeCount()
146: */
147: public int getAttributeCount() {
148: return featureClass.getAttributeCount();
149: }
150:
151: /* (non-Javadoc)
152: * @see org.geotools.feature.FeatureType#getAttributeType(int)
153: */
154: public AttributeType getAttributeType(int position) {
155: return featureClass.getAttributeType(position);
156: }
157:
158: /* (non-Javadoc)
159: * @see org.geotools.feature.FeatureType#getAttributeType(java.lang.String)
160: */
161: public AttributeType getAttributeType(String xPath) {
162: return featureClass.getAttributeType(xPath);
163: }
164:
165: /* (non-Javadoc)
166: * @see org.geotools.feature.FeatureType#getAttributeTypes()
167: */
168: public AttributeType[] getAttributeTypes() {
169: return featureClass.getAttributeTypes();
170: }
171:
172: /**
173: * @return The <code>VPFCoverage</code> that this <code>FeatureType</code>
174: * belongs to.
175: */
176: public VPFCoverage getCoverage() {
177: return featureClass.getCoverage();
178: }
179:
180: /* (non-Javadoc)
181: * @see org.geotools.feature.FeatureType#getDefaultGeometry()
182: */
183: public GeometryAttributeType getDefaultGeometry() {
184: return featureClass.getDefaultGeometry();
185: }
186:
187: /* (non-Javadoc)
188: * @see org.geotools.feature.FeatureType#getPrimaryGeometry()
189: */
190: public GeometryAttributeType getPrimaryGeometry() {
191: return featureClass.getPrimaryGeometry();
192: }
193:
194: /**
195: * @return The <code>String</code> path for the directory containing the
196: * <code>VPFFeatureClass</code> that this <code>FeatureType</code>
197: * belongs to.
198: */
199: public String getDirectoryName() {
200: return featureClass.getDirectoryName();
201: }
202:
203: /**
204: * @return Returns the featureClass.
205: */
206: public VPFFeatureClass getFeatureClass() {
207: return featureClass;
208: }
209:
210: /**
211: * Returns a list of file objects
212: *
213: * @return A <code>List</code> containing <code>VPFFile</code> objects.
214: */
215: public List getFileList() {
216: return featureClass.getFileList();
217: }
218:
219: /**
220: * @return A <code>List</code> containing the <code>ColumnPair</code>
221: * objects which identify the file joins for the
222: * <code>VPFFeatureClass</code> that this <code>FeatureType</code>
223: * belongs to.
224: */
225: public List getJoinList() {
226: return featureClass.getJoinList();
227: }
228:
229: /* (non-Javadoc)
230: * @see org.geotools.feature.FeatureType#getNamespace()
231: */
232: public URI getNamespace() {
233: return featureClass.getNamespace();
234: }
235:
236: // /* (non-Javadoc)
237: // * @see org.geotools.feature.FeatureType#getNamespace()
238: // */
239: // public URI getNamespaceURI() {
240: // return featureClass.getNamespaceURI();
241: // }
242:
243: /* (non-Javadoc)
244: * @see org.geotools.feature.FeatureType#getTypeName()
245: */
246: public String getTypeName() {
247: return typeName;
248: }
249:
250: /* (non-Javadoc)
251: * @see org.geotools.feature.FeatureType#hasAttributeType(java.lang.String)
252: */
253: public boolean hasAttributeType(String xPath) {
254: return featureClass.hasAttributeType(xPath);
255: }
256:
257: /* (non-Javadoc)
258: * @see org.geotools.feature.FeatureType#isAbstract()
259: */
260: public boolean isAbstract() {
261: return featureClass.isAbstract();
262: }
263:
264: /* (non-Javadoc)
265: * @see org.geotools.feature.FeatureType#isDescendedFrom(org.geotools.feature.FeatureType)
266: */
267: public boolean isDescendedFrom(FeatureType type) {
268: return featureClass.isDescendedFrom(type);
269: }
270:
271: /* (non-Javadoc)
272: * @see org.geotools.feature.FeatureType#isDescendedFrom(java.lang.String, java.lang.String)
273: */
274: public boolean isDescendedFrom(URI nsURI, String typeName) {
275: return featureClass.isDescendedFrom(nsURI, typeName);
276: }
277:
278: /**
279: * The FACC code, a two-letter, 3-number code
280: * identifying the feature type
281: * @return Returns the FACC Code.
282: */
283: public String getFaccCode() {
284: return faccCode;
285: }
286:
287: /* (non-Javadoc)
288: * @see org.geotools.feature.FeatureType#find(java.lang.String)
289: */
290: public int find(String attName) {
291: return featureClass.find(attName);
292: }
293:
294: public boolean equals(Object obj) {
295: return featureClass.equals(obj);
296: }
297:
298: public int hashCode() {
299: return featureClass.hashCode();
300: }
301:
302: }
|