Revision 1161

View differences:

org.gvsig.raster.wmts/tags/buildNumber_20/org.gvsig.raster.wmts/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/buildNumber_20/org.gvsig.raster.wmts/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/buildNumber_20/org.gvsig.raster.wmts/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/buildNumber_20/org.gvsig.raster.wmts/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
	
76
	/*
77
	 * (non-Javadoc)
78
	 * @see org.gvsig.raster.cache.tile.provider.TileServer#getFileSuffix()
79
	 */
80
	public String getFileSuffix() {
81
		return suffix;
82
	}
83
	
84
	/*
85
	 * (non-Javadoc)
86
	 * @see org.gvsig.raster.cache.tile.provider.TileServer#setFileExtension(java.lang.String)
87
	 */
88
	public void setFileSuffix(String extension) {
89
		this.suffix = extension;
90
	}
91
}
0 92

  
org.gvsig.raster.wmts/tags/buildNumber_20/org.gvsig.raster.wmts/org.gvsig.raster.wmts.io/src/main/java/org/gvsig/raster/wmts/io/downloader/WMTSCacheStruct.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.awt.geom.Point2D;
25
import java.awt.geom.Rectangle2D;
26
import java.util.ArrayList;
27

  
28
import org.gvsig.fmap.dal.coverage.RasterLocator;
29
import org.gvsig.fmap.dal.coverage.exception.RasterDriverException;
30
import org.gvsig.fmap.dal.coverage.util.MathUtils;
31
import org.gvsig.raster.cache.tile.Tile;
32
import org.gvsig.raster.cache.tile.TileCacheLocator;
33
import org.gvsig.raster.cache.tile.exception.TileBuildException;
34
import org.gvsig.raster.cache.tile.provider.CacheStruct;
35
import org.gvsig.raster.wmts.io.WMTSDataParameters;
36
import org.gvsig.raster.wmts.io.WMTSProvider;
37
import org.gvsig.remoteclient.wmts.WMTSStatus;
38
import org.gvsig.remoteclient.wmts.struct.WMTSTileMatrix;
39
import org.gvsig.remoteclient.wmts.struct.WMTSTileMatrixLimits;
40
import org.gvsig.remoteclient.wmts.struct.WMTSTileMatrixSet;
41
import org.gvsig.remoteclient.wmts.struct.WMTSTileMatrixSetLink;
42

  
43
/**
44
 * Implementation for a structure of a cache
45
 * @author Nacho Brodin (nachobrodin@gmail.com)
46
 */
47
public class WMTSCacheStruct implements CacheStruct {
48
    private String                        layerName           = null;
49
	private String                        serverURL           = null;
50
	private WMTSTileMatrixSet             tileMatrixSet       = null;
51
	private ArrayList<?>                  tileMatrixSetLimits = null;
52
	private double[]                      pixelSize           = null;
53
    private WMTSProvider                  provider            = null;
54
    
55
    public WMTSCacheStruct(WMTSProvider provider, WMTSTileMatrixSetLink tileMatrixSetLink) {
56
    	this.provider = provider;
57
    	this.tileMatrixSet = tileMatrixSetLink.getTileMatrixSet();
58
		this.tileMatrixSetLimits = tileMatrixSetLink.getTileMatrixLimits();
59
		pixelSize = provider.getPixelSizeByLevel();
60
		serverURL = provider.getURIOfFirstProvider();
61
		layerName = ((WMTSDataParameters)provider.getDataParameters()).getLayer().getTitle();
62
    }
63

  
64
    /*
65
     * (non-Javadoc)
66
     * @see org.gvsig.raster.cache.tile.provider.CacheStruct#getNumberOfLevels()
67
     */
68
	public int getNumberOfLevels() {
69
		return tileMatrixSet.getTileMatrix().size();
70
	}
71

  
72
	/*
73
	 * (non-Javadoc)
74
	 * @see org.gvsig.raster.cache.tile.provider.CacheStruct#getLayerName()
75
	 */
76
	public String getLayerName() {
77
		return layerName;
78
	}
79

  
80
	/*
81
	 * (non-Javadoc)
82
	 * @see org.gvsig.raster.cache.tile.provider.CacheStruct#getServerURL()
83
	 */
84
	public String getServerURL() {
85
		return serverURL;
86
	}
87

  
88
	/*
89
	 * (non-Javadoc)
90
	 * @see org.gvsig.raster.cache.tile.provider.CacheStruct#getTileSizeByLevel(int)
91
	 */
92
	public int[] getTileSizeByLevel(int level) {
93
		return new int[] {
94
			((WMTSTileMatrix)tileMatrixSet.getTileMatrix().get(level)).getTileWidth(),
95
			((WMTSTileMatrix)tileMatrixSet.getTileMatrix().get(level)).getTileHeight()
96
		};
97
	}
98

  
99
	/*
100
	 * (non-Javadoc)
101
	 * @see org.gvsig.raster.cache.tile.provider.CacheStruct#getLayerWidthOfTileMatrixByLevel(int)
102
	 */
103
	public int getLayerWidthOfTileMatrixByLevel(int level) {
104
		if(tileMatrixSetLimits != null && tileMatrixSetLimits.size() > level) {
105
			WMTSTileMatrixLimits l = (WMTSTileMatrixLimits)tileMatrixSetLimits.get(level);
106
			return l.getMaxTileRow() - l.getMinTileRow();
107
		} else {
108
			WMTSTileMatrix tm = (WMTSTileMatrix)tileMatrixSet.getTileMatrix().get(level);
109
			return (int)tm.getMatrixWidth();
110
		}
111
	}
112
	
113
	/*
114
	 * (non-Javadoc)
115
	 * @see org.gvsig.raster.cache.tile.provider.CacheStruct#getLayerHeightOfTileMatrixByLevel(int)
116
	 */
117
	public int getLayerHeightOfTileMatrixByLevel(int level) {
118
		if(tileMatrixSetLimits != null && tileMatrixSetLimits.size() > level) {
119
			WMTSTileMatrixLimits l = (WMTSTileMatrixLimits)tileMatrixSetLimits.get(level);
120
			return l.getMaxTileCol() - l.getMinTileCol();
121
		} else {
122
			WMTSTileMatrix tm = (WMTSTileMatrix)tileMatrixSet.getTileMatrix().get(level);
123
			return (int)tm.getMatrixHeight();
124
		}
125
	}
126

  
127
	/*
128
	 * (non-Javadoc)
129
	 * @see org.gvsig.raster.cache.tile.provider.CacheStruct#getLayerInitXTilePositionByLevel(int)
130
	 */
131
	public int getLayerInitXTilePositionByLevel(int level) {
132
		if(tileMatrixSetLimits != null && tileMatrixSetLimits.size() > level) {
133
			WMTSTileMatrixLimits l = (WMTSTileMatrixLimits)tileMatrixSetLimits.get(level);
134
			return l.getMinTileCol();
135
		} else
136
			return 0;
137
	}
138

  
139
	/*
140
	 * (non-Javadoc)
141
	 * @see org.gvsig.raster.cache.tile.provider.CacheStruct#getLayerInitYTilePositionByLevel(int)
142
	 */
143
	public int getLayerInitYTilePositionByLevel(int level) {
144
		if(tileMatrixSetLimits != null && tileMatrixSetLimits.size() > level) {
145
			WMTSTileMatrixLimits l = (WMTSTileMatrixLimits)tileMatrixSetLimits.get(level);
146
			return l.getMinTileRow();
147
		} else 
148
			return 0;
149
	}
150

  
151
	/*
152
	 * (non-Javadoc)
153
	 * @see org.gvsig.raster.cache.tile.provider.CacheStruct#getWorldHeightOfTileMatrixByLevel(int)
154
	 */
155
	public long getWorldHeightOfTileMatrixByLevel(int level) {
156
		return ((WMTSTileMatrix)tileMatrixSet.getTileMatrix().get(level)).getMatrixWidth();
157
	}
158

  
159
	/*
160
	 * (non-Javadoc)
161
	 * @see org.gvsig.raster.cache.tile.provider.CacheStruct#getWorldWidthOfTileMatrixByLevel(int)
162
	 */
163
	public long getWorldWidthOfTileMatrixByLevel(int level) {
164
		return ((WMTSTileMatrix)tileMatrixSet.getTileMatrix().get(level)).getMatrixHeight();
165
	}
166
	
167
	/*
168
	 * (non-Javadoc)
169
	 * @see org.gvsig.raster.cache.tile.provider.CacheStruct#getPixelSizeByLevel(int)
170
	 */
171
	public double getPixelSizeByLevel(int level) {
172
		if(level < pixelSize.length)
173
			return pixelSize[level];
174
		else
175
			return pixelSize[pixelSize.length - 1];
176
	}
177
	
178
	/*
179
	 * (non-Javadoc)
180
	 * @see org.gvsig.raster.cache.tile.provider.CacheStruct#getTileExtent(org.gvsig.raster.cache.tile.Tile)
181
	 */
182
	public Point2D[] getTileExtent(Tile tile) {
183
		return getTileExtent(tile.getLevel(), tile.getCol(), tile.getRow());
184
	}
185
	
186
	/*
187
	 * (non-Javadoc)
188
	 * @see org.gvsig.raster.cache.tile.provider.CacheStruct#getTileExtent(int, int, int)
189
	 */
190
	public Point2D[] getTileExtent(int level, int col, int row) {
191
		double[] ul = tileMatrixSet.getBoundingBox().getUpperCorner();
192
		long tileWidth = ((WMTSTileMatrix)tileMatrixSet.getTileMatrix().get(level)).getTileWidth();
193
		long tileHeight = ((WMTSTileMatrix)tileMatrixSet.getTileMatrix().get(level)).getTileHeight();
194
		double mtsWidthTile = tileWidth * pixelSize[level];
195
		double mtsHeightTile = tileHeight * pixelSize[level];
196
		double ulx = ul[0] + (col * mtsWidthTile);
197
		double uly = ulx + mtsWidthTile;
198
		double lrx = ul[1] - (row * mtsHeightTile);
199
		double lry = lrx - mtsHeightTile;
200
		return new Point2D[]{new Point2D.Double(ulx, uly), new Point2D.Double(lrx, lry)};
201
	}
202
	
203
	/*
204
	 * (non-Javadoc)
205
	 * @see org.gvsig.raster.cache.tile.provider.CacheStruct#getTileStructure(int, int, int, java.awt.geom.Point2D, java.awt.geom.Point2D)
206
	 */
207
	public Tile getTileStructure(int level, int tileCol, int tileRow, Point2D ul, Point2D lr) throws TileBuildException  {
208
		int[] size = getTileSizeByLevel(level);
209
		Tile tile = TileCacheLocator.getManager().createTile(level, tileRow, tileCol);
210
		tile.setUl(ul);
211
		tile.setLr(lr);
212
		tile.setWidthPx(size[0]);
213
		tile.setHeightPx(size[1]);
214
		
215
		Rectangle2D r = new Rectangle2D.Double(Math.min(ul.getX(), lr.getX()), 
216
				Math.min(ul.getY(), lr.getY()), 
217
				Math.abs(ul.getX() - lr.getX()), 
218
				Math.abs(ul.getY() - lr.getY()));
219
		int bufWidth = (int)(r.getWidth() / getPixelSizeByLevel(level));
220
		int bufHeight = (int)(r.getHeight() / getPixelSizeByLevel(level));
221
		try {
222
			WMTSStatus status = provider.buildWMTSStatus(r, bufWidth, bufHeight);
223
			tile.setDownloaderParams("WMTSStatus", status);
224
		} catch (RasterDriverException e) {
225
			throw new TileBuildException(e); 
226
		}
227
			
228
		return tile;
229
	}
230
	
231
	/*
232
	 * (non-Javadoc)
233
	 * @see org.gvsig.raster.cache.tile.provider.CacheStruct#getTileList(java.awt.geom.Point2D, java.awt.geom.Point2D)
234
	 */
235
	@SuppressWarnings("unchecked")
236
	public ArrayList<Tile> getTileList(Point2D ul, Point2D lr, double mtsPixelRequest) throws TileBuildException {
237
		Rectangle2D r = new Rectangle2D.Double(Math.min(ul.getX(), lr.getX()), 
238
				Math.min(ul.getY(), lr.getY()), 
239
				Math.abs(ul.getX() - lr.getX()), 
240
				Math.abs(ul.getY() - lr.getY()));
241
		int bufWidth = (int)(r.getWidth() / mtsPixelRequest);
242
		int bufHeight = (int)(r.getHeight() / mtsPixelRequest);
243
		try {
244
			WMTSStatus status = provider.buildWMTSStatus(r, bufWidth, bufHeight);
245
			
246
			//Conversi?n a tiles de la librer?a
247
			ArrayList<org.gvsig.remoteclient.wmts.struct.WMTSTileMatrix.Tile> tiles = status.getTileList();
248
			ArrayList<Tile> tileList = new ArrayList<Tile>();
249
			for (int i = 0; i < tiles.size(); i++) {
250
				org.gvsig.remoteclient.wmts.struct.WMTSTileMatrix.Tile tOrigin = (org.gvsig.remoteclient.wmts.struct.WMTSTileMatrix.Tile) tiles.get(i);
251
				Tile t = TileCacheLocator.getManager().createTile(status.getLevel(), tOrigin.col, tOrigin.row);
252
				t.setUl(new Point2D.Double(tOrigin.ulx, tOrigin.uly));
253
				t.setLr(new Point2D.Double(tOrigin.lrx, tOrigin.lry));
254
				t.setWidthPx(tOrigin.wPx);
255
				t.setHeightPx(tOrigin.hPx);
256
				t.setDownloaderParams("WMTSStatus", provider.buildWMTSStatus(r, bufWidth, bufHeight));
257
				tileList.add(t);
258
			}
259
			return tileList;
260
		} catch (RasterDriverException e) {
261
			throw new TileBuildException(e); 
262
		}
263
	}
264

  
265
	/*
266
	 * (non-Javadoc)
267
	 * @see org.gvsig.raster.cache.tile.provider.CacheStruct#getTileSizeInRealCoordsByLevel(int)
268
	 */
269
	public double[] getTileSizeInRealCoordsByLevel(int level) {
270
		return new double[] {
271
				getPixelSizeByLevel(level) * getTileSizeByLevel(level)[0],
272
				getPixelSizeByLevel(level) *  getTileSizeByLevel(level)[1]
273
			};
274
	}
275
	
276
	/*
277
	 * (non-Javadoc)
278
	 * @see org.gvsig.raster.cache.tile.provider.CacheStruct#getFileSuffix()
279
	 */
280
	public String getFileSuffix() {
281
		return provider.getFileSuffix();
282
	}
283

  
284
	/*
285
	 * (non-Javadoc)
286
	 * @see org.gvsig.raster.cache.tile.provider.CacheStruct#compare(org.gvsig.raster.cache.tile.provider.CacheStruct)
287
	 */
288
	public boolean compare(CacheStruct struct) {
289
		MathUtils mu = RasterLocator.getManager().getMathUtils();
290
		//Compara: n?mero de niveles, tama?o de tile, 
291
		//anchoXalto de la matriz, tama?o de pixel por nivel, 
292
		//coordenadas de al menos un tile de la matriz
293
		if(struct.getNumberOfLevels() == getNumberOfLevels()) {
294
			for (int i = 0; i < getNumberOfLevels(); i++) {
295
				if(	struct.getTileSizeByLevel(i)[0] == getTileSizeByLevel(i)[0] && 
296
					struct.getTileSizeByLevel(i)[1] == getTileSizeByLevel(i)[1] &&
297
					struct.getWorldHeightOfTileMatrixByLevel(i) == getWorldHeightOfTileMatrixByLevel(i) &&
298
					struct.getWorldWidthOfTileMatrixByLevel(i) == getWorldWidthOfTileMatrixByLevel(i) &&
299
					mu.clipDecimals(struct.getPixelSizeByLevel(i), 2) == mu.clipDecimals(getPixelSizeByLevel(i), 2) &&
300
					compareExtents(struct.getTileExtent(i, 0, 0), getTileExtent(i, 0, 0))) {
301
					return true;
302
				}
303
			}
304
		}
305
		return false;
306
	}
307
	
308
	private boolean compareExtents(Point2D[] p, Point2D[] p1) {
309
		return (p[0].getX() == p1[0].getX() && p[0].getY() == p1[0].getY() &&
310
				p[1].getX() == p1[1].getX() && p[1].getY() == p1[1].getY());
311
	}
312

  
313
	/*
314
	 * (non-Javadoc)
315
	 * @see org.gvsig.raster.cache.tile.provider.CacheStruct#getEPSG()
316
	 */
317
	public String getEPSG() {
318
		/*IProjection proj = provider.getProjection();
319
		if(proj != null)
320
			return proj.getAbrev();
321
		return null;*/
322
		return provider.getSRSCode();
323
	}
324

  
325
	/*
326
	 * (non-Javadoc)
327
	 * @see org.gvsig.raster.cache.tile.provider.CacheStruct#getFileSize()
328
	 */
329
	public String getFileSize() {
330
		return "0";
331
	}
332

  
333
	public ArrayList<Tile> getTileList(int x, int y, int w, int h) {
334
		return null;
335
	}
336

  
337
	public ArrayList<Tile> getTileList(Rectangle2D r) {
338
		return null;
339
	}
340
}
0 341

  
org.gvsig.raster.wmts/tags/buildNumber_20/org.gvsig.raster.wmts/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/buildNumber_20/org.gvsig.raster.wmts/org.gvsig.raster.wmts.io/src/main/java/org/gvsig/raster/wmts/io/package.html
1
<?xml version="1.0" encoding="UTF-8" ?>
2
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
<html xmlns="http://www.w3.org/1999/xhtml">
4
<head>
5
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
6
<title>org.gvsig.raster.wmts.io package documentation</title>
7
</head>
8
<body>
9

  
10
	<p>WMTS provider</p>
11

  
12
</body>
13
</html>
0 14

  
org.gvsig.raster.wmts/tags/buildNumber_20/org.gvsig.raster.wmts/org.gvsig.raster.wmts.io/src/main/java/org/gvsig/raster/wmts/io/WMTSServerExplorer.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
/*
24
* AUTHORS (In addition to CIT):
25
* 2009 IVER T.I   {{Task}}
26
*/
27

  
28
package org.gvsig.raster.wmts.io;
29

  
30
import java.io.IOException;
31
import java.net.URL;
32
import java.util.ArrayList;
33
import java.util.List;
34

  
35
import org.gvsig.compat.net.ICancellable;
36
import org.gvsig.fmap.dal.DALLocator;
37
import org.gvsig.fmap.dal.DataManager;
38
import org.gvsig.fmap.dal.DataServerExplorer;
39
import org.gvsig.fmap.dal.DataServerExplorerParameters;
40
import org.gvsig.fmap.dal.DataStoreParameters;
41
import org.gvsig.fmap.dal.NewDataStoreParameters;
42
import org.gvsig.fmap.dal.coverage.store.parameter.TileDataParameters;
43
import org.gvsig.fmap.dal.exception.DataException;
44
import org.gvsig.fmap.dal.exception.InitializeException;
45
import org.gvsig.fmap.dal.exception.ProviderNotRegisteredException;
46
import org.gvsig.fmap.dal.spi.DataServerExplorerProvider;
47
import org.gvsig.fmap.dal.spi.DataServerExplorerProviderServices;
48
import org.gvsig.remoteclient.wmts.exception.WMTSException;
49
import org.gvsig.remoteclient.wmts.struct.WMTSLayer;
50
import org.gvsig.remoteclient.wmts.struct.WMTSServiceIdentification;
51
import org.gvsig.remoteclient.wmts.struct.WMTSServiceProvider;
52
import org.gvsig.remoteclient.wmts.struct.WMTSThemes;
53
import org.gvsig.remoteclient.wmts.struct.WMTSTileMatrixSet;
54

  
55
/**
56
 * Explorer for a WMTS server
57
 * @author Nacho Brodin (nachobrodin@gmail.com)
58
 */
59
public class WMTSServerExplorer implements DataServerExplorer, DataServerExplorerProvider {
60
	public static final String           NAME                     = "WMTSRemoteServerExplorer";
61
	private WMTSConnector                connector                = null;
62
	private WMTSServerExplorerParameters parameters               = null;
63
	
64
	public WMTSServerExplorer(
65
			WMTSServerExplorerParameters parameters,
66
			DataServerExplorerProviderServices services)
67
			throws InitializeException {
68
		this.parameters = parameters;
69
	}
70
	
71
	/*
72
	 * (non-Javadoc)
73
	 * @see org.gvsig.fmap.dal.coverage.store.remote.RemoteServerExplorerProvider#getDataStoreProviderName()
74
	 */
75
	public String getDataStoreProviderName() {
76
		return WMTSProvider.NAME;
77
	}
78
	
79
	/*
80
	 * (non-Javadoc)
81
	 * @see org.gvsig.fmap.dal.coverage.store.remote.RemoteServerExplorerProvider#getDescription()
82
	 */
83
	public String getDescription() {
84
		return WMTSProvider.DESCRIPTION;
85
	}
86
	
87
	/*
88
	 * (non-Javadoc)
89
	 * @see org.gvsig.fmap.dal.coverage.explorer.WMTSServerExplorer#getStoreParameters()
90
	 */
91
	public DataStoreParameters getStoreParameters() {
92
		DataManager manager = DALLocator.getDataManager();
93
		WMTSDataParameters wmtsParams = null;
94
		try {
95
			wmtsParams = (WMTSDataParameters) manager.createStoreParameters(this.getDataStoreProviderName());
96
			wmtsParams.setURI(parameters.getHost());
97

  
98
			if(WMTSProvider.TILED) {
99
				TileDataParameters tileParams = (TileDataParameters) manager.createStoreParameters("Tile Store");
100
				tileParams.setDataParameters(wmtsParams);
101
				return tileParams;
102
			} 
103
		} catch (InitializeException e) {
104
			e.printStackTrace();
105
		} catch (ProviderNotRegisteredException e) {
106
			e.printStackTrace();
107
		}
108
		return wmtsParams;
109
	}
110

  
111
	public boolean add(String provider, NewDataStoreParameters parameters,
112
			boolean overwrite) throws DataException {
113
		return false;
114
	}
115

  
116
	public boolean canAdd() {
117
		return false;
118
	}
119

  
120
	public boolean canAdd(String storeName) throws DataException {
121
		return false;
122
	}
123

  
124
	public NewDataStoreParameters getAddParameters(String storeName)
125
			throws DataException {
126
		return null;
127
	}
128

  
129
	@SuppressWarnings("unchecked")
130
	public List getDataStoreProviderNames() {
131
		return null;
132
	}
133

  
134
	/*
135
	 * (non-Javadoc)
136
	 * @see org.gvsig.fmap.dal.DataServerExplorer#getParameters()
137
	 */
138
	public DataServerExplorerParameters getParameters() {
139
		return parameters;
140
	}
141

  
142
	@SuppressWarnings("unchecked")
143
	public List list() throws DataException {
144
		return null;
145
	}
146

  
147
	@SuppressWarnings("unchecked")
148
	public List list(int mode) throws DataException {
149
		return null;
150
	}
151

  
152
	public void remove(DataStoreParameters parameters) throws DataException {
153
		
154
	}
155

  
156
	public void dispose() {
157
		
158
	}
159

  
160
	public String getProviderName() {
161
		return null;
162
	}
163

  
164
	//**********************************************
165
	//Connector
166
	//**********************************************
167
	
168
	/*
169
	 * (non-Javadoc)
170
	 * @see org.gvsig.fmap.dal.coverage.explorer.WMTSServerExplorer#connect(org.gvsig.compat.net.ICancellable)
171
	 */
172
	public void connect(ICancellable cancellable) throws WMTSException {
173
		URL url = null;
174
		boolean override = false;
175
		
176
		try {
177
			url = new URL(parameters.getHost());
178
		} catch (Exception e) {
179
			throw new WMTSException("Malformed URL",e);
180
		}
181
        try {
182
        	connector = new WMTSConnector(url);
183
        	connector.setForceLongitudeFirstAxisOrder(parameters.isLongitudeFirst());
184
        	if (!connector.connect(override, cancellable))
185
        		throw new WMTSException("Error connecting");
186
        } catch (IOException e) {
187
			throw new WMTSException(e.getMessage(), e);
188
		}
189
	}
190

  
191
	/*
192
	 * (non-Javadoc)
193
	 * @see org.gvsig.fmap.dal.coverage.explorer.WMTSServerExplorer#isConnected()
194
	 */
195
	public boolean isConnected() {
196
		if(connector != null)
197
			return true;
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff