gvsig-gdal / branches / org.gvsig.gdal-2018a / org.gvsig.gdal.prov / org.gvsig.gdal.raster / org.gvsig.gdal.raster.provider / src / main / java / org / gvsig / raster / gdal / provider / RasterGdalStoreProviderFactory.java @ 361
History | View | Annotate | Download (6.33 KB)
1 | 361 | fdiaz | /* gvSIG. Desktop Geographic Information System.
|
---|---|---|---|
2 | *
|
||
3 | * Copyright ? 2007-2016 gvSIG Association
|
||
4 | *
|
||
5 | * This program is free software; you can redistribute it and/or
|
||
6 | * modify it under the terms of the GNU General Public License
|
||
7 | * as published by the Free Software Foundation; either version 2
|
||
8 | * of the License, or (at your option) any later version.
|
||
9 | *
|
||
10 | * This program is distributed in the hope that it will be useful,
|
||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
13 | * GNU General Public License for more details.
|
||
14 | *
|
||
15 | * You should have received a copy of the GNU General Public License
|
||
16 | * along with this program; if not, write to the Free Software
|
||
17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||
18 | * MA 02110-1301, USA.
|
||
19 | *
|
||
20 | * For any additional information, do not hesitate to contact us
|
||
21 | * at info AT gvsig.com, or visit our website www.gvsig.com.
|
||
22 | */
|
||
23 | package org.gvsig.raster.gdal.provider; |
||
24 | |||
25 | import org.gdal.gdal.Driver; |
||
26 | import org.gdal.gdalconst.gdalconstConstants; |
||
27 | |||
28 | import org.gvsig.fmap.dal.DataParameters; |
||
29 | import org.gvsig.fmap.dal.DataStoreProvider; |
||
30 | import org.gvsig.fmap.dal.exception.InitializeException; |
||
31 | import org.gvsig.fmap.dal.exception.OpenException; |
||
32 | import org.gvsig.fmap.dal.raster.spi.AbstractRasterStoreProviderFactory; |
||
33 | import org.gvsig.fmap.dal.raster.spi.RasterStoreProvider; |
||
34 | import org.gvsig.fmap.dal.spi.DataStoreProviderServices; |
||
35 | import org.gvsig.tools.ToolsLocator; |
||
36 | import org.gvsig.tools.dynobject.DynObject; |
||
37 | import org.gvsig.tools.dynobject.DynStruct_v2; |
||
38 | import org.gvsig.tools.persistence.PersistenceManager; |
||
39 | |||
40 | import org.slf4j.Logger; |
||
41 | import org.slf4j.LoggerFactory; |
||
42 | |||
43 | /**
|
||
44 | * Factory for Raster GDAL provider
|
||
45 | * @author dmartinezizquierdo
|
||
46 | *
|
||
47 | */
|
||
48 | public class RasterGdalStoreProviderFactory extends AbstractRasterStoreProviderFactory { |
||
49 | |||
50 | private static final Logger logger = LoggerFactory.getLogger(RasterGdalStoreProviderFactory.class); |
||
51 | private Driver gdalDriver; |
||
52 | private String openingParams; |
||
53 | |||
54 | protected RasterGdalStoreProviderFactory(String name, String description,Driver gdalDriver, String openingParams) { |
||
55 | super(name, description);
|
||
56 | this.gdalDriver=gdalDriver;
|
||
57 | this.openingParams=openingParams;
|
||
58 | } |
||
59 | |||
60 | @Override
|
||
61 | public DataStoreProvider createProvider(DataParameters parameters,
|
||
62 | DataStoreProviderServices providerServices) |
||
63 | throws InitializeException {
|
||
64 | // FIXME: This drivers are not loaded and maybe will be deployed in
|
||
65 | // their own plugin
|
||
66 | /*
|
||
67 | // POSTGIS uses its own driver
|
||
68 | if (gdalDriver.getShortName().equalsIgnoreCase("PostGISRaster")) {
|
||
69 | return new RasterGdalPostgisStoreProvider((RasterGdalStoreParameters) parameters, providerServices);
|
||
70 | }
|
||
71 | // WCS uses its own driver
|
||
72 | if (gdalDriver.getShortName().equalsIgnoreCase("WCS")) {
|
||
73 | return new RasterGdalWCSStoreProvider((RasterGdalStoreParameters) parameters, providerServices);
|
||
74 | }
|
||
75 | // WMS uses its own driver
|
||
76 | if (gdalDriver.getShortName().equalsIgnoreCase("WMS")) {
|
||
77 | return new RasterGdalWMSStoreProvider((RasterGdalStoreParameters) parameters, providerServices);
|
||
78 | }
|
||
79 | */
|
||
80 | |||
81 | String allowCreate = (String) gdalDriver.GetMetadata_Dict().get(gdalconstConstants.GDAL_DCAP_CREATE); |
||
82 | String allowCreateCopy = (String) gdalDriver.GetMetadata_Dict().get(gdalconstConstants.GDAL_DCAP_CREATECOPY); |
||
83 | RasterStoreProvider provider; |
||
84 | if (allowCreate != null && allowCreate.equalsIgnoreCase("YES")) { |
||
85 | provider = new RasterGdalStoreProviderCreate((RasterGdalFileStoreParameters) parameters, providerServices);
|
||
86 | // return provider;
|
||
87 | } else if (allowCreateCopy != null && allowCreateCopy.equalsIgnoreCase("YES")) { |
||
88 | provider = |
||
89 | new RasterGdalStoreProviderCreateCopy((RasterGdalFileStoreParameters) parameters, providerServices);
|
||
90 | } else {
|
||
91 | provider = new DefaultRasterGdalStoreProvider((RasterGdalFileStoreParameters) parameters, providerServices);
|
||
92 | } |
||
93 | try {
|
||
94 | provider.open(); |
||
95 | } catch (OpenException e) {
|
||
96 | throw new InitializeException("Can't open provider: ", e); |
||
97 | } |
||
98 | return provider;
|
||
99 | } |
||
100 | |||
101 | /**
|
||
102 | * Creates provider to create a new store
|
||
103 | * @param parameters
|
||
104 | * @return DataStoreProvider
|
||
105 | * @throws InitializeException
|
||
106 | */
|
||
107 | public DataStoreProvider createProvider(DataParameters parameters) throws InitializeException { |
||
108 | //TODO: If a specific provider must be used, it must be defined here.
|
||
109 | // if (parameters.getDynClass().getName().equals("NewRasterGdalStoreParameters_GTiff") ){
|
||
110 | //
|
||
111 | // return new RasterGdalGTiffStoreProvider((NewRasterGdalStoreParameters)parameters,this.gdalDriver);
|
||
112 | //
|
||
113 | // }
|
||
114 | String allowCreate=(String)gdalDriver.GetMetadata_Dict().get(gdalconstConstants.GDAL_DCAP_CREATE); |
||
115 | String allowCreateCopy=(String)gdalDriver.GetMetadata_Dict().get(gdalconstConstants.GDAL_DCAP_CREATECOPY); |
||
116 | if ( allowCreate!=null && allowCreate.equalsIgnoreCase("YES") ){ |
||
117 | return new RasterGdalStoreProviderCreate((NewRasterGdalStoreParameters)parameters, this.gdalDriver); |
||
118 | } |
||
119 | if ( allowCreateCopy!=null && allowCreateCopy.equalsIgnoreCase("YES") ){ |
||
120 | return new RasterGdalStoreProviderCreateCopy((NewRasterGdalStoreParameters)parameters, this.gdalDriver); |
||
121 | } |
||
122 | return new DefaultRasterGdalStoreProvider((NewRasterGdalStoreParameters)parameters, this.gdalDriver); |
||
123 | } |
||
124 | |||
125 | @Override
|
||
126 | public DynObject createParameters() {
|
||
127 | PersistenceManager persistenceManager = ToolsLocator.getPersistenceManager(); |
||
128 | DynStruct_v2 openingStruct = (DynStruct_v2)persistenceManager.getDefinition(this.openingParams);
|
||
129 | DynStruct_v2 rasterGdalFileStoreParametersStruct = (DynStruct_v2)persistenceManager.getDefinition(RasterGdalFileStoreParameters.PARAMETERS_DEFINITION_NAME); |
||
130 | |||
131 | if ( openingStruct.isInstance(rasterGdalFileStoreParametersStruct.newInstance()) ){
|
||
132 | return new RasterGdalFileStoreParameters(this.openingParams, getName()); |
||
133 | }else{
|
||
134 | return new RasterGdalStoreParameters(this.openingParams, getName()); |
||
135 | } |
||
136 | } |
||
137 | |||
138 | /**
|
||
139 | * Returns the gdal driver from the provider store factory
|
||
140 | * @return gdalDriver
|
||
141 | */
|
||
142 | public Driver getDriver(){ |
||
143 | return gdalDriver;
|
||
144 | } |
||
145 | } |