gvsig-raster / org.gvsig.raster.tilecache / trunk / org.gvsig.raster.tilecache / org.gvsig.raster.tilecache.io / src / main / java / org / gvsig / raster / tilecache / io / TileDataParametersImpl.java @ 4270
History | View | Annotate | Download (6.17 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 |
|
23 |
package org.gvsig.raster.tilecache.io; |
24 |
|
25 |
import java.net.URI; |
26 |
|
27 |
import org.gvsig.fmap.dal.DataParameters; |
28 |
import org.gvsig.fmap.dal.coverage.store.parameter.RasterDataParameters; |
29 |
import org.gvsig.fmap.dal.coverage.store.parameter.RemoteStoreParameters; |
30 |
import org.gvsig.fmap.dal.coverage.store.parameter.TileDataParameters; |
31 |
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemStoreParameters; |
32 |
import org.gvsig.raster.cache.tile.provider.TileServer; |
33 |
import org.gvsig.raster.impl.store.AbstractRasterDataParameters; |
34 |
import org.gvsig.raster.impl.store.AbstractRasterFileDataParameters; |
35 |
import org.gvsig.tools.ToolsLocator; |
36 |
import org.gvsig.tools.dynobject.DelegatedDynObject; |
37 |
import org.gvsig.tools.dynobject.DynStruct; |
38 |
import org.gvsig.tools.persistence.PersistenceManager; |
39 |
|
40 |
/**
|
41 |
* Parameters for the <code>TileProvider</code>
|
42 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
43 |
*/
|
44 |
public class TileDataParametersImpl extends AbstractRasterFileDataParameters implements TileDataParameters { |
45 |
public static final String FIELD_PARAMETERS = "parameters"; |
46 |
public static final String FIELD_SECONDLEVEL = "secondlevel"; |
47 |
public static final String FIELD_NAME = "name"; |
48 |
private static final String FIELD_DELETECACHE = "deletecache"; |
49 |
|
50 |
private DelegatedDynObject delegatedDynObject = null; |
51 |
private TileServer tileServer = null; |
52 |
|
53 |
public TileDataParametersImpl() {
|
54 |
super();
|
55 |
initialize(); |
56 |
} |
57 |
|
58 |
protected void initialize() { |
59 |
this.delegatedDynObject = (DelegatedDynObject) ToolsLocator
|
60 |
.getDynObjectManager().createDynObject( |
61 |
registerDynClass()); |
62 |
} |
63 |
|
64 |
public static DynStruct registerDynClass() { |
65 |
PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
66 |
DynStruct definition = manager.getDefinition("TileDataParameters_Persistent");
|
67 |
if( definition == null ) { |
68 |
definition = manager.addDefinition( |
69 |
TileDataParametersImpl.class, |
70 |
"TileDataParameters_Persistent",
|
71 |
"TileDataParameters Persistency",
|
72 |
null,
|
73 |
null
|
74 |
); |
75 |
} |
76 |
|
77 |
AbstractRasterDataParameters.registerDynClass(definition); |
78 |
|
79 |
definition.addDynFieldObject(FIELD_PARAMETERS) |
80 |
.setDescription("Provider")
|
81 |
.setClassOfValue(RasterDataParameters.class) |
82 |
.setMandatory(true);
|
83 |
|
84 |
definition.addDynFieldBoolean(FIELD_SECONDLEVEL) |
85 |
.setDescription("SecondLevelProvider")
|
86 |
.setMandatory(false);
|
87 |
|
88 |
definition.addDynFieldString(FIELD_NAME) |
89 |
.setDescription("Name")
|
90 |
.setMandatory(false);
|
91 |
|
92 |
definition.addDynFieldBoolean(FIELD_DELETECACHE) |
93 |
.setDescription("Flag to delete cache the next request")
|
94 |
.setMandatory(false);
|
95 |
return definition;
|
96 |
} |
97 |
|
98 |
/**
|
99 |
* Sets the <code>DataParameters</code>
|
100 |
* @param params
|
101 |
*/
|
102 |
public void setDataParameters(DataParameters params) { |
103 |
this.setDynValue(FIELD_PARAMETERS, params);
|
104 |
} |
105 |
|
106 |
public DataParameters getDataParameters() {
|
107 |
return (DataParameters) this.getDynValue(FIELD_PARAMETERS); |
108 |
} |
109 |
|
110 |
/**
|
111 |
* Sets the <code>TileServer</code>
|
112 |
* @param tileServer
|
113 |
*/
|
114 |
public void setTileServer(TileServer tileServer) { |
115 |
this.tileServer = tileServer;
|
116 |
} |
117 |
|
118 |
/**
|
119 |
* Gets the <code>TileServer</code>
|
120 |
* @return
|
121 |
*/
|
122 |
public TileServer getTileServer() {
|
123 |
return tileServer;
|
124 |
} |
125 |
|
126 |
/**
|
127 |
* Returns true if this provider is for the second level of cach?
|
128 |
* @return
|
129 |
*/
|
130 |
public boolean isSecondLevelCache() { |
131 |
Object obj = this.getDynValue(FIELD_SECONDLEVEL); |
132 |
if(obj != null && obj instanceof Boolean) |
133 |
return ((Boolean)obj).booleanValue(); |
134 |
return false; |
135 |
} |
136 |
|
137 |
/**
|
138 |
* Sets the flag to inform to the provider that is a second level provider
|
139 |
* @param secondLevel
|
140 |
*/
|
141 |
public void setSecondLevelCache(boolean secondLevel) { |
142 |
this.setDynValue(FIELD_SECONDLEVEL, new Boolean(secondLevel)); |
143 |
} |
144 |
|
145 |
/**
|
146 |
* Gets the name
|
147 |
* @return
|
148 |
*/
|
149 |
public String getName() { |
150 |
DataParameters p = getDataParameters(); |
151 |
if(p != null) { |
152 |
if(p instanceof RemoteStoreParameters) |
153 |
return ((RasterDataParameters)p).getURI().getPath();
|
154 |
if(p instanceof FilesystemStoreParameters) |
155 |
return ((FilesystemStoreParameters)p).getFile().getAbsolutePath();
|
156 |
} |
157 |
return null; |
158 |
} |
159 |
|
160 |
@Override
|
161 |
public URI getURI() { |
162 |
if(this.getDynValue(FIELD_URI) == null) { |
163 |
DataParameters p = getDataParameters(); |
164 |
if(p != null) { |
165 |
if(p instanceof FilesystemStoreParameters) { |
166 |
return ((FilesystemStoreParameters)p).getFile().toURI();
|
167 |
} else {
|
168 |
return ((RasterDataParameters)p).getURI();
|
169 |
} |
170 |
} |
171 |
} |
172 |
return (URI) this.getDynValue(FIELD_URI); |
173 |
} |
174 |
|
175 |
|
176 |
//**********************************************
|
177 |
|
178 |
public String getDataStoreName() { |
179 |
return TileProvider.NAME;
|
180 |
} |
181 |
|
182 |
public String getDescription() { |
183 |
return TileProvider.DESCRIPTION;
|
184 |
} |
185 |
|
186 |
public String getExplorerName() { |
187 |
return TileServerExplorer.NAME;
|
188 |
} |
189 |
|
190 |
public boolean isValid() { |
191 |
return (this.getDataParameters() != null); |
192 |
} |
193 |
|
194 |
protected DelegatedDynObject getDelegatedDynObject() {
|
195 |
return delegatedDynObject;
|
196 |
} |
197 |
|
198 |
/**
|
199 |
* Sets the flag to delete the cache
|
200 |
* @param deleteCache
|
201 |
*/
|
202 |
public void deleteCache(boolean deleteCache) { |
203 |
this.setDynValue(FIELD_DELETECACHE, new Boolean(deleteCache)); |
204 |
} |
205 |
|
206 |
/**
|
207 |
* Returns true if the cache is going to be deleted
|
208 |
* @return
|
209 |
*/
|
210 |
public boolean isDeletingCache() { |
211 |
Boolean b = (Boolean)getDynValue(FIELD_DELETECACHE); |
212 |
if(b != null) |
213 |
return ((Boolean)getDynValue(FIELD_DELETECACHE)).booleanValue(); |
214 |
else
|
215 |
return false; |
216 |
} |
217 |
|
218 |
public boolean isSourceTiled() { |
219 |
return true; |
220 |
} |
221 |
} |