Revision 229 org.gvsig.projection.jcrs/trunk/org.gvsig.projection.jcrs/org.gvsig.projection.jcrs.lib/src/main/java/org/gvsig/crs/JCRSLibrary.java
JCRSLibrary.java | ||
---|---|---|
34 | 34 |
import org.slf4j.Logger; |
35 | 35 |
import org.slf4j.LoggerFactory; |
36 | 36 |
|
37 |
|
|
38 | 37 |
/** |
39 | 38 |
* @author gvSIG Team |
40 | 39 |
* @version $Id$ |
41 | 40 |
* |
42 | 41 |
*/ |
43 | 42 |
public class JCRSLibrary extends AbstractLibrary { |
44 |
|
|
45 |
private static final Logger logger = LoggerFactory.getLogger(JCRSLibrary.class);
|
|
46 |
|
|
43 |
|
|
44 |
private static final Logger logger = LoggerFactory.getLogger(JCRSLibrary.class);
|
|
45 |
|
|
47 | 46 |
public void doRegistration() { |
48 | 47 |
registerAsImplementationOf(ProjectionLibrary.class, 10); |
49 | 48 |
} |
50 | 49 |
|
51 | 50 |
protected void doInitialize() throws LibraryException { |
52 |
// cleanGeotoolsDatabase(); |
|
53 |
initializeGeotoolsProviders(); |
|
54 |
CRSFactory.registerCRSFactory(new CrsFactory()); |
|
51 |
initializeGeotoolsProviders(); |
|
52 |
CRSFactory.registerCRSFactory(new CrsFactory()); |
|
55 | 53 |
} |
56 | 54 |
|
57 | 55 |
protected void doPostInitialize() throws LibraryException { |
58 | 56 |
// nothing to do |
59 | 57 |
} |
60 | 58 |
|
61 |
//Hemos cambiado el jar de epsg-hsql y tal vez esto ya no sea necesario |
|
62 |
// private void cleanGeotoolsDatabase(){ |
|
63 |
// |
|
64 |
// // Parche para limpiar los archivos temporales de la base de datos cacheada de EPSG cuando ha podido quedar corrupta |
|
65 |
// String tempFolder = System.getProperty("java.io.tmpdir") ; |
|
66 |
// String pathSeparator = System.getProperty("file.separator") ; |
|
67 |
// String cachedDatabasesDir = tempFolder+pathSeparator+"Geotools"+pathSeparator+"Cached databases"; |
|
68 |
// |
|
69 |
// File fileProperties = new File(cachedDatabasesDir+pathSeparator+"EPSG.properties"); |
|
70 |
// File fileScript = new File(cachedDatabasesDir+pathSeparator+"EPSG.script"); |
|
71 |
// File fileData = new File(cachedDatabasesDir+pathSeparator+"EPSG.data"); |
|
72 |
// |
|
73 |
// boolean canDelete = true; |
|
74 |
// if ((fileProperties.exists() || fileScript.exists()) && !fileData.exists()){ |
|
75 |
// File cachedDatabasesDirFile = new File(cachedDatabasesDir); |
|
76 |
// String[] fileNames = cachedDatabasesDirFile.list(); |
|
77 |
// for (int i = 0; i < fileNames.length; i++) { |
|
78 |
// File file = new File(cachedDatabasesDir+pathSeparator+fileNames[i]); |
|
79 |
// canDelete &= file.delete(); |
|
80 |
// } |
|
81 |
// if (!canDelete){ |
|
82 |
// NotificationManager.showMessageWarning("La base de datos de EPSG ha quedado corrupta, por favor salga de la aplicaci?n y borre manualmente el directorio "+cachedDatabasesDir, null); |
|
83 |
// } |
|
84 |
// } |
|
85 |
// // Fin del parche |
|
86 |
// |
|
87 |
// /* Parche para prevenir una posible corrupci?n de la base de datos de EPSG que se |
|
88 |
// * produce en windows al tener m?s de una instancia de gvSIG abierta. |
|
89 |
// */ |
|
90 |
// if (fileProperties.exists()){ |
|
91 |
// if (!fileProperties.delete()){ |
|
92 |
// NotificationManager.showMessageWarning("La base de datos de EPSG ha podido quedar corrupta, por favor salga de la aplicaci?n y borre manualmente el directorio "+cachedDatabasesDir, null); |
|
93 |
// } |
|
94 |
// } |
|
95 |
// // Fin del parche |
|
96 |
// |
|
97 |
// |
|
98 |
// } |
|
99 |
|
|
100 |
private void initializeGeotoolsProviders(){ |
|
101 |
/* |
|
102 |
* Se eliminan del registro de geotools las proyecciones que aporta libJCrs para asegurar que |
|
103 |
* son estas ?ltimas las que se utilizan. |
|
104 |
*/ |
|
105 |
final Class[] categories = {org.geotools.referencing.operation.MathTransformProvider.class}; |
|
106 |
FactoryRegistry registry = new FactoryRegistry(Arrays.asList(categories)); |
|
107 |
Iterator providers = registry.getServiceProviders(MathTransformProvider.class); |
|
108 |
Iterator providers2 = null; |
|
109 |
MathTransformProvider provider = null; |
|
110 |
MathTransformProvider provider2 = null; |
|
59 |
private void initializeGeotoolsProviders() { |
|
60 |
/* |
|
61 |
* Se eliminan del registro de geotools las proyecciones que aporta libJCrs para asegurar que |
|
62 |
* son estas ?ltimas las que se utilizan. |
|
63 |
*/ |
|
64 |
final Class[] categories = {org.geotools.referencing.operation.MathTransformProvider.class}; |
|
65 |
FactoryRegistry registry = new FactoryRegistry(Arrays.asList(categories)); |
|
66 |
Iterator providers = registry.getServiceProviders(MathTransformProvider.class); |
|
67 |
Iterator providers2 = null; |
|
68 |
MathTransformProvider provider = null; |
|
69 |
MathTransformProvider provider2 = null; |
|
111 | 70 |
|
112 |
while (providers.hasNext()){
|
|
113 |
provider = (MathTransformProvider) providers.next();
|
|
114 |
if(provider.nameMatches("IDR")){
|
|
115 |
providers2 = registry.getServiceProviders(MathTransformProvider.class);
|
|
116 |
while (providers2.hasNext()){
|
|
117 |
provider2 = (MathTransformProvider) providers2.next();
|
|
118 |
if(provider2.nameMatches(provider.getName().toString()) && !provider2.nameMatches("IDR")) {
|
|
119 |
registry.deregisterServiceProvider(provider2, categories[0]);
|
|
120 |
}
|
|
121 |
}
|
|
122 |
}
|
|
123 |
}
|
|
71 |
while ( providers.hasNext() ) {
|
|
72 |
provider = (MathTransformProvider) providers.next();
|
|
73 |
if ( provider.nameMatches("IDR") ) {
|
|
74 |
providers2 = registry.getServiceProviders(MathTransformProvider.class);
|
|
75 |
while ( providers2.hasNext() ) {
|
|
76 |
provider2 = (MathTransformProvider) providers2.next();
|
|
77 |
if ( provider2.nameMatches(provider.getName().toString()) && !provider2.nameMatches("IDR") ) {
|
|
78 |
registry.deregisterServiceProvider(provider2, categories[0]);
|
|
79 |
}
|
|
80 |
}
|
|
81 |
}
|
|
82 |
}
|
|
124 | 83 |
|
125 |
logger.debug("Dump of CRS MathTransformProviders");
|
|
126 |
providers = registry.getServiceProviders(MathTransformProvider.class);
|
|
127 |
while (providers.hasNext()) {
|
|
84 |
logger.debug("Dump of CRS MathTransformProviders");
|
|
85 |
providers = registry.getServiceProviders(MathTransformProvider.class);
|
|
86 |
while ( providers.hasNext() ) {
|
|
128 | 87 |
provider = (MathTransformProvider) providers.next(); |
129 | 88 |
logger.debug(provider.toString()); |
130 |
}
|
|
131 |
}
|
|
89 |
}
|
|
90 |
}
|
|
132 | 91 |
|
133 | 92 |
} |
Also available in: Unified diff