Revision 1667

View differences:

org.gvsig.raster.wmts/tags/2.0.0/distribution/distribution.xml
1
<assembly>
2
</assembly>
0 3

  
org.gvsig.raster.wmts/tags/2.0.0/org.gvsig.raster.wmts.io/src/test/resources/log4j.xml
1
<?xml version="1.0" encoding="ISO-8859-1" ?>
2
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
3

  
4
<!-- 
5
Log4J configuration file for unit tests execution.
6
 -->
7
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
8

  
9
	<!-- Appender configuration to show logging messages through the console -->
10
	<appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
11
		<layout class="org.apache.log4j.PatternLayout">
12
			<param name="ConversionPattern" value="%d{HH:mm:ss,SSS} %-5p [%c{2}.%M()]\n  %m%n" />
13
		</layout>
14
	</appender>
15

  
16
	<!-- 
17
	Activate logging messages of DEBUG level of higher only for the
18
	org.gvsig.tools packages.
19
	You can put full classes names or packages instead, to configure
20
	logging for all the classes and subpackages of the package.
21
	-->
22
	<category name="org.gvsig.tools">
23
		<priority value="DEBUG" />
24
	</category>
25
	<category name="org.gvsig.raster">
26
		<priority value="DEBUG" />
27
	</category>
28

  
29
	<!-- 
30
	By default, show only logging messages of INFO level or higher, 
31
	through the previously configured CONSOLE appender. 
32
	-->
33
	<root>
34
		<priority value="INFO" />
35
		<appender-ref ref="CONSOLE" />
36
	</root>
37
</log4j:configuration>
0 38

  
org.gvsig.raster.wmts/tags/2.0.0/org.gvsig.raster.wmts.io/src/test/resources/TemplateRasterProvider.java
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.fmap.dal.coverage.dataset.io.netcdf;
23

  
24
import java.awt.geom.AffineTransform;
25

  
26
import org.gvsig.fmap.dal.DALFileLocator;
27
import org.gvsig.fmap.dal.DALLocator;
28
import org.gvsig.fmap.dal.DataStore;
29
import org.gvsig.fmap.dal.coverage.dataset.Buffer;
30
import org.gvsig.fmap.dal.coverage.dataset.io.tile.downloader.FileTileServer;
31
import org.gvsig.fmap.dal.coverage.datastruct.BandList;
32
import org.gvsig.fmap.dal.coverage.datastruct.Extent;
33
import org.gvsig.fmap.dal.coverage.exception.BandAccessException;
34
import org.gvsig.fmap.dal.coverage.exception.FileNotOpenException;
35
import org.gvsig.fmap.dal.coverage.exception.InvalidSetViewException;
36
import org.gvsig.fmap.dal.coverage.exception.NotSupportedExtensionException;
37
import org.gvsig.fmap.dal.coverage.exception.ParsingException;
38
import org.gvsig.fmap.dal.coverage.exception.ProcessInterruptedException;
39
import org.gvsig.fmap.dal.coverage.exception.RasterDriverException;
40
import org.gvsig.fmap.dal.coverage.store.RasterFileStoreParameters;
41
import org.gvsig.fmap.dal.spi.DataManagerProviderServices;
42
import org.gvsig.fmap.dal.spi.DataStoreProviderServices;
43
import org.gvsig.metadata.MetadataLocator;
44
import org.gvsig.raster.cache.tile.provider.TileListener;
45
import org.gvsig.raster.cache.tile.provider.TileServer;
46
import org.gvsig.raster.impl.datastruct.ExtentImpl;
47
import org.gvsig.raster.impl.provider.DefaultRasterProvider;
48
import org.gvsig.raster.impl.provider.RasterProvider;
49
import org.gvsig.raster.impl.store.AbstractRasterDataParameters;
50
import org.gvsig.raster.impl.store.AbstractRasterDataStore;
51
import org.gvsig.raster.impl.store.DefaultStoreFactory;
52
import org.gvsig.raster.impl.store.properties.DataStoreColorInterpretation;
53
import org.gvsig.raster.impl.store.properties.DataStoreMetadata;
54
import org.gvsig.raster.impl.store.properties.DataStoreTransparency;
55
import org.gvsig.tools.ToolsLocator;
56
import org.gvsig.tools.extensionpoint.ExtensionPoint;
57
import org.gvsig.tools.extensionpoint.ExtensionPointManager;
58
/**
59
 * Data provider for ...
60
 *
61
 * @author Nacho Brodin (nachobrodin@gmail.com)
62
 */
63
public class NetCDFProvider extends DefaultRasterProvider {
64
	public static String        NAME                     = "Template Store";
65
	public static String        DESCRIPTION              = "Template Raster file";
66
	public final String         METADATA_DEFINITION_NAME = "TemplateStore";
67
	
68
	private static String[]     formatList               = new String[]{"*"};
69

  
70
	private Extent              viewRequest              = null;
71
	private TileServer          tileServer               = null;
72
	private boolean             open                     = false;
73

  
74
	public static void register() {
75
		DataManagerProviderServices dataman = (DataManagerProviderServices) DALLocator.getDataManager();
76
		if (dataman != null && !dataman.getStoreProviders().contains(NAME)) {
77
			dataman.registerStoreProvider(NAME,
78
					NetCDFProvider.class, NetCDFDataParameters.class);
79
		}
80
		
81
		if(DALFileLocator.getFilesystemServerExplorerManager() != null)
82
			DALFileLocator.getFilesystemServerExplorerManager().registerProvider(
83
					NAME, DESCRIPTION,
84
					NetCDFFilesystemServerExplorer.class);
85
		
86
		dataman.registerStoreFactory(NAME, DefaultStoreFactory.class);
87
	}
88

  
89
	/**
90
	 * Returns true if the extension is supported and false if doesn't
91
	 * @param ext
92
	 * @return
93
	 */
94
	public static boolean isExtensionSupported(String ext) {
95
		for (int i = 0; i < formatList.length; i++) {
96
			if(formatList[i].compareTo(ext) == 0)
97
				return true;
98
		}
99
		return false;
100
	}
101
	
102
	/**
103
	 * Constructor. Abre el dataset.
104
	 * @param proj Proyecci?n
105
	 * @param fName Nombre del fichero
106
	 * @throws NotSupportedExtensionException
107
	 */
108
	public NetCDFProvider(String params) throws NotSupportedExtensionException {
109
		super(params);
110
		if(params instanceof String) {
111
			NetCDFDataParameters p = new NetCDFDataParameters();
112
			p.setURI((String)params);
113
			super.init(p, null, ToolsLocator.getDynObjectManager()
114
					.createDynObject(
115
							MetadataLocator.getMetadataManager().getDefinition(
116
									DataStore.METADATA_DEFINITION_NAME)));
117
			init(p, null);
118
		}
119
	}
120
	
121
	public NetCDFProvider (NetCDFDataParameters params,
122
			AbstractRasterDataStore storeServices) throws NotSupportedExtensionException {
123
		super(params, storeServices, ToolsLocator.getDynObjectManager()
124
				.createDynObject(
125
						MetadataLocator.getMetadataManager().getDefinition(
126
								DataStore.METADATA_DEFINITION_NAME)));
127
		init(params, storeServices);
128
	}
129

  
130
	/**
131
	 * Crea las referencias al fichero y carga
132
	 * las estructuras con la informaci?n y los metadatos.
133
	 * @param proj Proyecci?n
134
	 * @param param Parametros de carga
135
	 * @throws NotSupportedExtensionException
136
	 */
137
	public void init (AbstractRasterDataParameters params,
138
			DataStoreProviderServices storeServices) throws NotSupportedExtensionException {
139
		//TODO:
140
		
141
		if(((RasterFileStoreParameters)params).getFile().exists()) {
142
			setParam(params);
143
			colorTable = null;
144
			noData = 0;
145
			wktProjection = null;
146
			//CrsWkt crs = new CrsWkt(wktProjection);
147
			//IProjection proj = CRSFactory.getCRS("EPSG:23030");
148
			noDataEnabled = true;
149
			ownTransformation = null;
150
			externalTransformation = (AffineTransform)ownTransformation.clone();
151
			load();
152
		} else
153
			setParam(params);
154
		bandCount = 0;
155
		setDataType(null);
156
		super.init();
157

  
158
		try {
159
			loadFromRmf(getRmfBlocksManager());
160
		} catch (ParsingException e) {
161
			//No lee desde rmf
162
		}
163
	}
164
	
165
	/*
166
	 * (non-Javadoc)
167
	 * @see org.gvsig.raster.impl.provider.DefaultRasterProvider#load()
168
	 */
169
	public RasterProvider load() {
170
		return this;
171
	}
172
	
173
	/*
174
	 * (non-Javadoc)
175
	 * @see org.gvsig.raster.impl.provider.RasterProvider#isOpen()
176
	 */
177
	public boolean isOpen() {
178
		return open;
179
	}
180

  
181
	/*
182
	 * (non-Javadoc)
183
	 * @see org.gvsig.raster.impl.provider.DefaultRasterProvider#close()
184
	 */
185
	public void close() {
186
		//TODO:
187
	}
188

  
189
	/*
190
	 * (non-Javadoc)
191
	 * @see org.gvsig.raster.impl.provider.DefaultRasterProvider#translateFileName(java.lang.String)
192
	 */
193
	public String translateFileName(String fileName) {
194
		return fileName;
195
	}
196

  
197
	/**
198
	 * Asigna el extent de la vista actual. existe un fichero .rmf debemos hacer una transformaci?n
199
	 * de la vista asignada ya que la petici?n viene en coordenadas del fichero .rmf y la vista (v)
200
	 * ha de estar en coordenadas del fichero.
201
	 */
202
	public void setView(Extent e) {
203
		viewRequest = new ExtentImpl(e);
204
	}
205

  
206
	/*
207
	 * (non-Javadoc)
208
	 * @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getView()
209
	 */
210
	public Extent getView() {
211
		return viewRequest;
212
	}
213

  
214
	/*
215
	 * (non-Javadoc)
216
	 * @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getWidth()
217
	 */
218
	public double getWidth() {
219
		//TODO:
220
		return 0;
221
	}
222

  
223
	/*
224
	 * (non-Javadoc)
225
	 * @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getHeight()
226
	 */
227
	public double getHeight() {
228
		//TODO:
229
		return 0;
230
	}
231

  
232
	/**
233
	 * Read a line from the file
234
	 * @param line
235
	 * @param band
236
	 * @return
237
	 * @throws InvalidSetViewException
238
	 * @throws FileNotOpenException
239
	 * @throws RasterDriverException
240
	 * @Deprecated This operation is deprecated because is not useful and in the future
241
	 * it will not be maintained. The abstract operation has dissapear
242
	 */
243
	public Object readCompleteLine(int line, int band)throws InvalidSetViewException, FileNotOpenException, RasterDriverException {
244
		if(line > this.getHeight() || band > this.getBandCount())
245
			throw new InvalidSetViewException("Request out of grid");
246

  
247
		//TODO:
248
		return null;
249
	}
250

  
251
	/*
252
	 *  (non-Javadoc)
253
	 * @see org.gvsig.raster.dataset.RasterDataset#readBlock(int, int)
254
	 */
255
	public Object readBlock(int pos, int blockHeight)
256
		throws InvalidSetViewException, FileNotOpenException, RasterDriverException, ProcessInterruptedException {
257
		if(pos < 0)
258
			throw new InvalidSetViewException("Request out of grid");
259

  
260
		if((pos + blockHeight) > getHeight())
261
			blockHeight = Math.abs(((int)getHeight()) - pos);
262
		
263
		//TODO:
264
		return null;
265
	}
266

  
267
	/*
268
	 * (non-Javadoc)
269
	 * @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getData(int, int, int)
270
	 */
271
	public Object getData(int x, int y, int band)throws InvalidSetViewException, FileNotOpenException, RasterDriverException {
272
		if(x < 0 || y < 0 || x >= getWidth() || y >= getHeight())
273
			throw new InvalidSetViewException("Request out of grid");
274
		
275
		//TODO
276
		return null;
277
	}
278

  
279
	/*
280
	 * (non-Javadoc)
281
	 * @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getWindowRaster(double, double, double, double, int, int, org.gvsig.fmap.dal.coverage.datastruct.BandList, org.gvsig.raster.cache.tile.provider.TileListener)
282
	 */
283
	public void getWindow(Extent ex, int bufWidth, int bufHeight, 
284
			BandList bandList, TileListener listener) throws ProcessInterruptedException, RasterDriverException {
285
		//TODO
286
	}
287

  
288
	/*
289
	 * (non-Javadoc)
290
	 * @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getWindowRaster(org.gvsig.fmap.dal.coverage.datastruct.Extent, org.gvsig.fmap.dal.coverage.datastruct.BandList, org.gvsig.fmap.dal.coverage.dataset.Buffer)
291
	 */
292
	public Buffer getWindow(Extent ex, BandList bandList, Buffer rasterBuf) 
293
		throws ProcessInterruptedException, RasterDriverException {
294
		//TODO
295

  
296
		return rasterBuf;
297
	}
298

  
299
	/*
300
	 * (non-Javadoc)
301
	 * @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getWindowRaster(double, double, double, double, org.gvsig.fmap.dal.coverage.datastruct.BandList, org.gvsig.fmap.dal.coverage.dataset.Buffer, boolean)
302
	 */
303
	public Buffer getWindow(double ulx, double uly, double w, double h, 
304
			BandList bandList, Buffer rasterBuf, boolean adjustToExtent) throws ProcessInterruptedException, RasterDriverException {
305
		//TODO
306

  
307
		return rasterBuf;
308
	}
309

  
310
	/*
311
	 * (non-Javadoc)
312
	 * @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getWindowRaster(double, double, double, double, int, int, org.gvsig.fmap.dal.coverage.datastruct.BandList, org.gvsig.fmap.dal.coverage.dataset.Buffer, boolean)
313
	 */
314
	public Buffer getWindow(Extent extent, 
315
			int bufWidth, int bufHeight, BandList bandList, Buffer rasterBuf, boolean adjustToExtent) throws ProcessInterruptedException, RasterDriverException {
316
		//TODO
317
		
318
		return rasterBuf;
319
	}
320

  
321
	/*
322
	 * (non-Javadoc)
323
	 * @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getWindowRaster(int, int, int, int, org.gvsig.fmap.dal.coverage.datastruct.BandList, org.gvsig.fmap.dal.coverage.dataset.Buffer)
324
	 */
325
	public Buffer getWindow(int x, int y, int w, int h, 
326
			BandList bandList, Buffer rasterBuf) throws ProcessInterruptedException, RasterDriverException {
327
		//TODO
328
		
329
		return rasterBuf;
330
	}
331

  
332
	/*
333
	 * (non-Javadoc)
334
	 * @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getWindowRaster(int, int, int, int, int, int, org.gvsig.fmap.dal.coverage.datastruct.BandList, org.gvsig.fmap.dal.coverage.dataset.Buffer)
335
	 */
336
	public Buffer getWindow(int x, int y, int w, int h, 
337
			int bufWidth, int bufHeight, BandList bandList, Buffer rasterBuf) throws ProcessInterruptedException, RasterDriverException {
338
		//TODO
339
		
340
		return rasterBuf;
341
	}
342

  
343
	/*
344
	 * (non-Javadoc)
345
	 * @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getBlockSize()
346
	 */
347
	public int getBlockSize(){
348
		//TODO
349
		
350
		return 0;
351
	}
352

  
353
	/*
354
	 * (non-Javadoc)
355
	 * @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getMetadata()
356
	 */
357
	public DataStoreMetadata getMetadata() {
358
		//TODO
359
		
360
		return null;
361
	}
362

  
363
	/*
364
	 * (non-Javadoc)
365
	 * @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getColorInterpretation()
366
	 */
367
	public DataStoreColorInterpretation getColorInterpretation(){
368
		//TODO
369
		
370
		return null;
371
	}
372

  
373
	/*
374
	 * (non-Javadoc)
375
	 * @see org.gvsig.raster.impl.provider.DefaultRasterProvider#setColorInterpretation(org.gvsig.raster.impl.store.properties.DataStoreColorInterpretation)
376
	 */
377
	public void setColorInterpretation(DataStoreColorInterpretation colorInterpretation){
378
		//TODO
379
	}
380

  
381
	/*
382
	 * (non-Javadoc)
383
	 * @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getTransparency()
384
	 */
385
	public DataStoreTransparency getTransparency() {
386
		//TODO
387
		
388
		return null;
389
	}
390

  
391
	/*
392
	 * (non-Javadoc)
393
	 * @see org.gvsig.raster.impl.provider.DefaultRasterProvider#isGeoreferenced()
394
	 */
395
	public boolean isGeoreferenced() {
396
		//TODO
397
		
398
		return false;
399
	}
400

  
401
	/**
402
	 * Informa de si el driver ha supersampleado en el ?ltimo dibujado. Es el driver el que colocar?
403
	 * el valor de esta variable cada vez que dibuja.
404
	 * @return true si se ha supersampleado y false si no se ha hecho.
405
	 */
406
	public boolean isSupersampling() {
407
		//TODO
408
		
409
		return false;
410
	}
411

  
412
	/*
413
	 * (non-Javadoc)
414
	 * @see org.gvsig.raster.impl.provider.DefaultRasterProvider#setAffineTransform(java.awt.geom.AffineTransform)
415
	 */
416
	public void setAffineTransform(AffineTransform t){
417
		super.setAffineTransform(t);
418
	}
419

  
420
	/*
421
	 * (non-Javadoc)
422
	 * @see org.gvsig.raster.impl.provider.RasterProvider#getOverviewCount(int)
423
	 */
424
	public int getOverviewCount(int band) throws BandAccessException, RasterDriverException {
425
		if(band >= getBandCount())
426
			throw new BandAccessException("Wrong band");
427
		//TODO
428
		
429
		return 0;
430
	}
431

  
432
	/*
433
	 * (non-Javadoc)
434
	 * @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getOverviewWidth(int, int)
435
	 */
436
	public int getOverviewWidth(int band, int overview) throws BandAccessException, RasterDriverException {
437
		if (band >= getBandCount())
438
			throw new BandAccessException("Wrong band");
439
		//TODO
440
		
441
		return 0;
442
	}
443

  
444
	/*
445
	 * (non-Javadoc)
446
	 * @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getOverviewHeight(int, int)
447
	 */
448
	public int getOverviewHeight(int band, int overview) throws BandAccessException, RasterDriverException {
449
		if (band >= getBandCount())
450
			throw new BandAccessException("Wrong band");
451
		//TODO
452
		
453
		return 0;
454
	}
455

  
456
	/*
457
	 * (non-Javadoc)
458
	 * @see org.gvsig.raster.impl.provider.DefaultRasterProvider#overviewsSupport()
459
	 */
460
	public boolean overviewsSupport() {
461
		return true;
462
	}
463

  
464
	/*
465
	 * (non-Javadoc)
466
	 * @see org.gvsig.raster.impl.provider.DefaultRasterProvider#isReproyectable()
467
	 */
468
	public boolean isReproyectable() {
469
		return true;
470
	}
471

  
472
	/*
473
	 * (non-Javadoc)
474
	 * @see org.gvsig.fmap.dal.spi.DataStoreProvider#getName()
475
	 */
476
	public String getName() {
477
		return NAME;
478
	}
479
	
480
	/*
481
	 * (non-Javadoc)
482
	 * @see org.gvsig.raster.impl.provider.RasterProvider#setStatus(org.gvsig.raster.impl.provider.RasterProvider)
483
	 */
484
	public void setStatus(RasterProvider provider) {
485
		if(provider instanceof NetCDFProvider) {
486
			//Not implemented yet
487
		}
488
	}
489
	
490
	/*
491
	 * (non-Javadoc)
492
	 * @see org.gvsig.raster.impl.provider.RasterProvider#getTileServer()
493
	 */
494
	public TileServer getTileServer() {
495
		if(tileServer == null)
496
			tileServer = new FileTileServer(this);
497
		return tileServer;
498
	}
499
}
0 500

  
org.gvsig.raster.wmts/tags/2.0.0/org.gvsig.raster.wmts.io/src/test/resources/README.txt
1
Put into this folder the resources needed by your test classes.
2

  
3
This folder is added to the Tests classpath, so you can load any resources 
4
through the ClassLoader.
5

  
6
By default, in this folder you can find an example of log4j configuration,
7
prepared to log messages through the console, so logging works when you
8
run your tests classes.
0 9

  
org.gvsig.raster.wmts/tags/2.0.0/org.gvsig.raster.wmts.io/src/main/resources/META-INF/services/org.gvsig.tools.library.Library
1
org.gvsig.raster.wmts.io.DefaultWMTSIOLibrary
org.gvsig.raster.wmts/tags/2.0.0/org.gvsig.raster.wmts.io/src/main/java/org/gvsig/raster/wmts/io/WMTSDataParametersImpl.java
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.wmts.io;
24

  
25

  
26
import java.awt.geom.Rectangle2D;
27

  
28
import org.cresques.cts.IProjection;
29
import org.gvsig.compat.net.ICancellable;
30
import org.gvsig.fmap.crs.CRSFactory;
31
import org.gvsig.raster.impl.store.AbstractRasterDataParameters;
32
import org.gvsig.remoteclient.wmts.struct.WMTSLayer;
33
import org.gvsig.remoteclient.wmts.struct.WMTSStyle;
34
import org.gvsig.tools.ToolsLocator;
35
import org.gvsig.tools.dataTypes.DataTypes;
36
import org.gvsig.tools.dynobject.DelegatedDynObject;
37
import org.gvsig.tools.dynobject.DynClass;
38
import org.gvsig.tools.dynobject.DynField;
39
import org.gvsig.tools.dynobject.DynObjectManager;
40
import org.gvsig.tools.dynobject.DynStruct;
41
import org.gvsig.tools.persistence.PersistenceManager;
42
import org.gvsig.tools.persistence.PersistentState;
43
import org.gvsig.tools.persistence.exception.PersistenceException;
44

  
45
/**
46
 * Parameters for the WMTS provider
47
 * @author Nacho Brodin (nachobrodin@gmail.com)
48
 */
49
public class WMTSDataParametersImpl extends AbstractRasterDataParameters implements WMTSDataParameters {
50
	private DelegatedDynObject       delegatedDynObject    = null;
51
	protected static DynClass        DYNCLASS              = null;
52
	//private Logger                   log                   = LoggerFactory.getLogger(WMTSDataParametersImpl.class);
53
	
54
	public static void registerPersistence() {
55
		PersistenceManager manager = ToolsLocator.getPersistenceManager();
56
		DynStruct definition = manager.getDefinition("WMTSDataParametersImpl_Persistent");
57
		if( definition == null ) {
58
			definition = manager.addDefinition(
59
					WMTSDataParametersImpl.class,
60
					"WMTSDataParametersImpl_Persistent",
61
					"WMTS DataParameters Persistency",
62
					null, 
63
					null
64
			);
65
			AbstractRasterDataParameters.registerPersistence(definition);
66
			
67
			definition.addDynFieldObject(FIELD_EXTENT).setClassOfValue(Rectangle2D.class).setMandatory(false);
68
			definition.addDynFieldString(FIELD_IMAGE_FORMAT).setMandatory(false);
69
			definition.addDynFieldString(FIELD_INFO_FORMAT).setMandatory(false);
70
			definition.addDynFieldString(FIELD_NAME).setMandatory(false);			
71
			definition.addDynFieldString(FIELD_SRSSTR).setMandatory(false);
72
			definition.addDynFieldBoolean(FIELD_OVERRIDE).setMandatory(false);
73
		}
74
	}
75
	
76
	@Override
77
	public void saveToState(PersistentState state) throws PersistenceException {
78
		super.saveToState(state);
79
		
80
		state.set(FIELD_NAME, getName());	
81
		state.set(FIELD_SRSSTR, getSRSCode());
82
		state.set(FIELD_OVERRIDE, isOverridingHost());
83
		state.set(FIELD_EXTENT, getExtent());
84
		state.set(FIELD_IMAGE_FORMAT, getImageFormat());
85
		state.set(FIELD_INFO_FORMAT, getInfoFormat());
86
	}
87
	
88
	@Override
89
	public void loadFromState(PersistentState state)
90
			throws PersistenceException {
91
		super.loadFromState(state);
92
		
93
		setImageFormat(state.getString(FIELD_IMAGE_FORMAT));
94
		setInfoFormat(state.getString(FIELD_INFO_FORMAT));
95
		setName(state.getString(FIELD_NAME));
96
		setSRS(state.getString(FIELD_SRSSTR));
97
		setOverrideHost(state.getBoolean(FIELD_OVERRIDE));
98
		setExtent((Rectangle2D)state.get(FIELD_EXTENT));
99
	}
100
	
101
	/*
102
	 * (non-Javadoc)
103
	 * @see org.gvsig.raster.wmts.io.WMTSDataParameters#assignFields(org.gvsig.raster.wmts.io.WMTSDataParameters)
104
	 */
105
	public void assignFields(WMTSDataParameters p) {
106
		setImageFormat(p.getImageFormat());
107
		setInfoFormat(p.getInfoFormat());
108
		setName(p.getName());
109
		setSRS(p.getSRSCode());
110
		setOverrideHost(p.isOverridingHost());
111
		setExtent(p.getExtent());
112
	}
113
	 
114
	public WMTSDataParametersImpl() {
115
		super();
116
		initialize();
117
	}
118
	
119
	protected void initialize() {
120
		this.delegatedDynObject = (DelegatedDynObject) ToolsLocator
121
				.getDynObjectManager().createDynObject(
122
						DYNCLASS);
123
	}
124
	
125
	@SuppressWarnings("deprecation")
126
	public static void registerDynClass() {
127
		DynObjectManager dynman = ToolsLocator.getDynObjectManager();
128
		DynClass dynClass;
129
		DynField field;
130
		
131
		if(dynman == null)
132
			return;
133
		
134
		if (DYNCLASS == null) {
135
			dynClass = AbstractRasterDataParameters.registerDynClass(WMTSDataParametersImpl.DYNCLASS_NAME);
136

  
137
			field = dynClass.addDynField(FIELD_LAYER);
138
			field.setTheTypeOfAvailableValues(DynField.ANY);
139
			field.setDescription("Layer");
140
			field.setType(DataTypes.OBJECT);
141
			field.setMandatory(false);
142
			
143
			field = dynClass.addDynField(FIELD_STYLE);
144
			field.setTheTypeOfAvailableValues(DynField.ANY);
145
			field.setDescription("Style");
146
			field.setType(DataTypes.OBJECT);
147
			field.setMandatory(false);
148
			
149
			field = dynClass.addDynField(FIELD_SRS);
150
			field.setTheTypeOfAvailableValues(DynField.ANY);
151
			field.setDescription("SRS");
152
			field.setType(org.cresques.DataTypes.CRS);
153
			field.setMandatory(false);
154

  
155
			field = dynClass.addDynField(FIELD_IMAGE_FORMAT);
156
			field.setTheTypeOfAvailableValues(DynField.ANY);
157
			field.setDescription("Image Format");
158
			field.setType(DataTypes.STRING);
159
			field.setMandatory(false);
160

  
161
			field = dynClass.addDynField(FIELD_INFO_FORMAT);
162
			field.setTheTypeOfAvailableValues(DynField.ANY);
163
			field.setDescription("Info Format");
164
			field.setType(DataTypes.STRING);
165
			field.setMandatory(false);
166
			
167
			field = dynClass.addDynField(FIELD_NAME);
168
			field.setTheTypeOfAvailableValues(DynField.ANY);
169
			field.setDescription("Name");
170
			field.setType(DataTypes.STRING);
171
			field.setMandatory(false);
172
			
173
			field = dynClass.addDynField(FIELD_SRSSTR);
174
			field.setTheTypeOfAvailableValues(DynField.ANY);
175
			field.setDescription("String that represents the SRS");
176
			field.setType(DataTypes.STRING);
177
			field.setMandatory(false);
178
			
179
			field = dynClass.addDynField(FIELD_OVERRIDE);
180
			field.setTheTypeOfAvailableValues(DynField.ANY);
181
			field.setDescription("Override a host capabilities");
182
			field.setType(DataTypes.BOOLEAN);
183
			field.setMandatory(false);
184
			
185
			field = dynClass.addDynField(FIELD_CANCEL);
186
			field.setTheTypeOfAvailableValues(DynField.ANY);
187
			field.setDescription("Cancellable");
188
			field.setType(DataTypes.OBJECT);
189
			field.setMandatory(false);
190
			
191
			field = dynClass.addDynField(FIELD_EXTENT);
192
			field.setTheTypeOfAvailableValues(DynField.ANY);
193
			field.setDescription("Extent");
194
			field.setType(DataTypes.OBJECT);
195
			field.setMandatory(false);
196
			
197
			field = dynClass.addDynField(FIELD_WIDTH);
198
			field.setTheTypeOfAvailableValues(DynField.ANY);
199
			field.setDescription("Width");
200
			field.setType(DataTypes.INT);
201
			field.setMandatory(false);
202
			
203
			field = dynClass.addDynField(FIELD_HEIGHT);
204
			field.setTheTypeOfAvailableValues(DynField.ANY);
205
			field.setDescription("Height");
206
			field.setType(DataTypes.INT);
207
			field.setMandatory(false);
208
			
209
			field = dynClass.addDynField(FIELD_DELETECACHE);
210
			field.setTheTypeOfAvailableValues(DynField.ANY);
211
			field.setDescription("Flag to delete cache the next request");
212
			field.setType(DataTypes.BOOLEAN);
213
			field.setMandatory(false);
214
			
215
			DYNCLASS = dynClass;
216
		}
217

  
218
	}
219
	
220
	/**
221
	 * Sets the style selected
222
	 * @param layer
223
	 */
224
	public void setStyle(WMTSStyle layer) {
225
		this.setDynValue(FIELD_STYLE, layer);
226
	}
227
	
228
	/**
229
	 * Gets the style
230
	 * @return
231
	 */
232
	public WMTSStyle getStyle() {
233
		return (WMTSStyle) this.getDynValue(FIELD_STYLE);
234
	}
235
	
236
	/**
237
	 * Gets the image format
238
	 * @return Format
239
	 */
240
	public String getImageFormat() {
241
		return (String) this.getDynValue(FIELD_IMAGE_FORMAT);
242
	}
243

  
244
	/**
245
	 * Sets the image format
246
	 * @param format
247
	 */
248
	public void setImageFormat(String format) {
249
		this.setDynValue(FIELD_IMAGE_FORMAT, format);
250
	}
251
	
252
	/*
253
	 * (non-Javadoc)
254
	 * @see org.gvsig.fmap.dal.coverage.store.parameter.WMTSStoreParameters#getImageFormat()
255
	 */
256
	public String getInfoFormat() {
257
		return (String) this.getDynValue(FIELD_INFO_FORMAT);
258
	}
259

  
260
	/*
261
	 * (non-Javadoc)
262
	 * @see org.gvsig.fmap.dal.coverage.store.parameter.WMTSStoreParameters#setImageFormat(java.lang.String)
263
	 */
264
	public void setInfoFormat(String format) {
265
		this.setDynValue(FIELD_INFO_FORMAT, format);
266
	}
267
	
268
	/**
269
	 * Sets the layer selected
270
	 * @param layer
271
	 */
272
	public void setLayer(WMTSLayer layer) {
273
		this.setDynValue(FIELD_LAYER, layer);
274
	}
275
	
276
	/**
277
	 * Gets the layer
278
	 * @return
279
	 */
280
	public WMTSLayer getLayer() {
281
		return (WMTSLayer) this.getDynValue(FIELD_LAYER);
282
	}
283
	
284
	/**
285
	 * Devuelve el SRS.
286
	 * @return SRS.
287
	 */
288
	public String getSRSCode() {
289
		return (String) this.getDynValue(FIELD_SRSSTR);
290
	}
291
	
292
	public void setSRS(String m_srs) {
293
		if(m_srs.compareTo("CRS:84") == 0)
294
			m_srs = "EPSG:4326";
295
		this.setDynValue(FIELD_SRSSTR, m_srs);
296
		if(getEPSG(m_srs) != null)
297
			setSRS(CRSFactory.getCRS(getEPSG(m_srs)));
298
	}
299
	
300
	public void setSRS(IProjection srs) {
301
		setDynValue(FIELD_SRS, srs);
302
	}
303

  
304
	/**
305
	 * Returns the projection
306
	 * @return
307
	 */
308
	public IProjection getSRS() {
309
		if (this.getSRSID() == null) {
310
			return null;
311
		}
312
		return (IProjection) getDynValue(FIELD_SRS);
313
	}
314
	
315
	/**
316
	 * Returns true if the layer is projected
317
	 * @return
318
	 */
319
	public boolean isProjected() {
320
		IProjection proj = getSRS();
321
		if(proj == null)
322
			return false;
323
		else
324
			return proj.isProjected();
325
	}
326
	
327
	public String getSRSID() {
328
		IProjection srs = (IProjection) getDynValue(FIELD_SRS);
329
		if (srs == null) {
330
			return null;
331
		}
332
		return srs.getAbrev();
333
	}
334

  
335
	public void setSRSID(String srsid) {
336
		if (srsid == null) {
337
			setDynValue(FIELD_SRS, null);
338
		} else {
339
			setDynValue(FIELD_SRS, CRSFactory.getCRS(getEPSG(srsid)));
340
		}
341
	}
342
	
343
	/**
344
	 * Returns the current selected SRS.
345
	 * @return
346
	 */
347
	public String getEPSG(String value) {
348
		if(value != null) {
349
			if(value.compareTo("CRS:84") == 0)
350
				return "EPSG:4326";
351

  
352
			String s = value.substring(value.lastIndexOf(":") + 1);
353
			return "EPSG:" + s;
354
		}
355
		return null;
356
	}
357
	
358
	public String getName() {
359
		return (String) this.getDynValue(FIELD_NAME);
360
	}
361

  
362
	public void setName(String name) {
363
		this.setDynValue(FIELD_NAME, name);
364
	}
365
	
366
	public void setCancellable(ICancellable cancel) {
367
		this.setDynValue(FIELD_CANCEL, cancel);
368
	}
369
	
370
	public ICancellable getCancellable() {
371
		return (ICancellable) this.getDynValue(FIELD_CANCEL);
372
	}
373
	
374
	/*
375
	 * (non-Javadoc)
376
	 * @see org.gvsig.fmap.dal.coverage.store.RasterStoreParameters#isOverridingHost()
377
	 */
378
	public boolean isOverridingHost() {
379
		Boolean b = (Boolean)getDynValue(FIELD_OVERRIDE);
380
		if(b != null)
381
			return ((Boolean)b).booleanValue();
382
		return false;
383
	}
384
	
385
	/*
386
	 * (non-Javadoc)
387
	 * @see org.gvsig.fmap.dal.coverage.store.RasterStoreParameters#setOverrideHost(boolean)
388
	 */
389
	public void setOverrideHost(boolean over) {
390
		this.setDynValue(FIELD_OVERRIDE, new Boolean(over));;
391
	}
392

  
393
	/**
394
	 * Assigns the extent. 
395
	 * When a provider is initialized this will need to know what is the extent before the request.
396
	 * 
397
	 * @param bBox
398
	 */
399
	public void setExtent(Rectangle2D bBox) {
400
		this.setDynValue(FIELD_EXTENT, bBox);
401
	}
402
	
403
	/**
404
	 * Sets the width
405
	 * When a provider is initialized this will need to know what is the width before the request.
406
	 * @param w
407
	 */
408
	public void setWidth(int w) {
409
		this.setDynValue(FIELD_WIDTH, new Integer(w));
410
	}
411
	
412
	/**
413
	 * Sets the height
414
	 * When a provider is initialized this will need to know what is the height before the request.
415
	 * @param h
416
	 */
417
	public void setHeight(int h) {
418
		this.setDynValue(FIELD_HEIGHT, new Integer(h));
419
	}
420
	
421
	/**
422
	 * Gets the bounding box
423
	 * @return
424
	 */
425
	public Rectangle2D getExtent() {
426
		return (Rectangle2D)getDynValue(FIELD_EXTENT);
427
	}
428
	
429
	/**
430
	 * Gets the width
431
	 * @return
432
	 */
433
	public int getWidth() {
434
		Integer b = (Integer)getDynValue(FIELD_WIDTH);
435
		if(b != null)
436
			return ((Integer)b).intValue();
437
		return 0;
438
	}
439
	
440
	/**
441
	 * Gets the height
442
	 * @return
443
	 */
444
	public int getHeight() {
445
		Integer b = (Integer)getDynValue(FIELD_HEIGHT);
446
		if(b != null)
447
			return ((Integer)b).intValue();
448
		return 0;
449
	}
450

  
451
	//**********************************************
452
	
453
	/*
454
	 * (non-Javadoc)
455
	 * @see org.gvsig.fmap.dal.DataStoreParameters#getDataStoreName()
456
	 */
457
	public String getDataStoreName() {
458
		return WMTSProvider.NAME;
459
	}
460
	
461
	/*
462
	 * (non-Javadoc)
463
	 * @see org.gvsig.fmap.dal.DataStoreParameters#getDescription()
464
	 */
465
	public String getDescription() {
466
		return WMTSProvider.DESCRIPTION;
467
	}
468

  
469
	public String getExplorerName() {
470
		return WMTSServerExplorer.NAME;
471
	}
472
	
473
	public boolean isValid() {
474
		return (this.getURI() != null);
475
	}
476
	
477
	protected DelegatedDynObject getDelegatedDynObject() {
478
		return delegatedDynObject;
479
	}
480
	
481
	/**
482
	 * Clones this structure
483
	 * @return
484
	 */
485
	public WMTSDataParameters clone() {
486
		WMTSDataParametersImpl p = new WMTSDataParametersImpl();
487
		p.setImageFormat(getImageFormat());
488
		p.setInfoFormat(getInfoFormat());
489
		p.setHeight(getHeight());
490
		p.setWidth(getWidth());
491
		p.setExtent(getExtent());
492
		p.setURI(getURI());
493
		p.setName(getName());
494
		p.setOverrideHost(isOverridingHost());
495
		p.setSRS(getSRS());
496
		p.setSRS(getSRSCode());
497
		p.setCancellable(getCancellable());
498
		return p;
499
	}
500

  
501
	/*
502
	 * (non-Javadoc)
503
	 * @see org.gvsig.fmap.dal.coverage.store.parameter.RemoteStoreParameters#isSizeFixed()
504
	 */
505
	public boolean isSizeFixed() {
506
		return true;
507
	}
508

  
509
	public void deleteCache(boolean deleteCache) {
510
		this.setDynValue(FIELD_DELETECACHE, new Boolean(deleteCache));
511
	}
512
	
513
	public boolean isDeletingCache() {
514
		return ((Boolean)getDynValue(FIELD_DELETECACHE)).booleanValue();
515
	}
516
	
517
}
0 518

  
org.gvsig.raster.wmts/tags/2.0.0/org.gvsig.raster.wmts.io/src/main/java/org/gvsig/raster/wmts/io/TilePipe.java
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.raster.wmts.io;
23

  
24
import org.gvsig.remoteclient.wmts.struct.WMTSTileMatrix.Tile;
25

  
26
/**
27
 * This class manages transactions between the producer and the consumer. The
28
 * producer download tiles from a server and the consumer is a tile provider
29
 * which will return downloaded tiles.
30
 *
31
 * @author Nacho Brodin (nachobrodin@gmail.com)
32
 */
33
public class TilePipe {
34
	//N?mero de threads m?ximos a lanzar para descarga. Cuando se lanzan m?s de estos el 
35
	//invocador debe dormir hasta que se haya liberado alguno.
36
	public static int            NTHREADS_QUEUE = 5;
37
	//N?mero m?ximo de elementos en la tuberia. Cuando se llene esta el setTile de esta clase debe
38
	//dormir hasta que getTile lo despierte.
39
	private final static int     BUFFER_SIZE    = 10;
40
	
41
	private Tile                 buffer[]       = new Tile[BUFFER_SIZE];
42
	private int                  next           = 0;
43
	private boolean              isFull         = false;
44
	private boolean              isEmpty        = true;
45
	private Thread               threadManager  = null;
46

  
47
	/**
48
	 * El thread manager no se usa con la pool solo para la implementaci?n de RequestThreadManager
49
	 * @param threadManager
50
	 */
51
	public void setRequestManager(Thread threadManager) {
52
		this.threadManager = threadManager;
53
	}
54
	
55
	/**
56
	 * Sets a tile in the pipe
57
	 * @param tile
58
	 */
59
	public synchronized void setTile(Tile tile) {
60
		while( isFull == true ) {
61
			try {
62
				wait();
63
			} catch( InterruptedException e ) {
64
			}
65
		}
66
		buffer[next] = tile;
67
		next++;
68
		if( next == BUFFER_SIZE )
69
			isFull = true;
70
		isEmpty = false;
71
		notify();
72
	}
73

  
74
	/**
75
	 * Gets a tile from the pipe
76
	 * @return
77
	 */
78
	public synchronized Tile getTile() {
79
		while( isEmpty == true ) {
80
			try {
81
				wait();
82
			} catch( InterruptedException e ) {
83
			}
84
		}
85
        next--;
86
        if( next == 0 )
87
        	isEmpty = true;
88
        isFull = false;
89
        notify();
90
        if(threadManager != null && getSize() <= NTHREADS_QUEUE) {
91
        	synchronized(threadManager) {
92
        		threadManager.notify();
93
        	}
94
        }
95
        	
96
        return buffer[next] ;
97
	}
98
	
99
	/**
100
	 * Returns the number of elements in the queue
101
	 * @return
102
	 */
103
	public synchronized int getSize() {
104
		return next;
105
	}
106
}
0 107

  
org.gvsig.raster.wmts/tags/2.0.0/org.gvsig.raster.wmts.io/src/main/java/org/gvsig/raster/wmts/io/DefaultWMTSIOLibrary.java
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.raster.wmts.io;
23

  
24
import org.gvsig.tools.library.AbstractLibrary;
25
import org.gvsig.tools.library.LibraryException;
26
/**
27
 *
28
 * @author Nacho Brodin (nachobrodin@gmail.com)
29
 */
30
public class DefaultWMTSIOLibrary extends AbstractLibrary {	
31

  
32
	public DefaultWMTSIOLibrary() {
33
		/*super(DefaultWMTSIOLibrary.class,Library.TYPE.IMPL);
34
		require(ToolsLibrary.class);
35
		require(DALLibrary.class);
36
		require(DALFileLibrary.class);*/
37
	}
38
	
39
	@Override
40
	protected void doInitialize() throws LibraryException {
41
		//RasterLibrary.wakeUp();
42
	}
43

  
44
	@Override
45
	protected void doPostInitialize() throws LibraryException {
46
		WMTSServerExplorerParameters.registerDynClass();
47
		WMTSDataParametersImpl.registerDynClass();
48
		WMTSProvider.register();
49
		WMTSDataParametersImpl.registerPersistence();
50
	}
51
}
0 52

  
org.gvsig.raster.wmts/tags/2.0.0/org.gvsig.raster.wmts.io/src/main/java/org/gvsig/raster/wmts/io/downloader/TileDownloaderForWMTS.java
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.raster.wmts.io.downloader;
23

  
24
import java.io.File;
25
import java.io.IOException;
26
import java.net.ConnectException;
27
import java.net.URL;
28

  
29
import org.gvsig.fmap.dal.coverage.exception.RemoteServiceException;
30
import org.gvsig.raster.cache.tile.Tile;
31
import org.gvsig.raster.cache.tile.exception.TileGettingException;
32
import org.gvsig.raster.impl.provider.tile.BaseTileDownloader;
33
import org.gvsig.raster.wmts.io.WMTSConnector;
34
import org.gvsig.raster.wmts.io.WMTSDataParameters;
35
import org.gvsig.raster.wmts.io.WMTSProvider;
36
import org.gvsig.remoteclient.exceptions.ServerErrorException;
37
import org.gvsig.remoteclient.wmts.WMTSStatus;
38
import org.gvsig.remoteclient.wmts.exception.WMTSException;
39

  
40
/** 
41
 * Tile getter 
42
 * @author Nacho Brodin (nachobrodin@gmail.com)
43
 */
44
public class TileDownloaderForWMTS extends BaseTileDownloader {
45
	private WMTSConnector             connector  = null;
46
	
47
	public TileDownloaderForWMTS(WMTSProvider prov, 
48
			int tilePxWidth,
49
			int tilePxHeight) {
50
		super(prov, tilePxWidth, tilePxHeight);
51
	}
52
	
53
	/**
54
	 * Gets the connector from the URL
55
	 * @return
56
	 * @throws RemoteServiceException
57
	 */
58
	public WMTSConnector getConnector() throws WMTSException {
59
		if(connector == null) {
60
			WMTSDataParameters p = (WMTSDataParameters)prov.getDataParameters();
61
			URL url = null;
62
			try {
63
				url = new URL(p.getURI());
64
			} catch (Exception e) {
65
				throw new WMTSException("Malformed URL",e);
66
			}
67
			try {
68
				connector = new WMTSConnector(url);
69
			} catch (ConnectException e) {
70
				throw new WMTSException("Connect exception",e);
71
			} catch (IOException e) {
72
				throw new WMTSException("Connect exception",e);
73
			}
74
		}
75
		return connector;
76
	}
77
	
78
	/*
79
	 * (non-Javadoc)
80
	 * @see org.gvsig.raster.cache.tile.provider.Downloader#getTile(org.gvsig.raster.cache.tile.Tile)
81
	 */
82
	public synchronized Tile downloadTile(Tile tile) throws TileGettingException {
83
		try {
84
			WMTSStatus status = (WMTSStatus)tile.getDownloaderParams("WMTSStatus");
85
			status.setTileRow(tile.getRow());
86
			status.setTileCol(tile.getCol());
87
			File f = getConnector().getTile(status, tile.getCancelled(), tile.getFile());
88
			tile.setFile(f);
89
			//Si borramos el rmf no se puede leer la etiqueta Alpha. En caso de que se modifique jgdal para
90
			//poder guardar esta etiqueta deberiamos borrar el rmf para ahorrar ficheros
91
			//File rmf = new File(tile.getFile().getAbsolutePath() + ".rmf");
92
			//if(rmf.exists())
93
				//rmf.delete();
94
		} catch (WMTSException e) {
95
			throw new TileGettingException(e);
96
		} catch (ServerErrorException e) {
97
			throw new TileGettingException(e);
98
		}
99
		readTileFromDisk(tile);
100
		return tile;
101
	}
102
	
103
}
0 104

  
org.gvsig.raster.wmts/tags/2.0.0/org.gvsig.raster.wmts.io/src/main/java/org/gvsig/raster/wmts/io/downloader/WMTSTileServer.java
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.raster.wmts.io.downloader;
23

  
24
import org.gvsig.raster.cache.tile.provider.CacheStruct;
25
import org.gvsig.raster.cache.tile.provider.Downloader;
26
import org.gvsig.raster.cache.tile.provider.TileServer;
27
import org.gvsig.raster.wmts.io.WMTSProvider;
28
import org.gvsig.remoteclient.wmts.struct.WMTSTileMatrix;
29
import org.gvsig.remoteclient.wmts.struct.WMTSTileMatrixSetLink;
30

  
31
/** 
32
* Data server for the tile cache in a WMTSProvider 
33
* @author Nacho Brodin (nachobrodin@gmail.com)
34
*/
35
public class WMTSTileServer implements TileServer {
36
	private CacheStruct                struct               = null;
37
	private Downloader                 downloader           = null;
38
	private WMTSProvider               provider             = null;
39
	private String                     suffix               = ".tif";
40
	private WMTSTileMatrixSetLink      tileMatrixSetLink    = null;
41
	
42
	public WMTSTileServer(WMTSProvider prov, 
43
			WMTSTileMatrixSetLink tileMatrixSetLink) {
44
		this.provider = prov;
45
		this.tileMatrixSetLink = tileMatrixSetLink;
46
	}
47
	
48
	/*
49
	 * (non-Javadoc)
50
	 * @see org.gvsig.raster.cache.tile.provider.TileServer#getDownloader()
51
	 */
52
	public Downloader getDownloader() {
53
		//if(downloader == null) {
54
			int tileWidth = ((WMTSTileMatrix)tileMatrixSetLink.getTileMatrixSet().getTileMatrix().get(0)).getTileWidth();
55
			int tileHeight = ((WMTSTileMatrix)tileMatrixSetLink.getTileMatrixSet().getTileMatrix().get(0)).getTileHeight();
56
			downloader = new TileDownloaderForWMTS(provider, tileWidth, tileHeight);
57
		//}
58
		return downloader;
59
	}
60

  
61
	public CacheStruct getStruct() {
62
		if(struct == null) {
63
			struct = new WMTSCacheStruct(provider, tileMatrixSetLink);
64
		}
65
		return struct;
66
	}
67
	
68
	/*
69
	 * (non-Javadoc)
70
	 * @see org.gvsig.raster.cache.tile.provider.TileServer#setStruct(org.gvsig.raster.cache.tile.provider.CacheStruct)
71
	 */
72
	public void setStruct(CacheStruct struct) {
73
		//La structura de cache es proporcionada por el servidor
74
	}
75
	
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff