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.console;
028:
029: import java.io.File;
030: import java.util.ArrayList;
031: import java.util.List;
032:
033: import javax.swing.JPanel;
034:
035: import org.apache.ojb.broker.util.configuration.impl.OjbConfiguration;
036:
037: import fr.ign.cogit.geoxygene.datatools.Geodatabase;
038: import fr.ign.cogit.geoxygene.datatools.ojb.GeodatabaseOjbFactory;
039: import fr.ign.cogit.geoxygene.util.loader.MetadataReader;
040: import fr.ign.cogit.geoxygene.util.loader.XMLJavaDicoGenerator;
041: import fr.ign.cogit.geoxygene.util.loader.gui.GUICompileMessage;
042: import fr.ign.cogit.geoxygene.util.loader.gui.GUIConfigOJBXMLJava;
043:
044: /**
045: *
046: * @author Thierry Badard & Arnaud Braun
047: * @version 1.1
048: *
049: */
050:
051: class SqlToJava extends JPanel {
052:
053: // liste des noms de tables geographiques a traiter
054: private static List allTables = new ArrayList();
055: // nom du fichier de mapping
056: private static String mappingFileName = "repository_geo.xml";
057: // classe mere des classes chargees
058: private static String extentClassName = "fr.ign.cogit.geoxygene.feature.FT_Feature";
059: // fichier de mapping classe mere (pour OJB)
060: private static String extentMappingFileName = null;
061: // generation automatique ou pas ?
062: private static boolean flagInterroTable = false;
063: // nom du package
064: private static String packageName = "geoxygene.geodata";
065: // repertoire d'accueil des packages Java
066: private static String geOxygeneData;
067: // repertoire d'accueil des fichiers de mapping
068: private static String geOxygeneMapping;
069:
070: protected static void action(int mapping) {
071:
072: System.out
073: .println("Generation de mapping XML et de classes java ... ");
074:
075: if (mapping == GeOxygeneConsole.CASTOR) {
076: System.out.println("CASTOR : marche pas !");
077: return;
078: }
079:
080: try {
081:
082: // repertoire d'accueil des fichiers de mapping
083: OjbConfiguration config = new OjbConfiguration();
084: File fileMapping = new File(config.getRepositoryFilename());
085:
086: // initialisation
087: Geodatabase data = GeodatabaseOjbFactory.newInstance();
088:
089: // choix des tables a charger
090: MetadataReader theMetadataReader = new MetadataReader(data);
091: allTables = theMetadataReader.getSelectedTables();
092:
093: if (allTables.size() == 0) {
094: System.out.println("Aucune table selectionnee ...");
095: return;
096: }
097:
098: System.out
099: .println("Generation du mapping, des classes java et du dico ...");
100:
101: // determine valeur par defaut de geOxygeneData
102: File tryFileData = new File(fileMapping.getParentFile()
103: .getParentFile().getParentFile(), "data");
104: if (tryFileData.exists()) {
105: geOxygeneData = tryFileData.getPath();
106: } else {
107: tryFileData = new File(fileMapping.getParentFile()
108: .getParentFile().getParentFile()
109: .getParentFile(), "data");
110: if (tryFileData.exists()) {
111: geOxygeneData = tryFileData.getPath();
112: }
113: }
114:
115: // determine valeur par defaut de geOxygeneMapping
116: geOxygeneMapping = fileMapping.getParentFile().getPath();
117:
118: GUIConfigOJBXMLJava configuration = new GUIConfigOJBXMLJava(
119: packageName, geOxygeneData, geOxygeneMapping,
120: extentClassName, mappingFileName,
121: extentMappingFileName);
122: String[] selectedValues = configuration.showDialog();
123:
124: // ceci permet d'utiliser le cancel
125: if (selectedValues[2] == null)
126: return;
127:
128: XMLJavaDicoGenerator generator = new XMLJavaDicoGenerator(
129: null, data, false, allTables, selectedValues[0],
130: selectedValues[1], selectedValues[2],
131: selectedValues[3], selectedValues[4],
132: selectedValues[5]);
133: generator.writeAll();
134:
135: GUICompileMessage message = new GUICompileMessage();
136: message.showDialog();
137:
138: } catch (Exception e) {
139: e.printStackTrace();
140: }
141:
142: }
143:
144: }
|