svn-gvsig-desktop / branches / v2_0_0_prep / libraries / org.gvsig.exportto / org.gvsig.exportto.swing / org.gvsig.exportto.swing.impl / src / main / java / org / gvsig / exportto / swing / impl / DefaultExporttoSwingProviderManager.java @ 34981
History | View | Annotate | Download (4.53 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.exportto.swing.impl; |
23 |
|
24 |
import java.util.ArrayList; |
25 |
import java.util.Iterator; |
26 |
import java.util.List; |
27 |
|
28 |
import org.cresques.cts.IProjection; |
29 |
import org.slf4j.Logger; |
30 |
import org.slf4j.LoggerFactory; |
31 |
|
32 |
import org.gvsig.exportto.swing.spi.ExporttoSwingProvider; |
33 |
import org.gvsig.exportto.swing.spi.ExporttoSwingProviderManager; |
34 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
35 |
import org.gvsig.tools.ToolsLocator; |
36 |
import org.gvsig.tools.dynobject.DynObject; |
37 |
import org.gvsig.tools.extensionpoint.ExtensionPoint; |
38 |
import org.gvsig.tools.extensionpoint.ExtensionPoint.Extension; |
39 |
import org.gvsig.tools.extensionpoint.ExtensionPointManager; |
40 |
import org.gvsig.tools.service.Service; |
41 |
import org.gvsig.tools.service.ServiceException; |
42 |
import org.gvsig.tools.service.spi.AbstractProviderManager; |
43 |
import org.gvsig.tools.service.spi.Provider; |
44 |
import org.gvsig.tools.service.spi.ProviderFactory; |
45 |
import org.gvsig.tools.service.spi.ProviderServices; |
46 |
|
47 |
|
48 |
/**
|
49 |
* @author gvSIG Team
|
50 |
* @version $Id$
|
51 |
*
|
52 |
*/
|
53 |
public class DefaultExporttoSwingProviderManager extends AbstractProviderManager implements ExporttoSwingProviderManager { |
54 |
private static final Logger LOG = |
55 |
LoggerFactory.getLogger(DefaultExporttoSwingProviderManager.class); |
56 |
|
57 |
private static final String PROVIDERS_NAME = "Exportto.swing.providers"; |
58 |
private static final String PROVIDERS_DESCRIPTION = "Exportto swing providers"; |
59 |
|
60 |
private static final String PARAMETER_FEATURESTORE = "FeatureStore"; |
61 |
private static final String PARAMETER_PROJECTION = "Projection"; |
62 |
|
63 |
public DefaultExporttoSwingProviderManager() {
|
64 |
super();
|
65 |
} |
66 |
|
67 |
public ProviderServices createProviderServices(Service service) {
|
68 |
return new DefaultExporttoSwingProviderServices(); |
69 |
} |
70 |
|
71 |
@SuppressWarnings({ "rawtypes", "unchecked" }) |
72 |
public List getProviderNames() { |
73 |
ExtensionPointManager extensionPointManager = ToolsLocator.getExtensionPointManager(); |
74 |
ExtensionPoint extensionPoint = extensionPointManager.get(this.getRegistryKey());
|
75 |
List providers = new ArrayList(); |
76 |
if (extensionPoint != null){ |
77 |
Iterator it = extensionPoint.iterator();
|
78 |
while (it.hasNext()){
|
79 |
Extension extension = (Extension)it.next(); |
80 |
try {
|
81 |
ProviderFactory providerFactory = (ProviderFactory)extension.create(); |
82 |
providers.add(providerFactory.getName()); |
83 |
} catch (InstantiationException e) { |
84 |
LOG.error("Not possible to create the exportto provider factory", e);
|
85 |
} catch (IllegalAccessException e) { |
86 |
LOG.error("Not possible to create the exportto provider factory", e);
|
87 |
} |
88 |
} |
89 |
} |
90 |
return providers;
|
91 |
} |
92 |
|
93 |
protected String getRegistryDescription() { |
94 |
return PROVIDERS_DESCRIPTION;
|
95 |
} |
96 |
|
97 |
protected String getRegistryKey() { |
98 |
return PROVIDERS_NAME;
|
99 |
} |
100 |
|
101 |
public ExporttoSwingProvider createExporttoSwingProvider(
|
102 |
String providerName, FeatureStore featureStore, IProjection projection)
|
103 |
throws ServiceException {
|
104 |
DynObject serviceParameters = createServiceParameters(providerName); |
105 |
serviceParameters.setDynValue(PARAMETER_FEATURESTORE, featureStore); |
106 |
serviceParameters.setDynValue(PARAMETER_PROJECTION, projection); |
107 |
Provider provider = createProvider(serviceParameters,
|
108 |
new DefaultExporttoSwingProviderServices());
|
109 |
if (!(provider instanceof ExporttoSwingProvider)) { |
110 |
throw new NotExporttoSwingProviderException(providerName); |
111 |
} |
112 |
return (ExporttoSwingProvider) provider;
|
113 |
} |
114 |
} |
115 |
|