root / org.gvsig.projection.jcrs / trunk / org.gvsig.projection.jcrs / org.gvsig.projection.jcrs.lib / src / main / java / org / gvsig / crs / JCRSLibrary.java @ 229
History | View | Annotate | Download (3.48 KB)
1 | 147 | jjdelcerro | /* 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 | import org.geotools.factory.FactoryRegistry; |
||
30 | import org.geotools.referencing.operation.MathTransformProvider; |
||
31 | import org.gvsig.fmap.crs.CRSFactory; |
||
32 | import org.gvsig.tools.library.AbstractLibrary; |
||
33 | import org.gvsig.tools.library.LibraryException; |
||
34 | import org.slf4j.Logger; |
||
35 | import org.slf4j.LoggerFactory; |
||
36 | |||
37 | /**
|
||
38 | * @author gvSIG Team
|
||
39 | * @version $Id$
|
||
40 | *
|
||
41 | */
|
||
42 | public class JCRSLibrary extends AbstractLibrary { |
||
43 | 229 | jjdelcerro | |
44 | private static final Logger logger = LoggerFactory.getLogger(JCRSLibrary.class); |
||
45 | |||
46 | 147 | jjdelcerro | public void doRegistration() { |
47 | registerAsImplementationOf(ProjectionLibrary.class, 10);
|
||
48 | } |
||
49 | |||
50 | protected void doInitialize() throws LibraryException { |
||
51 | 229 | jjdelcerro | initializeGeotoolsProviders(); |
52 | CRSFactory.registerCRSFactory(new CrsFactory());
|
||
53 | 147 | jjdelcerro | } |
54 | |||
55 | protected void doPostInitialize() throws LibraryException { |
||
56 | // nothing to do
|
||
57 | } |
||
58 | |||
59 | 229 | jjdelcerro | 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;
|
||
70 | 147 | jjdelcerro | |
71 | 229 | jjdelcerro | 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 | } |
||
83 | 147 | jjdelcerro | |
84 | 229 | jjdelcerro | logger.debug("Dump of CRS MathTransformProviders");
|
85 | providers = registry.getServiceProviders(MathTransformProvider.class); |
||
86 | while ( providers.hasNext() ) {
|
||
87 | 147 | jjdelcerro | provider = (MathTransformProvider) providers.next(); |
88 | logger.debug(provider.toString()); |
||
89 | 229 | jjdelcerro | } |
90 | } |
||
91 | 147 | jjdelcerro | |
92 | } |