Statistics
| Revision:

root / org.gvsig.jcrs / libJCRS / src / org / gvsig / crs / JCRSLibrary.java @ 38

History | View | Annotate | Download (5.26 KB)

1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 */
22
package org.gvsig.crs;
23

    
24
import java.io.File;
25
import java.util.Arrays;
26
import java.util.Iterator;
27

    
28
import org.cresques.ProjectionLibrary;
29

    
30
import org.geotools.factory.FactoryRegistry;
31
import org.geotools.referencing.operation.MathTransformProvider;
32
import org.gvsig.andami.messages.NotificationManager;
33
import org.gvsig.fmap.crs.CRSFactory;
34
import org.gvsig.tools.library.AbstractLibrary;
35
import org.gvsig.tools.library.LibraryException;
36

    
37

    
38
/**
39
 * @author gvSIG Team
40
 * @version $Id$
41
 *
42
 */
43
public class JCRSLibrary extends AbstractLibrary {
44
    
45
    @Override
46
    public void doRegistration() {
47
        registerAsImplementationOf(ProjectionLibrary.class, 10);
48
    }
49

    
50
    @Override
51
    protected void doInitialize() throws LibraryException {
52
//            cleanGeotoolsDatabase();
53
            initializeGeotoolsProviders();
54
        CRSFactory.cp = new CrsFactory();
55
    }
56

    
57
    @Override
58
    protected void doPostInitialize() throws LibraryException {
59
        // nothing to do 
60
    }
61

    
62
    //Hemos cambiado el jar de epsg-hsql y tal vez esto ya no sea necesario
63
//        private void cleanGeotoolsDatabase(){
64
//        
65
//                // Parche para limpiar los archivos temporales de la base de datos cacheada de EPSG cuando ha podido quedar corrupta 
66
//                String tempFolder =  System.getProperty("java.io.tmpdir") ;
67
//        String pathSeparator = System.getProperty("file.separator") ;
68
//        String cachedDatabasesDir = tempFolder+pathSeparator+"Geotools"+pathSeparator+"Cached databases";
69
//        
70
//        File fileProperties = new File(cachedDatabasesDir+pathSeparator+"EPSG.properties");
71
//        File fileScript = new File(cachedDatabasesDir+pathSeparator+"EPSG.script");
72
//        File fileData = new File(cachedDatabasesDir+pathSeparator+"EPSG.data");
73
//        
74
//        boolean canDelete = true;
75
//        if ((fileProperties.exists() || fileScript.exists()) && !fileData.exists()){
76
//                File cachedDatabasesDirFile = new File(cachedDatabasesDir);
77
//                String[] fileNames = cachedDatabasesDirFile.list();
78
//                for (int i = 0; i < fileNames.length; i++) {
79
//                                File file = new File(cachedDatabasesDir+pathSeparator+fileNames[i]);
80
//                                canDelete &= file.delete();
81
//                        }
82
//                if (!canDelete){
83
//                        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);
84
//                }
85
//        }
86
//        // Fin del parche
87
//        
88
//        /* Parche para prevenir una posible corrupci?n de la base de datos de EPSG que se
89
//         * produce en windows al tener m?s de una instancia de gvSIG abierta. 
90
//         */
91
//        if (fileProperties.exists()){
92
//                if (!fileProperties.delete()){
93
//                        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);
94
//                }
95
//        }
96
//        // Fin del parche
97
//            
98
//
99
//        }
100
        
101
        private void initializeGeotoolsProviders(){
102
                /*
103
                 * Se eliminan del registro de geotools las proyecciones que aporta libJCrs para asegurar que
104
                 * son estas ?ltimas las que se utilizan.
105
                 */
106
                final Class[] categories = {org.geotools.referencing.operation.MathTransformProvider.class};
107
                FactoryRegistry registry = new FactoryRegistry(Arrays.asList(categories));
108
                Iterator providers = registry.getServiceProviders(MathTransformProvider.class);
109
                Iterator providers2 = null;
110
                MathTransformProvider provider = null;
111
                MathTransformProvider provider2 = null;
112

    
113
                while (providers.hasNext()){
114
                        provider = (MathTransformProvider) providers.next();
115
                        if(provider.nameMatches("IDR")){
116
                                providers2 = registry.getServiceProviders(MathTransformProvider.class);
117
                                while (providers2.hasNext()){
118
                                        provider2 = (MathTransformProvider) providers2.next();
119
                                        if(provider2.nameMatches(provider.getName().toString()) && !provider2.nameMatches("IDR")) {
120
                                                registry.deregisterServiceProvider(provider2, categories[0]);
121
                                        }
122
                                }
123
                        }
124
                }
125

    
126
                //TODO: Solo para depurar: BORRAR
127
                providers = registry.getServiceProviders(MathTransformProvider.class);
128
                while (providers.hasNext()) {
129
            provider = (MathTransformProvider) providers.next();
130
            System.out.println(provider.toString());
131
                }
132
                /*
133
                 *
134
                 */
135
        }
136

    
137
}