svn-gvsig-desktop / trunk / extensions / extOracleSpatial / src / es / prodevelop / cit / gvsig / jdbc_spatial / ExportOracleExtension.java @ 14291
History | View | Annotate | Download (6.66 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2006 Prodevelop and Generalitat Valenciana.
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*
|
19 |
* For more information, contact:
|
20 |
*
|
21 |
* Generalitat Valenciana
|
22 |
* Conselleria d'Infraestructures i Transport
|
23 |
* Av. Blasco Ib??ez, 50
|
24 |
* 46010 VALENCIA
|
25 |
* SPAIN
|
26 |
*
|
27 |
* +34 963862235
|
28 |
* gvsig@gva.es
|
29 |
* www.gvsig.gva.es
|
30 |
*
|
31 |
* or
|
32 |
*
|
33 |
* Prodevelop Integraci?n de Tecnolog?as SL
|
34 |
* Conde Salvatierra de ?lava , 34-10
|
35 |
* 46004 Valencia
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 963 510 612
|
39 |
* +34 963 510 968
|
40 |
* gis@prodevelop.es
|
41 |
* http://www.prodevelop.es
|
42 |
*/
|
43 |
package es.prodevelop.cit.gvsig.jdbc_spatial; |
44 |
|
45 |
import java.security.KeyException; |
46 |
|
47 |
import org.apache.log4j.Logger; |
48 |
|
49 |
import com.iver.andami.PluginServices; |
50 |
import com.iver.andami.plugins.Extension; |
51 |
import com.iver.andami.ui.mdiManager.IWindow; |
52 |
import com.iver.cit.gvsig.About; |
53 |
import com.iver.cit.gvsig.fmap.MapContext; |
54 |
import com.iver.cit.gvsig.fmap.MapControl; |
55 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
56 |
import com.iver.cit.gvsig.fmap.layers.FLayerVectorialDB; |
57 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
58 |
import com.iver.cit.gvsig.project.documents.view.gui.View; |
59 |
import com.iver.utiles.extensionPoints.ExtensionPoint; |
60 |
import com.iver.utiles.extensionPoints.ExtensionPoints; |
61 |
import com.iver.utiles.extensionPoints.ExtensionPointsSingleton; |
62 |
|
63 |
|
64 |
/**
|
65 |
* This extension adds the export-to-oracle button.
|
66 |
*
|
67 |
* @author jldominguez
|
68 |
*
|
69 |
*/
|
70 |
public class ExportOracleExtension extends Extension { |
71 |
|
72 |
private static Logger logger = Logger.getLogger(ExportOracleExtension.class.getName()); |
73 |
|
74 |
public static boolean ORACLE_JAR_PRESENT = false; |
75 |
|
76 |
public void initialize() { |
77 |
|
78 |
ORACLE_JAR_PRESENT = isOracleJarPresent(); |
79 |
|
80 |
if (!ORACLE_JAR_PRESENT) {
|
81 |
logger.info("*-----------------------------------------------------------------------*");
|
82 |
logger.info("* Oracle library not found! *");
|
83 |
logger.info("* You need to place the Oracle JDBC library in gvSIG's main LIB folder. *");
|
84 |
logger.info("* Read the Oracle driver user manual for details. *");
|
85 |
logger.info("*-----------------------------------------------------------------------*");
|
86 |
} else {
|
87 |
logger.info("*-----------------------------------------------------------------------*");
|
88 |
logger.info("* Found the Oracle JDBC library! :) *");
|
89 |
logger.info("*-----------------------------------------------------------------------*");
|
90 |
} |
91 |
|
92 |
// about
|
93 |
java.net.URL newurl = createResourceUrl("about/jdbc-os-about.html");
|
94 |
About claseAbout = (About) PluginServices.getExtension(com.iver.cit.gvsig.About.class); |
95 |
claseAbout.getAboutPanel().addAboutUrl("JDBC Oracle Spatial", newurl);
|
96 |
ExtensionPoints extensionPoints = ExtensionPointsSingleton.getInstance(); |
97 |
try {
|
98 |
((ExtensionPoint)extensionPoints.get("Layers")).addAlias(FLayerVectorialDB.class.getName(), "VectorialDB"); |
99 |
} catch (KeyException e) { |
100 |
logger.error("While adding alias to extension point: " + e.getMessage());
|
101 |
} |
102 |
|
103 |
OraEpsgTableLoader loader = new OraEpsgTableLoader();
|
104 |
if (!loader.createOracleEpsgTable()) {
|
105 |
logger.error("Unable to create ORA_EPSG datasource!");
|
106 |
} |
107 |
} |
108 |
|
109 |
private boolean isOracleJarPresent() { |
110 |
|
111 |
try {
|
112 |
Class rowid_class = Class.forName("oracle.sql.ROWID"); |
113 |
} catch (Exception ex) { |
114 |
logger.error("Unbale to instantiate ROWID (oracle jar missing?) : " + ex.getMessage());
|
115 |
return false; |
116 |
} |
117 |
return true; |
118 |
} |
119 |
|
120 |
public void execute(String actionCommand) { |
121 |
if (actionCommand.compareToIgnoreCase("EXPORT_TO_ORACLE_SPATIAL") == 0) { |
122 |
FLyrVect lyrv = null;
|
123 |
MapContext mx = null;
|
124 |
|
125 |
try {
|
126 |
IWindow w = PluginServices.getMDIManager().getActiveWindow(); |
127 |
|
128 |
if (w instanceof View) { |
129 |
View v = (View) w; |
130 |
MapControl mc = v.getMapControl(); |
131 |
mx = mc.getMapContext(); |
132 |
|
133 |
FLayer[] lyrs = mx.getLayers().getActives();
|
134 |
|
135 |
if (lyrs.length == 1) { |
136 |
FLayer lyr = lyrs[0];
|
137 |
|
138 |
if (lyr instanceof FLyrVect) { |
139 |
lyrv = (FLyrVect) lyr; |
140 |
|
141 |
ExportToOracle export = new ExportToOracle(); |
142 |
export.toOracle(mx, lyrv);
|
143 |
} |
144 |
} |
145 |
} |
146 |
} |
147 |
catch (Exception ex) { |
148 |
logger.error( |
149 |
"Unexpected error while getting active vect layer: " +
|
150 |
ex.getMessage()); |
151 |
logger.error("Nothing done.");
|
152 |
} |
153 |
} |
154 |
} |
155 |
|
156 |
public boolean isEnabled() { |
157 |
return isVisible();
|
158 |
} |
159 |
|
160 |
/**
|
161 |
* Is visible when there is one vector layer selected
|
162 |
*/
|
163 |
public boolean isVisible() { |
164 |
|
165 |
if (!ORACLE_JAR_PRESENT) {
|
166 |
return false; |
167 |
} |
168 |
// if (true) return true;
|
169 |
|
170 |
try {
|
171 |
IWindow w = PluginServices.getMDIManager().getActiveWindow(); |
172 |
|
173 |
if (w instanceof View) { |
174 |
View v = (View) w; |
175 |
MapControl mc = v.getMapControl(); |
176 |
MapContext mx = mc.getMapContext(); |
177 |
FLayer[] lyrs = mx.getLayers().getActives();
|
178 |
|
179 |
if (lyrs.length == 1) { |
180 |
FLayer lyr = lyrs[0];
|
181 |
|
182 |
if ((lyr instanceof FLyrVect) && (true)) { |
183 |
return true; |
184 |
} |
185 |
} |
186 |
} |
187 |
} catch (Exception ex) { |
188 |
return false; |
189 |
} |
190 |
|
191 |
return false; |
192 |
} |
193 |
|
194 |
private java.net.URL createResourceUrl(String path) { |
195 |
return getClass().getClassLoader().getResource(path);
|
196 |
} |
197 |
} |