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.GenerateIds;
040: import fr.ign.cogit.geoxygene.util.loader.MetadataReader;
041: import fr.ign.cogit.geoxygene.util.loader.TypeGeom;
042: import fr.ign.cogit.geoxygene.util.loader.gui.GUIManageData;
043:
044: /**
045: *
046: * @author Thierry Badard & Arnaud Braun
047: * @version 1.1
048: *
049: */
050:
051: class ManageData extends JPanel {
052:
053: // liste des noms de tables geographiques a traiter
054: private static List allTables = new ArrayList();
055:
056: private static boolean genereIds = false;
057: private static boolean genereSimple = false;
058: private static boolean genereUnique = false;
059: private static boolean homogeneise = false;
060: private static boolean spatialIndex = false;
061: private static boolean emprise = false;
062:
063: protected static void action() {
064:
065: // initialisation
066: Geodatabase data = GeodatabaseOjbFactory.newInstance();
067:
068: // on recharge les fichiers de mapping (utile si on vient de generer le mapping)
069: OjbConfiguration config = new OjbConfiguration();
070: File fileMapping = new File(config.getRepositoryFilename());
071: try {
072: data.refreshRepository(fileMapping);
073: } catch (Exception ee) {
074: System.out
075: .println("## ATTENTION les fichiers de mapping sont incorrects");
076: ee.printStackTrace();
077: }
078:
079: // choix des tables a charger
080: MetadataReader theMetadataReader = new MetadataReader(data);
081: allTables = theMetadataReader.getSelectedTables();
082:
083: if (allTables.size() == 0) {
084: System.out.println("Aucune table selectionnee ...");
085: return;
086: }
087:
088: // on demande a l'utilisateur ce qu'il veut faire
089: GUIManageData configuration = new GUIManageData();
090: boolean[] selectedActions = configuration.showDialog();
091:
092: // le passage des parametres de l'IHM se fait par passage d'un tableau de boolean ...
093: if (selectedActions[0])
094: genereIds = true;
095: else
096: genereIds = false;
097: if (selectedActions[1])
098: homogeneise = true;
099: else
100: homogeneise = false;
101: if (selectedActions[2])
102: spatialIndex = true;
103: else
104: spatialIndex = false;
105: if (selectedActions[3])
106: emprise = true;
107: else
108: emprise = false;
109: if (selectedActions[4])
110: genereSimple = true;
111: else
112: genereSimple = false;
113: if (selectedActions[5])
114: genereUnique = true;
115: else
116: genereUnique = false;
117:
118: if (genereIds) {
119: System.out.println("Generation des COGITID ...");
120: for (int i = 0; i < allTables.size(); i++) {
121: String table = (String) allTables.get(i);
122: GenerateIds generator = new GenerateIds(data, table,
123: genereUnique);
124: generator.genere();
125: }
126: System.out.println("Fin de la generation des COGITID ...");
127: }
128:
129: if (homogeneise) {
130: System.out.println("Homogeneisation des geometries ...");
131: for (int i = 0; i < allTables.size(); i++) {
132: String tableName = (String) allTables.get(i);
133: System.out.println(tableName);
134: Class theClass = data.getMetadata(tableName)
135: .getJavaClass();
136: TypeGeom theTypeGeom = new TypeGeom(data, theClass);
137: theTypeGeom.multi();
138: }
139: System.out
140: .println("Fin de l'homogeneisation des geometries ...");
141: }
142:
143: if (emprise) {
144: System.out
145: .println("Calcul de l'emprise des geometries dans le SGBD");
146: if (data.getDBMS() == Geodatabase.ORACLE) {
147: for (int i = 0; i < allTables.size(); i++) {
148: String tableName = (String) allTables.get(i);
149: System.out.println(tableName);
150: Class theClass = data.getMetadata(tableName)
151: .getJavaClass();
152: data.mbr(theClass);
153: System.out.println("OK");
154: }
155: } else {
156: System.out
157: .println("Le calcul de l'emprise des geometries dans le SGBD ne fonctionne que pour Oracle");
158: }
159: System.out
160: .println("Fin du calcul de l'emprise des geometries dans le SGBD");
161: }
162:
163: if (spatialIndex) {
164: System.out
165: .println("Calcul des index spatiaux dans le SGBD");
166: for (int i = 0; i < allTables.size(); i++) {
167: String tableName = (String) allTables.get(i);
168: System.out.println(tableName);
169: Class theClass = data.getMetadata(tableName)
170: .getJavaClass();
171: data.spatialIndex(theClass);
172: System.out.println("OK");
173: }
174: System.out
175: .println("Fin du calcul des index spatiaux dans le SGBD");
176: }
177:
178: System.out.println("#### FINI !! ####");
179:
180: }
181:
182: }
|