Source Code Cross Referenced for Types.java in  » GIS » deegree » org » deegree » datatypes » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » GIS » deegree » org.deegree.datatypes 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        //$HeadURL: https://svn.wald.intevation.org/svn/deegree/base/trunk/src/org/deegree/datatypes/Types.java $
002:        /*----------------    FILE HEADER  ------------------------------------------
003:
004:         This file is part of deegree.
005:         Copyright (C) 2001-2008 by:
006:         EXSE, Department of Geography, University of Bonn
007:         http://www.giub.uni-bonn.de/deegree/
008:         lat/lon GmbH
009:         http://www.lat-lon.de
010:
011:         This library is free software; you can redistribute it and/or
012:         modify it under the terms of the GNU Lesser General Public
013:         License as published by the Free Software Foundation; either
014:         version 2.1 of the License, or (at your option) any later version.
015:
016:         This library is distributed in the hope that it will be useful,
017:         but WITHOUT ANY WARRANTY; without even the implied warranty of
018:         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
019:         Lesser General Public License for more details.
020:
021:         You should have received a copy of the GNU Lesser General Public
022:         License along with this library; if not, write to the Free Software
023:         Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
024:
025:         Contact:
026:
027:         Andreas Poth
028:         lat/lon GmbH
029:         Aennchenstr. 19
030:         53115 Bonn
031:         Germany
032:         E-Mail: poth@lat-lon.de
033:
034:         Prof. Dr. Klaus Greve
035:         Department of Geography
036:         University of Bonn
037:         Meckenheimer Allee 166
038:         53115 Bonn
039:         Germany
040:         E-Mail: greve@giub.uni-bonn.de
041:
042:         ---------------------------------------------------------------------------*/
043:        package org.deegree.datatypes;
044:
045:        import java.lang.reflect.Field;
046:        import java.net.URI;
047:        import java.util.HashMap;
048:        import java.util.Map;
049:
050:        import org.deegree.framework.log.ILogger;
051:        import org.deegree.framework.log.LoggerFactory;
052:        import org.deegree.framework.util.BootLogger;
053:        import org.deegree.ogcbase.CommonNamespaces;
054:
055:        /**
056:         * General data type constants definition. the type values are the same as in
057:         * <code>java.sql.Types<code>. Except for several geometry types, 
058:         * <code>UNKNOWN</code>, <code>FEATURE</code>, <code>FEATURES</code> and 
059:         * <code>FEATURECOLLECTION</code> that are not known by 
060:         * <code>java.sql.Types</code>.
061:         * <p>
062:         * NOTE: Generally, it would be feasible to extend <code>java.sql.Types</code>,
063:         * but unfortunately, this is not possible, as it's default constructor is not visible. 
064:         * </p> 
065:         * 
066:         * @author <a href="mailto:poth@lat-lon.de">Andreas Poth </a>
067:         * @author last edited by: $Author: apoth $
068:         * 
069:         * @version $Revision: 9337 $, $Date: 2007-12-27 04:31:11 -0800 (Thu, 27 Dec 2007) $
070:         * 
071:         * @see java.sql.Types
072:         */
073:        public final class Types {
074:
075:            private static ILogger LOG = LoggerFactory.getLogger(Types.class);
076:
077:            private static URI GMLNS = CommonNamespaces.GMLNS;
078:
079:            // generic sql types
080:
081:            public final static int ARRAY = java.sql.Types.ARRAY;
082:
083:            public final static int BIGINT = java.sql.Types.BIGINT;
084:
085:            public final static int BINARY = java.sql.Types.BINARY;
086:
087:            public final static int BIT = java.sql.Types.BIT;
088:
089:            public final static int BLOB = java.sql.Types.BLOB;
090:
091:            public final static int BOOLEAN = java.sql.Types.BOOLEAN;
092:
093:            public final static int CHAR = java.sql.Types.CHAR;
094:
095:            public final static int CLOB = java.sql.Types.CLOB;
096:
097:            public final static int DATALINK = java.sql.Types.DATALINK;
098:
099:            public final static int DATE = java.sql.Types.DATE;
100:
101:            public final static int DECIMAL = java.sql.Types.DECIMAL;
102:
103:            public final static int DISTINCT = java.sql.Types.DISTINCT;
104:
105:            public final static int DOUBLE = java.sql.Types.DOUBLE;
106:
107:            public final static int FLOAT = java.sql.Types.FLOAT;
108:
109:            public final static int INTEGER = java.sql.Types.INTEGER;
110:
111:            public final static int JAVA_OBJECT = java.sql.Types.JAVA_OBJECT;
112:
113:            public final static int LONGVARBINARY = java.sql.Types.LONGVARBINARY;
114:
115:            public final static int LONGVARCHAR = java.sql.Types.LONGVARCHAR;
116:
117:            public final static int NULL = java.sql.Types.NULL;
118:
119:            public final static int NUMERIC = java.sql.Types.NUMERIC;
120:
121:            public final static int OTHER = java.sql.Types.OTHER;
122:
123:            public final static int REAL = java.sql.Types.REAL;
124:
125:            public final static int REF = java.sql.Types.REF;
126:
127:            public final static int SMALLINT = java.sql.Types.SMALLINT;
128:
129:            public final static int STRUCT = java.sql.Types.STRUCT;
130:
131:            public final static int TIME = java.sql.Types.TIME;
132:
133:            public final static int TIMESTAMP = java.sql.Types.TIMESTAMP;
134:
135:            public final static int TINYINT = java.sql.Types.TINYINT;
136:
137:            public final static int VARBINARY = java.sql.Types.VARBINARY;
138:
139:            public final static int VARCHAR = java.sql.Types.VARCHAR;
140:
141:            // geometry + gml types
142:
143:            public static final int GEOMETRY = java.sql.Types.VARCHAR + 10000;
144:
145:            public static final int MULTIGEOMETRY = java.sql.Types.VARCHAR + 10001;
146:
147:            public static final int FEATURE = java.sql.Types.VARCHAR + 10002;
148:
149:            public static final int FEATURECOLLECTION = java.sql.Types.VARCHAR + 10004;
150:
151:            public static final int POINT = java.sql.Types.VARCHAR + 11000;
152:
153:            public static final int CURVE = java.sql.Types.VARCHAR + 11001;
154:
155:            public static final int SURFACE = java.sql.Types.VARCHAR + 11002;
156:
157:            public static final int MULTIPOINT = java.sql.Types.VARCHAR + 11003;
158:
159:            public static final int MULTICURVE = java.sql.Types.VARCHAR + 11004;
160:
161:            public static final int MULTISURFACE = java.sql.Types.VARCHAR + 11005;
162:
163:            public static final int ENVELOPE = java.sql.Types.VARCHAR + 11006;
164:
165:            public static final int ANYTYPE = java.sql.Types.VARCHAR + 11007;
166:
167:            public static final QualifiedName GEOMETRY_PROPERTY_NAME = new QualifiedName(
168:                    "GeometryPropertyType", GMLNS);
169:
170:            public static final QualifiedName MULTI_GEOMETRY_PROPERTY_NAME = new QualifiedName(
171:                    "MultiGeometryPropertyType", GMLNS);
172:
173:            public static final QualifiedName FEATURE_PROPERTY_NAME = new QualifiedName(
174:                    "FeaturePropertyType", GMLNS);
175:
176:            // TODO check if this is really needed
177:            public static final QualifiedName FEATURE_ARRAY_PROPERTY_NAME = new QualifiedName(
178:                    "FeatureArrayPropertyType", GMLNS);
179:
180:            // key instances: Integer, value instances: String
181:            private static Map<Integer, String> typeNameMap = new HashMap<Integer, String>();
182:
183:            // key instances: String, value instances: Integer
184:            private static Map<String, Integer> typeCodeMap = new HashMap<String, Integer>();
185:
186:            static {
187:                try {
188:                    Field[] fields = java.sql.Types.class.getFields();
189:                    for (int i = 0; i < fields.length; i++) {
190:                        String typeName = fields[i].getName();
191:                        Integer typeCode = (Integer) fields[i].get(null);
192:                        typeNameMap.put(typeCode, typeName);
193:                        typeCodeMap.put(typeName, typeCode);
194:                    }
195:                } catch (Exception e) {
196:                    BootLogger.logError("Error populating sql type code maps: "
197:                            + e.getMessage(), e);
198:                }
199:            }
200:
201:            /**
202:             * Returns the generic sql type code for the given type name.
203:             * 
204:             * @param typeName
205:             * @return the generic sql type code for the given type name.
206:             * @throws UnknownTypeException
207:             *             if the type name is not an sql type name
208:             * @see java.sql.Types
209:             */
210:            public static int getTypeCodeForSQLType(String typeName)
211:                    throws UnknownTypeException {
212:                Integer typeCode = typeCodeMap.get(typeName);
213:                if (typeCode == null) {
214:                    throw new UnknownTypeException("Type name '" + typeName
215:                            + "' does not denote an sql type.");
216:                }
217:                return typeCode.intValue();
218:            }
219:
220:            /**
221:             * Returns the generic sql type name for the given type code.
222:             * 
223:             * @param typeCode
224:             * @return the generic sql type name for the given type code.
225:             * @throws UnknownTypeException
226:             *             if the type code is not an sql type code
227:             * @see java.sql.Types
228:             */
229:            public static String getTypeNameForSQLTypeCode(int typeCode)
230:                    throws UnknownTypeException {
231:                String typeName = typeNameMap.get(new Integer(typeCode));
232:                if (typeName == null) {
233:                    throw new UnknownTypeException("Type code '" + typeCode
234:                            + "' does not denote an sql type.");
235:                }
236:                return typeName;
237:            }
238:
239:            /**
240:             * mapping between GML-typenames and java-classnames for GML-geometry types
241:             * 
242:             * @param gmlTypeName
243:             *            the name of the GML type name
244:             * @return the internal type
245:             * @throws UnknownTypeException
246:             *             if the given name cannot be mapped to a known type.
247:             */
248:            public static int getJavaTypeForGMLType(String gmlTypeName)
249:                    throws UnknownTypeException {
250:                if ("GeometryPropertyType".equals(gmlTypeName))
251:                    return Types.GEOMETRY;
252:
253:                if ("PointPropertyType".equals(gmlTypeName))
254:                    // return Types.POINT;
255:                    return Types.GEOMETRY;
256:
257:                if ("MultiPointPropertyType".equals(gmlTypeName))
258:                    // return Types.MULTIPOINT;
259:                    return Types.GEOMETRY;
260:
261:                if ("PolygonPropertyType".equals(gmlTypeName))
262:                    // return Types.SURFACE;
263:                    return Types.GEOMETRY;
264:
265:                if ("MultiPolygonPropertyType".equals(gmlTypeName))
266:                    // return Types.MULTISURFACE;
267:                    return Types.GEOMETRY;
268:
269:                if ("LineStringPropertyType".equals(gmlTypeName))
270:                    // return Types.CURVE;
271:                    return Types.GEOMETRY;
272:
273:                if ("MultiLineStringPropertyType".equals(gmlTypeName))
274:                    // return Types.MULTICURVE;
275:                    return Types.GEOMETRY;
276:
277:                if ("CurvePropertyType".equals(gmlTypeName))
278:                    // return Types.POINT;
279:                    return Types.GEOMETRY;
280:
281:                if ("MultiCurvePropertyType".equals(gmlTypeName))
282:                    // return Types.POINT;
283:                    return Types.GEOMETRY;
284:
285:                if ("SurfacePropertyType".equals(gmlTypeName))
286:                    // return Types.POINT;
287:                    return Types.GEOMETRY;
288:
289:                if ("MultiSurfacePropertyType".equals(gmlTypeName))
290:                    // return Types.POINT;
291:                    return Types.GEOMETRY;
292:
293:                throw new UnknownTypeException("Unsupported Type: '"
294:                        + gmlTypeName + "'");
295:            }
296:
297:            /**
298:             * mapping between xml-typenames and java-classnames for XMLSCHEMA-simple types
299:             * 
300:             * @param schemaTypeName
301:             *            of the XML schema type
302:             * @return the internal type
303:             * @throws UnknownTypeException
304:             *             if the given name cannot be mapped to a known type.
305:             * @todo TODO map them all over registry
306:             */
307:            public static int getJavaTypeForXSDType(String schemaTypeName)
308:                    throws UnknownTypeException {
309:
310:                if ("integer".equals(schemaTypeName)
311:                        || "int".equals(schemaTypeName)
312:                        || "long".equals(schemaTypeName))
313:                    return Types.INTEGER;
314:
315:                if ("string".equals(schemaTypeName))
316:                    return Types.VARCHAR;
317:
318:                if ("date".equals(schemaTypeName))
319:                    return Types.DATE;
320:
321:                if ("boolean".equals(schemaTypeName))
322:                    return Types.BOOLEAN;
323:
324:                if ("float".equals(schemaTypeName))
325:                    return Types.FLOAT;
326:
327:                if ("double".equals(schemaTypeName))
328:                    return Types.DOUBLE;
329:
330:                if ("decimal".equals(schemaTypeName))
331:                    return Types.DECIMAL;
332:
333:                if ("dateTime".equals(schemaTypeName))
334:                    return Types.TIMESTAMP;
335:
336:                if ("time".equals(schemaTypeName))
337:                    return Types.TIME;
338:
339:                if ("date".equals(schemaTypeName))
340:                    return Types.DATE;
341:
342:                if ("anyURI".equals(schemaTypeName))
343:                    return Types.VARCHAR;
344:
345:                if ("anyType".equals(schemaTypeName))
346:                    return Types.ANYTYPE;
347:
348:                throw new UnknownTypeException("Unsupported Type:"
349:                        + schemaTypeName);
350:            }
351:
352:            /**
353:             * 
354:             * @param type
355:             *            SQL datatype code
356:             * @param precision
357:             *            precision (just used for type NUMERIC)
358:             * @return typename
359:             */
360:            public static String getXSDTypeForSQLType(int type, int precision) {
361:                String s = null;
362:
363:                switch (type) {
364:                case Types.VARCHAR:
365:                case Types.CHAR:
366:                    s = "string";
367:                    break;
368:                case Types.NUMERIC: {
369:                    if (precision <= 1) {
370:                        s = "integer";
371:                        break;
372:                    }
373:                    s = "double";
374:                    break;
375:                }
376:                case Types.DECIMAL:
377:                    s = "decimal";
378:                    break;
379:                case Types.DOUBLE:
380:                case Types.REAL:
381:                    s = "double";
382:                    break;
383:                case Types.FLOAT:
384:                    s = "float";
385:                    break;
386:                case Types.INTEGER:
387:                case Types.SMALLINT:
388:                case Types.BIGINT:
389:                    s = "integer";
390:                    break;
391:                case Types.TIMESTAMP:
392:                case Types.TIME:
393:                case Types.DATE:
394:                    s = "dateTime";
395:                    break;
396:                case Types.CLOB:
397:                    s = "string";
398:                    break;
399:                case Types.BIT:
400:                case Types.BOOLEAN:
401:                    s = "boolean";
402:                    break;
403:                case Types.GEOMETRY:
404:                case Types.OTHER:
405:                case Types.STRUCT:
406:                    s = "gml:GeometryPropertyType";
407:                    break;
408:                case Types.FEATURE:
409:                    s = "gml:FeaturePropertyType";
410:                    break;
411:                default:
412:                    LOG
413:                            .logWarning("could not determine XSDType for SQLType; using 'XXX': "
414:                                    + type);
415:                    s = "code: " + type;
416:                }
417:                return s;
418:            }
419:
420:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.