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:
031: import javax.swing.JPanel;
032:
033: import org.apache.ojb.broker.util.configuration.impl.OjbConfiguration;
034:
035: import fr.ign.cogit.geoxygene.datatools.Geodatabase;
036: import fr.ign.cogit.geoxygene.datatools.ojb.GeodatabaseOjbFactory;
037: import fr.ign.cogit.geoxygene.util.loader.SQLXMLGenerator;
038: import fr.ign.cogit.geoxygene.util.loader.gui.GUIConfigSqlOJBXML;
039:
040: /**
041: * permet à partir d'une classe java choisie par l'utilisateur de générer automatiquement
042: * la table correspondante dans le sgbd (postgis ou oracle) et le fichier de mapping
043: * correspondant
044: *
045: * @author Eric Grosso - IGN / Laboratoire COGIT
046: * @version 1.0
047: *
048: */
049:
050: class JavaToSql extends JPanel {
051:
052: // nom du fichier de mapping
053: private static String mappingFileName = "repository_geo.xml";
054: // repertoire de la racine du projet geoxygene
055: private static String geoxygeneDirectory = "";
056: // repertoire d'accueil des fichiers de mapping
057: private static String geOxygeneMapping;
058:
059: protected static void action() {
060:
061: System.out
062: .println("Generation de tables dans le SGBD et du mapping XML correspondant ... ");
063:
064: try {
065:
066: // initialisation
067: Geodatabase data = GeodatabaseOjbFactory.newInstance();
068:
069: // determine valeur par defaut de la racine du projet geoxygene
070: OjbConfiguration config = new OjbConfiguration();
071: File fileMapping = new File(config.getRepositoryFilename());
072:
073: try {
074: File tryFileData = new File(fileMapping.getParentFile()
075: .getParentFile().getParentFile(), "data");
076: if (tryFileData.exists()) {
077: geoxygeneDirectory = tryFileData.getParentFile()
078: .getPath();
079: } else {
080: tryFileData = new File(fileMapping.getParentFile()
081: .getParentFile().getParentFile()
082: .getParentFile(), "data");
083: if (tryFileData.exists()) {
084: geoxygeneDirectory = tryFileData
085: .getParentFile().getPath();
086: }
087: }
088: if (!tryFileData.exists()) {
089: tryFileData = new File(fileMapping.getParentFile()
090: .getParentFile().getParentFile()
091: .getParentFile().getParentFile(), "data");
092: if (tryFileData.exists()) {
093: geoxygeneDirectory = tryFileData
094: .getParentFile().getPath();
095: }
096: }
097: } catch (Exception e) {
098: }
099:
100: // determine valeur par defaut de geoxygeneMapping
101: geOxygeneMapping = fileMapping.getParentFile().getPath();
102:
103: GUIConfigSqlOJBXML configuration = new GUIConfigSqlOJBXML(
104: geoxygeneDirectory, geOxygeneMapping,
105: mappingFileName);
106: String[] selectedValues = configuration.showDialog();
107:
108: String javaFilePath = selectedValues[0];
109: String mappingDirectory = selectedValues[1];
110: String tableName = selectedValues[2];
111: mappingFileName = selectedValues[3];
112:
113: if (javaFilePath == null || mappingDirectory == null
114: || tableName == null || mappingFileName == null)
115: return;
116: SQLXMLGenerator generator = new SQLXMLGenerator(data,
117: javaFilePath, mappingDirectory, tableName,
118: mappingFileName);
119: generator.writeAll();
120:
121: } catch (Exception e) {
122: e.printStackTrace();
123: }
124: }
125: }
|