Source Code Cross Referenced for OjbXMLGenerator.java in  » GIS » GeOxygene-1.3 » fr » ign » cogit » geoxygene » util » loader » 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 » GeOxygene 1.3 » fr.ign.cogit.geoxygene.util.loader 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * This file is part of the GeOxygene project source files. 
003:         * 
004:         * GeOxygene aims at providing an open framework which implements OGC/ISO specifications for 
005:         * the development and deployment of geographic (GIS) applications. It is a open source 
006:         * contribution of the COGIT laboratory at the Institut Géographique National (the French 
007:         * National Mapping Agency).
008:         * 
009:         * See: http://oxygene-project.sourceforge.net 
010:         *  
011:         * Copyright (C) 2005 Institut Géographique National
012:         *
013:         * This library is free software; you can redistribute it and/or modify it under the terms
014:         * of the GNU Lesser General Public License as published by the Free Software Foundation; 
015:         * either version 2.1 of the License, or any later version.
016:         *
017:         * This library is distributed in the hope that it will be useful, but WITHOUT ANY 
018:         * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 
019:         * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
020:         *
021:         * You should have received a copy of the GNU Lesser General Public License along with 
022:         * this library (see file LICENSE if present); if not, write to the Free Software 
023:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
024:         *  
025:         */
026:
027:        package fr.ign.cogit.geoxygene.util.loader;
028:
029:        import java.io.File;
030:        import java.io.FileWriter;
031:
032:        import fr.ign.cogit.geoxygene.datatools.Geodatabase;
033:
034:        /**
035:         * Usage interne. 
036:         * Generateur de fichier XML pour OJB.
037:         *
038:         *
039:         * @author Thierry Badard & Arnaud Braun
040:         * @version 1.1
041:         * 
042:         */
043:
044:        class OjbXMLGenerator {
045:
046:            private FileWriter fw;
047:            private String mappingFilePath; //GEOXYGENE_MAPPING/repository_geo.xml
048:            private String extentMappingFilePath = null; //GEOXYGENE_MAPPING/repository_feature.xml
049:            private String plateformePath;
050:            private int i = 1; // identifiant du field dans le fichier de mapping
051:            private String extentClassName;
052:
053:            private String mappingString = ""; // chaine de caractere qu'on va ecrire dans le fichier de mapping
054:            private String classeMereString = "";// chaine de caractere qu'on va ecrire dans le fichier de mapping de la classe mere
055:
056:            private Geodatabase data;
057:
058:            private String keyColumnName;
059:            private final static String KEY_COLUMN_NAME_ORACLE = "COGITID";
060:            private final static String KEY_COLUMN_NAME_POSTGIS = "COGITID";
061:
062:            OjbXMLGenerator(Geodatabase Data, String path,
063:                    String mappingFileName, String ExtentClassName,
064:                    String extentMappingFileName) {
065:                try {
066:                    data = Data;
067:                    plateformePath = path;
068:                    File thePath = new File(path);
069:                    File mappingFile = new File(thePath, mappingFileName);
070:                    mappingFilePath = mappingFile.getPath();
071:                    extentClassName = ExtentClassName;
072:                    if (extentMappingFileName != null) {
073:                        File extentMappingFile = new File(thePath,
074:                                extentMappingFileName);
075:                        extentMappingFilePath = extentMappingFile.getPath();
076:                    }
077:                    if (data.getDBMS() == Geodatabase.ORACLE)
078:                        keyColumnName = KEY_COLUMN_NAME_ORACLE;
079:                    else if (data.getDBMS() == Geodatabase.POSTGIS)
080:                        keyColumnName = KEY_COLUMN_NAME_POSTGIS;
081:                } catch (Exception e) {
082:                    e.printStackTrace();
083:                }
084:            }
085:
086:            void writeFileHeader() {
087:                // fichier de mapping des classes filles
088:                String line1 = "<!-- fichier de mapping OJB pour GeOxygene : classes geographiques -->\n";
089:                String line2 = "<!-- fichier genere automatiquement par le chargeur de la plate-forme GeOxygene -->\n";
090:                String line3 = "\n";
091:
092:                // fichier de mapping classe mere
093:                if (extentMappingFilePath != null) {
094:                    String line4 = "<class-descriptor class=\""
095:                            + extentClassName + "\"  >\n";
096:                    classeMereString = line1 + line2 + line3 + line4;
097:                }
098:            }
099:
100:            void writeFileBottom() {
101:                // fichier de mapping de la classe mere
102:                if (extentMappingFilePath != null) {
103:                    String line0 = "</class-descriptor>\n";
104:                    String line1 = "\n";
105:                    classeMereString += line0 + line1;
106:                }
107:            }
108:
109:            void writeClassHeader(String className, String tableName) {
110:                // fichier de mapping des classes filles
111:                i = 1; // remise a 1 du compteur
112:                String str1 = "<class-descriptor class=\"" + className
113:                        + "\" table=\"" + tableName + "\" >\n";
114:                String str2 = "  <field-descriptor name=\"id\"  column=\""
115:                        + keyColumnName
116:                        + "\" jdbc-type=\"INTEGER\" primarykey=\"true\" autoincrement=\"true\"/>\n";
117:                mappingString += str1 + str2;
118:
119:                // fichier de mapping de la classe mere
120:                if (extentMappingFilePath != null) {
121:                    str1 = "  <extent-class class-ref=\"" + className
122:                            + "\" />\n";
123:                    classeMereString += str1;
124:                }
125:            }
126:
127:            void writeClassBottom() {
128:                // fichier de mapping des classes filles
129:                String line0 = "</class-descriptor>\n";
130:                String line1 = "\n";
131:                mappingString += line0 + line1;
132:            }
133:
134:            void writeField(String javaName, String sqlName, String sqlType) {
135:                try {
136:                    i++;
137:                    String str1 = "  <field-descriptor name=\"" + javaName
138:                            + "\" column=\"" + sqlName + "\" jdbc-type=\""
139:                            + getJdbcType(sqlType) + "\" />\n";
140:                    mappingString += str1;
141:                } catch (Exception e) {
142:                    System.out.println(e.getMessage());
143:                }
144:            }
145:
146:            void writeInFile() {
147:                try {
148:                    if (extentMappingFilePath != null) {
149:                        if (extentMappingFilePath.equals(mappingFilePath)) {
150:                            fw = new FileWriter(mappingFilePath);
151:                            fw.write(classeMereString + "\n" + mappingString);
152:                            fw.close();
153:                        } else {
154:                            fw = new FileWriter(extentMappingFilePath);
155:                            fw.write(classeMereString);
156:                            fw.close();
157:                            fw = new FileWriter(mappingFilePath);
158:                            fw.write(mappingString);
159:                            fw.close();
160:                        }
161:                    } else {
162:                        fw = new FileWriter(mappingFilePath);
163:                        fw.write(mappingString);
164:                        fw.close();
165:                    }
166:                } catch (Exception e) {
167:                    e.printStackTrace();
168:                }
169:            }
170:
171:            ///////////////////////////////////////////////////////////////////////////////////////////////////////////
172:            ///////////////////////////////////////////////////////////////////////////////////////////////////////////        
173:            private String getJdbcType(String sqlType) {
174:                try {
175:                    if (data.getDBMS() == Geodatabase.ORACLE)
176:                        return oracleType2JdbcType(sqlType);
177:                    else if (data.getDBMS() == Geodatabase.POSTGIS)
178:                        return postgisType2JdbcType(sqlType);
179:                    return null;
180:                } catch (Exception e) {
181:                    e.printStackTrace();
182:                    return null;
183:                }
184:            }
185:
186:            ///////////////////////////////////////////////////////////////////////////////////////////////////////////
187:            ///////////////////////////////////////////////////////////////////////////////////////////////////////////        
188:            private String oracleType2JdbcType(String oracle) throws Exception {
189:                if (oracle.compareToIgnoreCase("VARCHAR2") == 0)
190:                    return "VARCHAR";
191:                else if (oracle.compareToIgnoreCase("VARCHAR") == 0)
192:                    return "VARCHAR";
193:                else if (oracle.compareToIgnoreCase("CHAR") == 0)
194:                    return "VARCHAR";
195:                else if (oracle.compareToIgnoreCase("NUMBER") == 0)
196:                    return "DOUBLE";
197:                else if (oracle.compareToIgnoreCase("FLOAT") == 0)
198:                    return "DOUBLE";
199:                else if (oracle.compareToIgnoreCase("INTEGER") == 0)
200:                    return "INTEGER";
201:                else if (oracle.compareToIgnoreCase("BOOLEAN") == 0)
202:                    return "BIT";
203:                else if (oracle.compareToIgnoreCase("SDO_GEOMETRY") == 0)
204:                    return "STRUCT\" conversion=\"fr.ign.cogit.geoxygene.datatools.ojb.GeomGeOxygene2Dbms";
205:                else
206:                    throw new Exception("type non reconnu : " + oracle);
207:            }
208:
209:            ///////////////////////////////////////////////////////////////////////////////////////////////////////////
210:            ///////////////////////////////////////////////////////////////////////////////////////////////////////////        
211:            private String postgisType2JdbcType(String postgis)
212:                    throws Exception {
213:                if (postgis.compareToIgnoreCase("varchar") == 0)
214:                    return "VARCHAR";
215:                else if (postgis.compareToIgnoreCase("bpchar") == 0)
216:                    return "VARCHAR";
217:                else if (postgis.compareToIgnoreCase("float8") == 0)
218:                    return "DOUBLE";
219:                else if (postgis.compareToIgnoreCase("float4") == 0)
220:                    return "FLOAT";
221:                else if (postgis.compareToIgnoreCase("int4") == 0)
222:                    return "INTEGER";
223:                else if (postgis.compareToIgnoreCase("int8") == 0)
224:                    return "BIGINT";
225:                else if (postgis.compareToIgnoreCase("bool") == 0)
226:                    return "BIT";
227:                else if (postgis.compareToIgnoreCase("geometry") == 0)
228:                    return "STRUCT\" conversion=\"fr.ign.cogit.geoxygene.datatools.ojb.GeomGeOxygene2Dbms";
229:                else
230:                    throw new Exception("type non reconnu : " + postgis);
231:            }
232:
233:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.