001: /*
002: * GeoTools - OpenSource mapping toolkit
003: * http://geotools.org
004: * (C) 2005-2006, Geotools Project Managment Committee (PMC)
005: * (C) 2003-2004, Julian J. Ray, All Rights Reserved
006: *
007: * This library is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU Lesser General Public
009: * License as published by the Free Software Foundation; either
010: * version 2.1 of the License, or (at your option) any later version.
011: *
012: * This library is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: */
017: package org.geotools.data.tiger;
018:
019: import java.util.Hashtable;
020:
021: /**
022: * <p>
023: * Title: GeoTools2 Development
024: * </p>
025: *
026: * <p>
027: * Description:
028: * </p>
029: *
030: * <p>
031: * Copyright: Copyright (c) 2003
032: * </p>
033: *
034: * <p>
035: * Company:
036: * </p>
037: *
038: * @author Julian J. Ray
039: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/unsupported/tiger/src/main/java/org/geotools/data/tiger/TigerSchemaManager.java $
040: * @version 1.0
041: */
042: public class TigerSchemaManager {
043: // These are the typeNames supported by the DataStore
044:
045: /** DOCUMENT ME! */
046: private static final String[] typeNames = { "HIGHWAYS",
047: "RAILROADS", "OTHER_TRANSPORTATION", "HYDROGRAPHY",
048: "LANDMARKS", "PHYSICAL_FEATURES" };
049:
050: // CFCC Codes used to map Type1 features to typeNames
051:
052: /** DOCUMENT ME! */
053: private static final String[] typeNameKeys = { "A", "B", "C", "H",
054: "D", "E" };
055:
056: /** DOCUMENT ME! */
057: private TigerSchemaElement[] highwayAttributes;
058:
059: /** DOCUMENT ME! */
060: private TigerSchemaElement[] railroadAttributes;
061:
062: /** DOCUMENT ME! */
063: private TigerSchemaElement[] otherTransAttributes;
064:
065: /** DOCUMENT ME! */
066: private TigerSchemaElement[] hydroAttributes;
067:
068: /** DOCUMENT ME! */
069: private TigerSchemaElement[] landmarkAttributes;
070:
071: /** DOCUMENT ME! */
072: private TigerSchemaElement[] physicalAttributes;
073:
074: /** DOCUMENT ME! */
075: private Hashtable schemaMapping;
076:
077: /** DOCUMENT ME! */
078: private Hashtable typeNameKey;
079:
080: /**
081: * TigerSchemaManager
082: */
083: public TigerSchemaManager() {
084: highwayAttributes = new TigerSchemaElement[14];
085: highwayAttributes[0] = new TigerSchemaElement("TLID",
086: "Integer", 5, 15);
087: highwayAttributes[1] = new TigerSchemaElement("Fedirp",
088: "String", 17, 19);
089: highwayAttributes[2] = new TigerSchemaElement("Fename",
090: "String", 19, 49);
091: highwayAttributes[3] = new TigerSchemaElement("Fetype",
092: "String", 49, 53);
093: highwayAttributes[4] = new TigerSchemaElement("Fedirs",
094: "String", 53, 55);
095: highwayAttributes[5] = new TigerSchemaElement("Ctype",
096: "String", 55, 56); // Classification type always 'A'
097: highwayAttributes[6] = new TigerSchemaElement("Ccode",
098: "String", 56, 58); // Classification sub-code
099: highwayAttributes[7] = new TigerSchemaElement("Fraddl",
100: "String", 58, 69);
101: highwayAttributes[8] = new TigerSchemaElement("Toaddl",
102: "String", 69, 80);
103: highwayAttributes[9] = new TigerSchemaElement("Fraddr",
104: "String", 80, 91);
105: highwayAttributes[10] = new TigerSchemaElement("Toaddr",
106: "String", 91, 102);
107: highwayAttributes[11] = new TigerSchemaElement("Zipl",
108: "String", 106, 111);
109: highwayAttributes[12] = new TigerSchemaElement("Zipr",
110: "String", 111, 116);
111: highwayAttributes[13] = new TigerSchemaElement("Geometry",
112: "Geometry", -1, -1);
113:
114: railroadAttributes = new TigerSchemaElement[5];
115: railroadAttributes[0] = new TigerSchemaElement("TLID",
116: "Integer", 5, 15);
117: railroadAttributes[1] = new TigerSchemaElement("Name",
118: "String", 19, 49);
119: railroadAttributes[2] = new TigerSchemaElement("Ctype",
120: "String", 55, 56); // Classification type always 'B'
121: railroadAttributes[3] = new TigerSchemaElement("Ccode",
122: "String", 56, 58); // Classification sub-code
123: railroadAttributes[4] = new TigerSchemaElement("Geometry",
124: "Geometry", -1, -1);
125:
126: hydroAttributes = new TigerSchemaElement[5];
127: hydroAttributes[0] = new TigerSchemaElement("TLID", "Integer",
128: 5, 15);
129: hydroAttributes[1] = new TigerSchemaElement("Name", "String",
130: 19, 49);
131: hydroAttributes[2] = new TigerSchemaElement("Ctype", "String",
132: 55, 56); // Classification type
133: hydroAttributes[3] = new TigerSchemaElement("Ccode", "String",
134: 56, 58); // Classification sub-code
135: hydroAttributes[4] = new TigerSchemaElement("Geometry",
136: "Geometry", -1, -1);
137:
138: otherTransAttributes = new TigerSchemaElement[5];
139: otherTransAttributes[0] = new TigerSchemaElement("TLID",
140: "Integer", 5, 15);
141: otherTransAttributes[1] = new TigerSchemaElement("Name",
142: "String", 19, 49);
143: otherTransAttributes[2] = new TigerSchemaElement("Ctype",
144: "String", 55, 56); // Classification type
145: otherTransAttributes[3] = new TigerSchemaElement("Ccode",
146: "String", 56, 58); // Classification sub-code
147: otherTransAttributes[4] = new TigerSchemaElement("Geometry",
148: "Geometry", -1, -1);
149:
150: landmarkAttributes = new TigerSchemaElement[5];
151: landmarkAttributes[0] = new TigerSchemaElement("TLID",
152: "Integer", 5, 15);
153: landmarkAttributes[1] = new TigerSchemaElement("Name",
154: "String", 19, 49);
155: landmarkAttributes[2] = new TigerSchemaElement("Ctype",
156: "String", 55, 56); // Classification type
157: landmarkAttributes[3] = new TigerSchemaElement("Ccode",
158: "String", 56, 58); // Classification sub-code
159: landmarkAttributes[4] = new TigerSchemaElement("Geometry",
160: "Geometry", -1, -1);
161:
162: physicalAttributes = new TigerSchemaElement[5];
163: physicalAttributes[0] = new TigerSchemaElement("TLID",
164: "Integer", 5, 15);
165: physicalAttributes[1] = new TigerSchemaElement("Name",
166: "String", 19, 49);
167: physicalAttributes[2] = new TigerSchemaElement("Ctype",
168: "String", 55, 56); // Classification type
169: physicalAttributes[3] = new TigerSchemaElement("Ccode",
170: "String", 56, 58); // Classification sub-code
171: physicalAttributes[4] = new TigerSchemaElement("Geometry",
172: "Geometry", -1, -1);
173:
174: // Store the mapping between type names and schema structure for fast access
175: schemaMapping = new Hashtable();
176: schemaMapping.put(typeNames[0], highwayAttributes);
177: schemaMapping.put(typeNames[1], railroadAttributes);
178: schemaMapping.put(typeNames[2], otherTransAttributes);
179: schemaMapping.put(typeNames[3], hydroAttributes);
180: schemaMapping.put(typeNames[4], landmarkAttributes);
181: schemaMapping.put(typeNames[5], physicalAttributes);
182:
183: // Set up the typeName mapping
184: typeNameKey = new Hashtable();
185:
186: for (int i = 0; i < typeNames.length; i++) {
187: typeNameKey.put(typeNames[i], typeNameKeys[i]);
188: }
189: }
190:
191: /**
192: * Returns a list of typeNames supported by this version of the DataStore
193: *
194: * @return String[]
195: */
196: public static String[] getTypeNames() {
197: return typeNames;
198: }
199:
200: /**
201: * Returns the schema mapping for a given typeName. The schema mapping is used to extract attributes from a
202: * TIGER/Line
203: *
204: * @param typeName String
205: *
206: * @return TigerSchemaElement[]
207: */
208: public TigerSchemaElement[] getSchema(String typeName) {
209: TigerSchemaElement[] schema = (TigerSchemaElement[]) schemaMapping
210: .get(typeName);
211: if (null == schema) {
212: String typeNameString = getTypeSubNameString(typeName);
213: schema = (TigerSchemaElement[]) schemaMapping
214: .get(typeNameString);
215: }
216: return schema;
217: }
218:
219: /**
220: * Returns a string containing the attribute properties for the given typeName. This is used to construct the
221: * AttributeType array for a Feature.
222: *
223: * @param typeName String
224: *
225: * @return String
226: */
227: public String getTypeSpec(String typeName) {
228: TigerSchemaElement[] atts = getSchema(typeName);
229: StringBuffer buffer = new StringBuffer();
230:
231: for (int i = 0; i < atts.length; i++) {
232: buffer.append(atts[i].getAttributeName());
233: buffer.append(":");
234: buffer.append(atts[i].getClassType());
235:
236: if (i != (atts.length - 1)) {
237: buffer.append(",");
238: }
239: }
240:
241: return buffer.toString();
242: }
243:
244: /**
245: * getTypeKey
246: *
247: * @param typeName String
248: *
249: * @return String
250: */
251: protected String getTypeKey(String typeName) {
252: return (String) typeNameKey.get(typeName);
253: }
254:
255: /**
256: * getTypeSubNameString
257: *
258: * @param inputName String
259: *
260: * @return String
261: */
262: public static String getTypeSubNameString(String inputName) {
263: int index = inputName.indexOf("_");
264:
265: if (index > 0) {
266: return inputName.substring(index + 1);
267: } else {
268: return inputName;
269: }
270: }
271: }
|