root / org.gvsig.projection.jcrs / trunk / org.gvsig.projection.jcrs / org.gvsig.projection.app.jcrs / org.gvsig.projection.app.jcrs.common / src / main / java / org / gvsig / crs / installer / EPSGDatabaseInstallerFactory.java @ 249
History | View | Annotate | Download (3.63 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 gvSIG Association.
|
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 3
|
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 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
package org.gvsig.crs.installer; |
25 |
|
26 |
import java.io.File; |
27 |
import java.io.IOException; |
28 |
import org.apache.commons.io.FileUtils; |
29 |
import org.gvsig.andami.PluginServices; |
30 |
import org.gvsig.andami.PluginsLocator; |
31 |
import org.gvsig.andami.PluginsManager; |
32 |
import org.gvsig.crs.CrsFactory; |
33 |
import org.gvsig.crs.JCrsExtension; |
34 |
import org.gvsig.installer.lib.api.InstallerLocator; |
35 |
import org.gvsig.installer.lib.api.InstallerManager; |
36 |
import org.gvsig.installer.lib.spi.InstallerProviderLocator; |
37 |
import org.gvsig.tools.ToolsLocator; |
38 |
import org.gvsig.tools.dynobject.DynClass; |
39 |
import org.gvsig.tools.dynobject.DynObject; |
40 |
import org.gvsig.tools.dynobject.DynObjectManager; |
41 |
import org.gvsig.tools.service.spi.AbstractProviderFactory; |
42 |
import org.gvsig.tools.service.spi.Provider; |
43 |
import org.gvsig.tools.service.spi.ProviderManager; |
44 |
import org.gvsig.tools.service.spi.ProviderServices; |
45 |
import org.slf4j.Logger; |
46 |
import org.slf4j.LoggerFactory; |
47 |
|
48 |
public class EPSGDatabaseInstallerFactory extends |
49 |
AbstractProviderFactory { |
50 |
|
51 |
private static final Logger logger = LoggerFactory.getLogger(EPSGDatabaseInstallerFactory.class); |
52 |
|
53 |
public static final String PROVIDER_NAME = "jCRS_EPSG"; |
54 |
public static final String PROVIDER_DESCRIPTION = "EPSG database installer for jCRS"; |
55 |
|
56 |
private DynClass dynclass;
|
57 |
|
58 |
@Override
|
59 |
protected DynClass createParametersDynClass() {
|
60 |
if ( dynclass == null ) { |
61 |
initialize(); |
62 |
} |
63 |
return dynclass;
|
64 |
} |
65 |
|
66 |
@Override
|
67 |
protected Provider doCreate(DynObject parameters, ProviderServices services) { |
68 |
return new EPSGDatabaseInstaller(services); |
69 |
} |
70 |
|
71 |
public void initialize() { |
72 |
if ( dynclass == null ) { |
73 |
DynObjectManager dynObjectManager = ToolsLocator |
74 |
.getDynObjectManager(); |
75 |
dynclass = dynObjectManager.createDynClass(PROVIDER_NAME, |
76 |
PROVIDER_DESCRIPTION); |
77 |
dynObjectManager.add(dynclass); |
78 |
} |
79 |
} |
80 |
|
81 |
|
82 |
public static void registerEPSGDatabaseInstaller() { |
83 |
|
84 |
InstallerManager installerManager = InstallerLocator.getInstallerManager(); |
85 |
ProviderManager providerManager = InstallerProviderLocator.getProviderManager(); |
86 |
PluginsManager pluginsManager = PluginsLocator.getManager(); |
87 |
|
88 |
providerManager.addProviderFactory(new EPSGDatabaseInstallerFactory());
|
89 |
|
90 |
File epsgDatabaseFolder = new File(CrsFactory.getDataBaseFolder(),"EPSG"); |
91 |
|
92 |
try {
|
93 |
FileUtils.forceMkdir(epsgDatabaseFolder); |
94 |
} catch (IOException ex) { |
95 |
logger.warn("Can't create EPSG databases folder in '"+epsgDatabaseFolder.getAbsolutePath()+"'.",ex); |
96 |
} |
97 |
installerManager.addLocalAddonRepository(epsgDatabaseFolder, PROVIDER_NAME); |
98 |
} |
99 |
} |