Revision 4250

View differences:

org.gvsig.raster.tilecache/tags/org.gvsig.raster.tilecache-2.2.14/org.gvsig.raster.tilecache.io/package.info
1
#
2
#Thu Mar 07 10:25:56 CET 2013
3
owner=gvSIG Association
4
code=org.gvsig.raster.tilecache.io
5
java-version=j1_5
6
official=true
7
type=plugin
8
version=2.0.0-0
9
state=devel
10
operating-system=all
11
dependencies=
12
sources-url=https\://devel.gvsig.org/redmine/projects/gvsig-raster/repository/show/org.gvsig.raster.tilecache/tags/2.0.0/org.gvsig.raster.tilecache.io
13
web-url=http\://www.gvsig.com
14
architecture=all
15
model-version=1.0.1
16
categories=
17
description=cache service for gvSIG
18
buildNumber=0
19
gvSIG-version=2.0.0
20
name=org.gvsig.raster.tilecache.io
org.gvsig.raster.tilecache/tags/org.gvsig.raster.tilecache-2.2.14/org.gvsig.raster.tilecache.io/src/main/java/org/gvsig/raster/tilecache/io/tff/TileFileFormatExplorerParameters.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.tilecache.io.tff;
29

  
30
import org.gvsig.fmap.dal.DataServerExplorerParameters;
31
import org.gvsig.fmap.dal.spi.AbstractDataParameters;
32
import org.gvsig.tools.ToolsLocator;
33
import org.gvsig.tools.dynobject.DelegatedDynObject;
34
import org.gvsig.tools.dynobject.DynClass;
35
import org.gvsig.tools.dynobject.DynObjectManager;
36

  
37
/**
38
 * Parameters for the TileFileFormat explorer provider
39
 * @author Nacho Brodin (nachobrodin@gmail.com)
40
 */
41
public class TileFileFormatExplorerParameters extends AbstractDataParameters implements DataServerExplorerParameters {
42
	public static final String     DYNCLASS_NAME       = "TileFileFormatExplorerParameters";
43
	protected static DynClass      DYNCLASS            = null;
44
	private DelegatedDynObject     delegatedDynObject  = null;
45
	
46
	
47
	public TileFileFormatExplorerParameters() {
48
		super();
49
		initialize();
50
	}
51

  
52
	protected void initialize() {
53
		this.delegatedDynObject = (DelegatedDynObject) ToolsLocator
54
				.getDynObjectManager().createDynObject(
55
						DYNCLASS);
56
	}
57
	
58
	public static void registerDynClass() {
59
		DynObjectManager dynman = ToolsLocator.getDynObjectManager();
60
		DynClass dynClass;
61
		
62
		if(dynman == null)
63
			return;
64
		
65
		if (DYNCLASS == null) {
66
			dynClass = dynman.add(DYNCLASS_NAME);
67

  
68
			DYNCLASS = dynClass;
69
		}
70

  
71
	}
72
	
73
	protected DelegatedDynObject getDelegatedDynObject() {
74
		return delegatedDynObject;
75
	}
76

  
77
	public String getDataStoreName() {
78
		return TileFileFormatProvider.NAME;
79
	}
80
	
81
	public String getDescription() {
82
		return TileFileFormatProvider.DESCRIPTION;
83
	}
84
	
85
	public String getExplorerName() {
86
		return TileFileFormatProvider.NAME;
87
	}
88
}
0 89

  
org.gvsig.raster.tilecache/tags/org.gvsig.raster.tilecache-2.2.14/org.gvsig.raster.tilecache.io/src/main/java/org/gvsig/raster/tilecache/io/tff/TileFileFormatProvider.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.tilecache.io.tff;
23

  
24
import java.awt.geom.Point2D;
25
import java.io.File;
26

  
27
import org.gvsig.fmap.dal.DALFileLocator;
28
import org.gvsig.fmap.dal.DALLocator;
29
import org.gvsig.fmap.dal.DataStore;
30
import org.gvsig.fmap.dal.coverage.RasterLocator;
31
import org.gvsig.fmap.dal.coverage.datastruct.Extent;
32
import org.gvsig.fmap.dal.coverage.exception.BandAccessException;
33
import org.gvsig.fmap.dal.coverage.exception.FileNotOpenException;
34
import org.gvsig.fmap.dal.coverage.exception.InvalidSetViewException;
35
import org.gvsig.fmap.dal.coverage.exception.InvalidSourceException;
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.exception.InitializeException;
41
import org.gvsig.fmap.dal.exception.OpenException;
42
import org.gvsig.fmap.dal.spi.DataManagerProviderServices;
43
import org.gvsig.fmap.dal.spi.DataStoreProviderServices;
44
import org.gvsig.metadata.MetadataLocator;
45
import org.gvsig.raster.cache.tile.Tile;
46
import org.gvsig.raster.cache.tile.exception.TileGettingException;
47
import org.gvsig.raster.cache.tile.provider.TileServer;
48
import org.gvsig.raster.impl.buffer.SpiRasterQuery;
49
import org.gvsig.raster.impl.provider.AbstractRasterProvider;
50
import org.gvsig.raster.impl.provider.RasterProvider;
51
import org.gvsig.raster.impl.provider.TiledRasterProvider;
52
import org.gvsig.raster.impl.store.DefaultStoreFactory;
53
import org.gvsig.tools.ToolsLocator;
54
import org.gvsig.tools.extensionpoint.ExtensionPoint;
55
import org.gvsig.tools.extensionpoint.ExtensionPointManager;
56

  
57
import org.slf4j.Logger;
58
import org.slf4j.LoggerFactory;
59

  
60
/**
61
 * Provider for <code>TileFileFormat</code>
62
 *
63
 * @author Nacho Brodin (nachobrodin@gmail.com)
64
 */
65
public class TileFileFormatProvider extends AbstractRasterProvider implements TiledRasterProvider {
66
	public static String                NAME                     = "TileFileFormat Store";
67
	public static String                DESCRIPTION              = "Tile file format Source";
68
	public static final String          METADATA_DEFINITION_NAME = "TileFileFormatStore";
69
	private static final Logger         logger                   = LoggerFactory.getLogger(TileFileFormatProvider.class);
70
	protected static String[]           formatList               = null;
71
	private boolean                     open                     = false;
72

  
73
	public static void register() {
74
		ExtensionPointManager extensionPoints = ToolsLocator.getExtensionPointManager();
75
		registerFormats();
76

  
77
		ExtensionPoint point = extensionPoints.get("DefaultRasterProvider");
78
		point.append("reader", TileFileFormatProvider.NAME, TileFileFormatProvider.class);
79

  
80
		DataManagerProviderServices dataman = (DataManagerProviderServices) DALLocator.getDataManager();
81
		if (dataman != null && !dataman.getStoreProviders().contains(NAME)) {
82
			dataman.registerStoreProvider(NAME,
83
					TileFileFormatProvider.class, TileFileFormatDataParameters.class);
84
		}
85

  
86
		if(DALFileLocator.getFilesystemServerExplorerManager() != null)
87
			DALFileLocator.getFilesystemServerExplorerManager().registerProvider(
88
					NAME, DESCRIPTION,
89
					TileFileFormatFilesystemServerExplorer.class);
90

  
91
		dataman.registerStoreFactory(NAME, DefaultStoreFactory.class);
92
	}
93

  
94
	private static void registerFormats() {
95
		formatList      = new String[] {"tff"};
96
		for (int i = 0; i < formatList.length; i++)
97
			RasterLocator.getManager().getProviderServices().addFormat(formatList[i], TileFileFormatProvider.class);
98
	}
99

  
100
	public String[] getFormatList() {
101
		return formatList;
102
	}
103

  
104
	public boolean isExtensionSupported(String ext) {
105
		if(ext.indexOf(".") != -1)
106
			ext = ext.substring(ext.lastIndexOf(".") + 1, ext.length());
107
		for (int i = 0; i < formatList.length; i++) {
108
			if(formatList[i].compareTo(ext) == 0)
109
				return true;
110
		}
111
		return false;
112
	}
113

  
114
	public TileFileFormatProvider() throws NotSupportedExtensionException {
115
		super();
116
	}
117

  
118
	public TileFileFormatProvider(TileFileFormatDataParameters params,
119
			DataStoreProviderServices storeServices) throws InitializeException {
120
		super(params, storeServices, ToolsLocator.getDynObjectManager()
121
				.createDynObject(
122
						MetadataLocator.getMetadataManager().getDefinition(
123
								DataStore.METADATA_DEFINITION_NAME)));
124
		try {
125
			init(params, storeServices);
126
		} catch (OpenException e) {
127
			throw new InitializeException("Error open the source", e);
128
		} catch (NotSupportedExtensionException e) {
129
			throw new InitializeException("Not supported extension", e);
130
		}
131
	}
132

  
133
	/**
134
	 * Build file references
135
	 * @param proj Projection
136
	 * @param param Load parameters
137
	 * @throws NotSupportedExtensionException
138
	 */
139
	public void init(TileFileFormatDataParameters params,
140
			DataStoreProviderServices storeServices) throws NotSupportedExtensionException, OpenException {
141

  
142
		openFromTff();
143

  
144
		uri = getParameters().getURI();
145

  
146
		super.init();
147

  
148
		try {
149
			loadFromRmf(getRmfBlocksManager());
150
		} catch (ParsingException e) {
151
			logger.debug("Problems reading from RMF", e);
152
		}
153

  
154
		open = true;
155
	}
156

  
157
	/**
158
	 * Open from a .mff file.
159
	 * This method loads all providers and adds these to the parameters
160
	 * @throws OpenException
161
	 */
162
	private void openFromTff() throws OpenException {
163

  
164
	}
165

  
166
	public TileFileFormatDataParameters getParameters() {
167
		try {
168
			return (TileFileFormatDataParameters)parameters;
169
		} catch (ClassCastException e) {
170
			return null;
171
		}
172
	}
173

  
174
	@Override
175
	public int getBlockSize() {
176
		return 0;
177
	}
178

  
179
	@Override
180
	public Object getData(int x, int y, int band)
181
			throws InvalidSetViewException, FileNotOpenException,
182
			RasterDriverException {
183
		return null;
184
	}
185

  
186
	@Override
187
	public double getHeight() {
188
		return 0;
189
	}
190

  
191
	@Override
192
	public int getOverviewHeight(int band, int overview)
193
			throws BandAccessException, RasterDriverException {
194
		return 0;
195
	}
196

  
197
	@Override
198
	public int getOverviewWidth(int band, int overview)
199
			throws BandAccessException, RasterDriverException {
200
		return 0;
201
	}
202

  
203
	@Override
204
	public Extent getView() {
205
		return null;
206
	}
207

  
208
	@Override
209
	public double getWidth() {
210
		return 0;
211
	}
212

  
213
	@Override
214
	public boolean isOverviewsSupported() {
215
		return false;
216
	}
217

  
218
	@Override
219
	public RasterProvider load() {
220
		return null;
221
	}
222

  
223
	@Override
224
	public void setView(Extent e) {
225

  
226
	}
227

  
228
	public Extent getCoordsInLevel(Point2D viewCenter, int level, int w, int h) {
229
		return null;
230
	}
231

  
232
	public Extent getCoordsInTheNearestLevel(Extent extent, int w, int h) {
233
		return null;
234
	}
235

  
236
	public RasterProvider getInternalProvider() {
237
		return null;
238
	}
239

  
240
	public int getNearestLevel(double pixelSize) {
241
		return 0;
242
	}
243

  
244
	public Tile getTile(SpiRasterQuery q) throws TileGettingException {
245
		return null;
246
	}
247

  
248
	public int getZoomLevels() {
249
		return 0;
250
	}
251

  
252
	public int getOverviewCount(int band) throws BandAccessException,
253
			RasterDriverException {
254
		return 0;
255
	}
256

  
257
	public TileServer getTileServer() {
258
		return null;
259
	}
260

  
261
	public boolean isOpen() {
262
		return open;
263
	}
264

  
265
	public Object readBlock(int pos, int blockHeight, double scale)
266
			throws InvalidSetViewException, FileNotOpenException,
267
			RasterDriverException, ProcessInterruptedException {
268
		return null;
269
	}
270

  
271
	public void setStatus(RasterProvider provider) {
272

  
273
	}
274

  
275
	public String getProviderName() {
276
		return NAME;
277
	}
278

  
279
	@Override
280
	public void loadBuffer(SpiRasterQuery query)
281
			throws ProcessInterruptedException, RasterDriverException {
282
		// TODO Auto-generated method stub
283

  
284
	}
285

  
286
    /* (non-Javadoc)
287
     * @see org.gvsig.raster.impl.provider.RasterProvider#addFile(java.io.File)
288
     */
289
    @Override
290
    public void addFile(File file) throws InvalidSourceException {
291
        //Do nothing
292
    }
293

  
294
    /* (non-Javadoc)
295
     * @see org.gvsig.raster.impl.provider.RasterProvider#removeFile(java.io.File)
296
     */
297
    @Override
298
    public void removeFile(File file) {
299
        //Do nothing
300
    }
301

  
302
}
0 303

  
org.gvsig.raster.tilecache/tags/org.gvsig.raster.tilecache-2.2.14/org.gvsig.raster.tilecache.io/src/main/java/org/gvsig/raster/tilecache/io/tff/TileFileFormatNewRasterStoreParameters.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.tilecache.io.tff;
23

  
24
import org.gvsig.raster.impl.store.AbstractNewRasterStoreParameters;
25

  
26
/**
27
 * Parameters for creating a <code>TileFileFormat</code> store
28
 * @author Nacho Brodin (nachobrodin@gmail.com)
29
 */
30
public class TileFileFormatNewRasterStoreParameters extends AbstractNewRasterStoreParameters {
31

  
32
	public String getDataStoreName() {
33
		return TileFileFormatProvider.NAME;
34
	}
35

  
36
	public String getDescription() {
37
		return TileFileFormatProvider.DESCRIPTION;
38
	}
39

  
40
}
0 41

  
org.gvsig.raster.tilecache/tags/org.gvsig.raster.tilecache-2.2.14/org.gvsig.raster.tilecache.io/src/main/java/org/gvsig/raster/tilecache/io/tff/TileFileFormatFilesystemServerExplorer.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.tilecache.io.tff;
24

  
25
import java.io.File;
26
import java.util.List;
27

  
28
import org.gvsig.fmap.dal.DALLocator;
29
import org.gvsig.fmap.dal.DataManager;
30
import org.gvsig.fmap.dal.DataServerExplorer;
31
import org.gvsig.fmap.dal.DataServerExplorerParameters;
32
import org.gvsig.fmap.dal.DataStoreParameters;
33
import org.gvsig.fmap.dal.NewDataStoreParameters;
34
import org.gvsig.fmap.dal.coverage.RasterLocator;
35
import org.gvsig.fmap.dal.exception.CreateException;
36
import org.gvsig.fmap.dal.exception.DataException;
37
import org.gvsig.fmap.dal.exception.InitializeException;
38
import org.gvsig.fmap.dal.exception.ProviderNotRegisteredException;
39
import org.gvsig.fmap.dal.exception.RemoveException;
40
import org.gvsig.fmap.dal.serverexplorer.filesystem.impl.AbstractFilesystemServerExplorerProvider;
41
import org.gvsig.fmap.dal.serverexplorer.filesystem.spi.FilesystemServerExplorerProviderServices;
42
import org.gvsig.fmap.dal.spi.DataServerExplorerProviderServices;
43
import org.gvsig.raster.impl.store.AbstractRasterFileDataParameters;
44

  
45
public class TileFileFormatFilesystemServerExplorer extends AbstractFilesystemServerExplorerProvider {
46
	
47
	public TileFileFormatFilesystemServerExplorer() {
48
		
49
	}
50
	
51
	public TileFileFormatFilesystemServerExplorer(
52
			TileFileFormatExplorerParameters parameters,
53
			DataServerExplorerProviderServices services)
54
			throws InitializeException {
55
		System.out.println();
56
	}
57
	
58
	public String getDataStoreProviderName() {
59
		return TileFileFormatProvider.NAME;
60
	}
61
	
62
	public String getDescription() {
63
		return TileFileFormatProvider.DESCRIPTION;
64
	}
65
	
66
	public DataStoreParameters getStoreParameters() {
67
		DataManager manager = DALLocator.getDataManager();
68
		try {
69
			return  manager.createStoreParameters(this.getDataStoreProviderName());
70
		} catch (InitializeException e) {
71
			e.printStackTrace();
72
		} catch (ProviderNotRegisteredException e) {
73
			e.printStackTrace();
74
		}
75
		return null;
76
	}
77

  
78
	@SuppressWarnings("unchecked")
79
	public List getDataStoreProviderNames() {
80
		return null;
81
	}
82

  
83
	public String getProviderName() {
84
		return TileFileFormatProvider.NAME;
85
	}
86

  
87
	public DataServerExplorerProviderServices getServerExplorerProviderServices() {
88
		return null;
89
	}
90

  
91
	public boolean canCreate() {
92
		return false;
93
	}
94

  
95
	public boolean canCreate(NewDataStoreParameters parameters) {
96
		return false;
97
	}
98

  
99
	public void create(NewDataStoreParameters parameters, boolean overwrite)
100
			throws CreateException {
101
		throw new UnsupportedOperationException();
102
	}
103

  
104
	public NewDataStoreParameters getCreateParameters() throws DataException {
105
		return null;
106
	}
107

  
108
	public void initialize(
109
			FilesystemServerExplorerProviderServices serverExplorer) {
110
	}
111

  
112
	public boolean accept(File pathname) {
113
		return RasterLocator.getManager().getProviderServices().isExtensionSupported(
114
				pathname.getAbsolutePath(), 
115
				TileFileFormatProvider.class);
116
	}
117

  
118
	public void remove(DataStoreParameters parameters) throws RemoveException {
119
		throw new UnsupportedOperationException();
120
	}
121

  
122
	public boolean add(String provider, NewDataStoreParameters parameters,
123
			boolean overwrite) throws DataException {
124
		return false;
125
	}
126

  
127
	public boolean canAdd() {
128
		return false;
129
	}
130

  
131
	public boolean canAdd(String storeName) throws DataException {
132
		return false;
133
	}
134

  
135
	public NewDataStoreParameters getAddParameters(String storeName)
136
			throws DataException {
137
		return null;
138
	}
139
	
140
	public DataStoreParameters getParameters(File file) throws DataException {
141
		DataManager manager = DALLocator.getDataManager();
142
		AbstractRasterFileDataParameters params = (AbstractRasterFileDataParameters) manager
143
				.createStoreParameters(this.getDataStoreProviderName());
144
		params.setFile(file);
145
		return params;
146
	}
147

  
148
	public DataServerExplorerParameters getParameters() {
149
		return null;
150
	}
151

  
152
	@SuppressWarnings("unchecked")
153
	public List list() throws DataException {
154
		return null;
155
	}
156

  
157
	@SuppressWarnings("unchecked")
158
	public List list(int mode) throws DataException {
159
		return null;
160
	}
161

  
162
	public void dispose() {
163
	}
164
	
165
	public int getMode() {
166
		return DataServerExplorer.MODE_RASTER;
167
	}
168

  
169
}
0 170

  
org.gvsig.raster.tilecache/tags/org.gvsig.raster.tilecache-2.2.14/org.gvsig.raster.tilecache.io/src/main/java/org/gvsig/raster/tilecache/io/tff/TileFileFormatDataParameters.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.tilecache.io.tff;
24

  
25
import org.gvsig.raster.impl.store.AbstractRasterDataParameters;
26
import org.gvsig.raster.impl.store.AbstractRasterFileDataParameters;
27
import org.gvsig.tools.ToolsLocator;
28
import org.gvsig.tools.dynobject.DynStruct;
29
import org.gvsig.tools.persistence.PersistenceManager;
30
import org.gvsig.tools.persistence.PersistentState;
31
import org.gvsig.tools.persistence.exception.PersistenceException;
32

  
33
/**
34
 * Parameters for the <code>TileFileFormatProvider</code>
35
 * @author Nacho Brodin (nachobrodin@gmail.com)
36
 */
37
public class TileFileFormatDataParameters extends AbstractRasterFileDataParameters {
38
	 
39
	public String getDataStoreName() {
40
		return TileFileFormatProvider.NAME;
41
	}
42
	
43
	public String getDescription() {
44
		return TileFileFormatProvider.DESCRIPTION;
45
	}
46
	
47
	public void loadFromState(PersistentState state)
48
			throws PersistenceException {
49
		super.loadFromState(state);
50
	}
51

  
52
	public void saveToState(PersistentState state) throws PersistenceException {
53
		super.saveToState(state);
54
	}	
55
	
56
	public static void registerPersistence() {
57
		PersistenceManager manager = ToolsLocator.getPersistenceManager();
58
		DynStruct definition = manager.getDefinition("TileFileFormatDataParameters_Persistent");
59
		if( definition == null ) {
60
			definition = manager.addDefinition(
61
					TileFileFormatDataParameters.class,
62
					"TileFileFormatDataParameters_Persistent",
63
					"TileFileFormatDataParameters Persistent",
64
					null, 
65
					null
66
			);
67
			AbstractRasterDataParameters.registerDynClass(definition);
68
		}
69
	}
70
}
0 71

  
org.gvsig.raster.tilecache/tags/org.gvsig.raster.tilecache-2.2.14/org.gvsig.raster.tilecache.io/src/main/java/org/gvsig/raster/tilecache/io/DefaultCacheIOLibrary.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.tilecache.io;
23

  
24
import org.gvsig.raster.cache.tile.impl.TileCacheDefaultImplLibrary;
25
import org.gvsig.tools.library.AbstractLibrary;
26
import org.gvsig.tools.library.LibraryException;
27

  
28
/**
29
 *
30
 * @author Nacho Brodin (nachobrodin@gmail.com)
31
 */
32
public class DefaultCacheIOLibrary extends AbstractLibrary {	
33

  
34
	public DefaultCacheIOLibrary() {
35
		registerAsServiceOf(TileCacheDefaultImplLibrary.class);
36
	}
37
	
38
	@Override
39
	protected void doInitialize() throws LibraryException {
40
		//RasterLibrary.wakeUp();
41
	}
42

  
43
	@Override
44
	protected void doPostInitialize() throws LibraryException {
45
		TileDataParametersImpl.registerDynClass();
46
		TileProvider.register();
47
	}
48
}
0 49

  
org.gvsig.raster.tilecache/tags/org.gvsig.raster.tilecache-2.2.14/org.gvsig.raster.tilecache.io/src/main/java/org/gvsig/raster/tilecache/io/TileServerExplorer.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.tilecache.io;
29

  
30
import java.io.File;
31
import java.io.FileInputStream;
32
import java.util.List;
33

  
34
import org.gvsig.fmap.dal.DALLocator;
35
import org.gvsig.fmap.dal.DataManager;
36
import org.gvsig.fmap.dal.DataServerExplorer;
37
import org.gvsig.fmap.dal.DataServerExplorerParameters;
38
import org.gvsig.fmap.dal.DataStoreParameters;
39
import org.gvsig.fmap.dal.NewDataStoreParameters;
40
import org.gvsig.fmap.dal.coverage.RasterLocator;
41
import org.gvsig.fmap.dal.exception.CreateException;
42
import org.gvsig.fmap.dal.exception.DataException;
43
import org.gvsig.fmap.dal.exception.InitializeException;
44
import org.gvsig.fmap.dal.exception.RemoveException;
45
import org.gvsig.fmap.dal.serverexplorer.filesystem.impl.AbstractFilesystemServerExplorerProvider;
46
import org.gvsig.fmap.dal.serverexplorer.filesystem.spi.FilesystemServerExplorerProviderServices;
47
import org.gvsig.fmap.dal.spi.DataServerExplorerProvider;
48
import org.gvsig.fmap.dal.spi.DataServerExplorerProviderServices;
49
import org.gvsig.raster.impl.store.AbstractRasterFileDataParameters;
50

  
51
public class TileServerExplorer extends AbstractFilesystemServerExplorerProvider implements DataServerExplorerProvider {
52
	public static final String               NAME                     = "TileServerExplorer";
53
	
54
	public TileServerExplorer() {
55
		
56
	}
57
	
58
	public TileServerExplorer(
59
			TileServerExplorerParameters parameters,
60
			DataServerExplorerProviderServices services)
61
			throws InitializeException {
62
	}
63
	
64
	public boolean canCreate() {
65
		return false;
66
	}
67

  
68
	public boolean canCreate(NewDataStoreParameters parameters) {
69
		return false;
70
	}
71

  
72
	public void create(NewDataStoreParameters parameters, boolean overwrite)
73
			throws CreateException {
74
		throw new UnsupportedOperationException();
75
	}
76

  
77
	public NewDataStoreParameters getCreateParameters() throws DataException {
78
		return null;
79
	}
80

  
81
	public void initialize(
82
			FilesystemServerExplorerProviderServices serverExplorer) {
83
	}
84
	
85
	public void remove(DataStoreParameters parameters) throws RemoveException {
86
		throw new UnsupportedOperationException();
87
	}
88

  
89
	public String getDataStoreProviderName() {
90
		return TileProvider.NAME;
91
	}
92

  
93
	/**
94
	 * When the source is a file then this method will check if exists a 
95
	 * provider that can manage it
96
	 */
97
	public boolean accept(File pathname) {
98
		if (pathname.getParentFile() != null && 
99
				pathname.getParentFile().getName().equals("cellhd")) {
100
			if (pathname.getName().endsWith(".rmf")
101
					|| pathname.getName().endsWith(".rmf~")) {
102
				return false;
103
			}
104
			return true;
105
		}
106

  
107
		// Comprobamos que no sea un rmf propio, osea, que contenga xml
108
		if (pathname.getName().toLowerCase().endsWith(".rmf")) {
109
			FileInputStream reader = null;
110
			try {
111
				reader = new FileInputStream(pathname);
112
				String xml = "";
113
				for (int i = 0; i < 6; i++) {
114
					xml += (char) reader.read();
115
				}
116
				if (xml.equals("<?xml ")) {
117
					return false;
118
				}
119
			} catch (Exception e) {
120
			} finally {
121
				try {
122
					reader.close();
123
				} catch (Exception e) {
124
				}
125
			}
126
		}
127

  
128
		//The formats will be registered if it hasn't been done yet
129
		RasterLocator.getManager().getProviderServices().registerTileProviderFormats(TileProvider.class);
130
		
131
		return RasterLocator.getManager().getProviderServices().isExtensionSupported(
132
				pathname.getName(), 
133
				TileProvider.class);
134
	}
135

  
136
	public String getDescription() {
137
		return TileProvider.DESCRIPTION;
138
	}
139

  
140
	public DataStoreParameters getParameters(File file) throws DataException {
141
		DataManager manager = DALLocator.getDataManager();
142
		AbstractRasterFileDataParameters params = (AbstractRasterFileDataParameters) manager
143
				.createStoreParameters(this.getDataStoreProviderName());
144
		params.setFile(file);
145
		return params;
146
	}
147
	
148
	public DataServerExplorerParameters getParameters() {
149
		return null;
150
	}
151
	
152
	public int getMode() {
153
		return DataServerExplorer.MODE_RASTER;
154
	}
155

  
156
	public DataServerExplorerProviderServices getServerExplorerProviderServices() {
157
		return null;
158
	}
159

  
160
	public boolean add(String provider, NewDataStoreParameters parameters,
161
			boolean overwrite) throws DataException {
162
		return false;
163
	}
164

  
165
	public boolean canAdd() {
166
		return false;
167
	}
168

  
169
	public boolean canAdd(String storeName) throws DataException {
170
		return false;
171
	}
172

  
173
	public NewDataStoreParameters getAddParameters(String storeName)
174
			throws DataException {
175
		return null;
176
	}
177

  
178
	@SuppressWarnings("unchecked")
179
	public List getDataStoreProviderNames() {
180
		return null;
181
	}
182

  
183
	public String getProviderName() {
184
		return null;
185
	}
186

  
187
	@SuppressWarnings("unchecked")
188
	public List list() throws DataException {
189
		return null;
190
	}
191

  
192
	@SuppressWarnings("unchecked")
193
	public List list(int mode) throws DataException {
194
		return null;
195
	}
196

  
197
	public void dispose() {
198
		
199
	}
200

  
201
}
0 202

  
org.gvsig.raster.tilecache/tags/org.gvsig.raster.tilecache-2.2.14/org.gvsig.raster.tilecache.io/src/main/java/org/gvsig/raster/tilecache/io/TileProvider.java
1
package org.gvsig.raster.tilecache.io;
2

  
3
import java.awt.Image;
4
import java.awt.geom.AffineTransform;
5
import java.awt.geom.NoninvertibleTransformException;
6
import java.awt.geom.Point2D;
7
import java.io.File;
8
import java.io.FileNotFoundException;
9
import java.io.IOException;
10
import java.lang.reflect.Constructor;
11
import java.lang.reflect.InvocationTargetException;
12
import java.net.URI;
13
import java.util.List;
14

  
15
import org.gvsig.compat.net.ICancellable;
16
import org.gvsig.fmap.dal.DALLocator;
17
import org.gvsig.fmap.dal.DataStore;
18
import org.gvsig.fmap.dal.DataStoreParameters;
19
import org.gvsig.fmap.dal.coverage.RasterLibrary;
20
import org.gvsig.fmap.dal.coverage.RasterLocator;
21
import org.gvsig.fmap.dal.coverage.dataset.Buffer;
22
import org.gvsig.fmap.dal.coverage.datastruct.BandList;
23
import org.gvsig.fmap.dal.coverage.datastruct.DatasetBand;
24
import org.gvsig.fmap.dal.coverage.datastruct.Extent;
25
import org.gvsig.fmap.dal.coverage.exception.BandAccessException;
26
import org.gvsig.fmap.dal.coverage.exception.BandNotFoundInListException;
27
import org.gvsig.fmap.dal.coverage.exception.FileNotOpenException;
28
import org.gvsig.fmap.dal.coverage.exception.FileNotSupportedException;
29
import org.gvsig.fmap.dal.coverage.exception.InfoByPointException;
30
import org.gvsig.fmap.dal.coverage.exception.InvalidSetViewException;
31
import org.gvsig.fmap.dal.coverage.exception.InvalidSourceException;
32
import org.gvsig.fmap.dal.coverage.exception.NotSupportedExtensionException;
33
import org.gvsig.fmap.dal.coverage.exception.ParsingException;
34
import org.gvsig.fmap.dal.coverage.exception.ProcessInterruptedException;
35
import org.gvsig.fmap.dal.coverage.exception.QueryException;
36
import org.gvsig.fmap.dal.coverage.exception.RasterDriverException;
37
import org.gvsig.fmap.dal.coverage.exception.RmfSerializerException;
38
import org.gvsig.fmap.dal.coverage.store.RasterQuery;
39
import org.gvsig.fmap.dal.coverage.store.parameter.MultiDimensionalStoreParameters;
40
import org.gvsig.fmap.dal.coverage.store.parameter.RasterDataParameters;
41
import org.gvsig.fmap.dal.coverage.store.parameter.RemoteStoreParameters;
42
import org.gvsig.fmap.dal.coverage.store.parameter.TileDataParameters;
43
import org.gvsig.fmap.dal.coverage.store.props.ColorInterpretation;
44
import org.gvsig.fmap.dal.coverage.store.props.ColorTable;
45
import org.gvsig.fmap.dal.coverage.util.MathUtils;
46
import org.gvsig.fmap.dal.exception.InitializeException;
47
import org.gvsig.fmap.dal.exception.ProviderNotRegisteredException;
48
import org.gvsig.fmap.dal.exception.ValidateDataParametersException;
49
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemServerExplorer;
50
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemServerExplorerParameters;
51
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemStoreParameters;
52
import org.gvsig.fmap.dal.spi.DataManagerProviderServices;
53
import org.gvsig.fmap.dal.spi.DataStoreProvider;
54
import org.gvsig.fmap.dal.spi.DataStoreProviderServices;
55
import org.gvsig.metadata.MetadataLocator;
56
import org.gvsig.raster.cache.tile.Tile;
57
import org.gvsig.raster.cache.tile.TileCache;
58
import org.gvsig.raster.cache.tile.TileCacheLibrary;
59
import org.gvsig.raster.cache.tile.TileCacheLocator;
60
import org.gvsig.raster.cache.tile.TileCacheManager;
61
import org.gvsig.raster.cache.tile.exception.TileBuildException;
62
import org.gvsig.raster.cache.tile.exception.TileGettingException;
63
import org.gvsig.raster.cache.tile.layer.TiledLayer;
64
import org.gvsig.raster.cache.tile.provider.CacheStruct;
65
import org.gvsig.raster.cache.tile.provider.TileServer;
66
import org.gvsig.raster.impl.buffer.SpiRasterQuery;
67
import org.gvsig.raster.impl.datastruct.BandListImpl;
68
import org.gvsig.raster.impl.datastruct.DatasetBandImpl;
69
import org.gvsig.raster.impl.datastruct.ExtentImpl;
70
import org.gvsig.raster.impl.provider.AbstractRasterProvider;
71
import org.gvsig.raster.impl.provider.MemoryTileMatrixBuffer;
72
import org.gvsig.raster.impl.provider.RasterProvider;
73
import org.gvsig.raster.impl.provider.RemoteRasterProvider;
74
import org.gvsig.raster.impl.provider.TiledRasterProvider;
75
import org.gvsig.raster.impl.store.DefaultRasterStore;
76
import org.gvsig.raster.impl.store.DefaultStoreFactory;
77
import org.gvsig.raster.impl.store.properties.DataStoreColorInterpretation;
78
import org.gvsig.raster.impl.store.properties.DataStoreTransparency;
79
import org.gvsig.raster.impl.store.properties.RemoteDataStoreStatistics;
80
import org.gvsig.tools.ToolsLocator;
81
import org.gvsig.tools.locator.LocatorException;
82

  
83
import org.slf4j.Logger;
84
import org.slf4j.LoggerFactory;
85

  
86
/**
87
 * Provider for WMTS service
88
 *
89
 * @author Nacho Brodin (nachobrodin@gmail.com)
90
 */
91
public class TileProvider extends AbstractRasterProvider implements TiledRasterProvider {
92
	public static String                NAME                     = "Tile Store";
93
	public static String                DESCRIPTION              = "Raster Tiled Source";
94
	public static final String          METADATA_DEFINITION_NAME = "TileStore";
95
	private static final Logger         logger                   = LoggerFactory.getLogger(TileProvider.class);
96
	private RasterProvider              provider                 = null;
97
	private boolean                     open                     = false;
98
	private Extent                      viewRequest              = null;
99
	private TiledLayer                  tiledLayer               = null;
100
	private MathUtils                   math                     = RasterLocator.getManager().getMathUtils();
101
	private TileServer                  secondLevelTileServer    = null;
102

  
103
	public static void register() {
104
		DataManagerProviderServices dataman = (DataManagerProviderServices) DALLocator.getDataManager();
105
		if (dataman != null && !dataman.getStoreProviders().contains(NAME)) {
106
			dataman.registerStoreProvider(NAME,
107
					TileProvider.class, TileDataParametersImpl.class);
108
		}
109

  
110
		/*if(DALFileLocator.getFilesystemServerExplorerManager() != null)
111
			DALFileLocator.getFilesystemServerExplorerManager().registerProvider(
112
					NAME, DESCRIPTION,
113
					TileServerExplorer.class);*/
114

  
115
		if (!dataman.getExplorerProviders().contains(TileServerExplorer.NAME)) {
116
			dataman.registerExplorerProvider(TileServerExplorer.NAME, TileServerExplorer.class, TileServerExplorerParameters.class);
117
		}
118
		dataman.registerStoreFactory(NAME, DefaultStoreFactory.class);
119
	}
120

  
121
	/**
122
	 * Loads the specific provider to download data
123
	 * @param file
124
	 * @return
125
	 * @throws NotSupportedExtensionException
126
	 * @throws FileNotSupportedException
127
	 */
128
	@SuppressWarnings("unchecked")
129
	private RasterProvider loadProvider(TileDataParametersImpl params, DataStoreProviderServices storeServices) throws ProviderNotRegisteredException, InitializeException {
130
		Object obj = params.getDataParameters();
131
		DataManagerProviderServices dataManager = (DataManagerProviderServices)DALLocator.getDataManager();
132
		DataStoreProvider prov = null;
133

  
134
		if(obj != null && obj instanceof DataStoreParameters) //Remote
135
			prov = dataManager.createProvider(storeServices, (DataStoreParameters)obj);
136
		else { //File
137
			if(params.getFile() != null) {
138
				//We have to locate a provider's name which manages the selected file
139
				//A FilesystemServerExplorer will give a getProviderNames service
140
				FilesystemServerExplorerParameters paramsExplorer = (FilesystemServerExplorerParameters)dataManager.createServerExplorerParameters(FilesystemServerExplorer.NAME);
141
				FilesystemServerExplorer serverExplorer = null;
142
				try {
143
					paramsExplorer.setRoot(File.separator);
144
					serverExplorer = (FilesystemServerExplorer)dataManager.openServerExplorer(FilesystemServerExplorer.NAME, paramsExplorer);
145
				} catch (ValidateDataParametersException e) {
146
					throw new InitializeException(e);
147
				}
148

  
149
				//Gets the list of provider's name to manage the file
150
				List<String> provName = serverExplorer.getProviderNameList(params.getFile());
151
				if(provName.size() > 0) {
152
					for (int i = 0; i < provName.size(); i++) {
153
						//Gets the first provider what is not a TileProvider
154
						if(provName.get(i).compareTo(NAME) != 0) {
155
							DataStoreParameters newparams = dataManager.createStoreParameters(provName.get(i));
156
							((FilesystemStoreParameters)newparams).setFile(params.getFile());
157
							prov = dataManager.createProvider(storeServices, newparams);
158
						}
159
					}
160
				}
161
			}
162
		}
163

  
164
		if(prov != null && prov instanceof RasterProvider) {
165
			if(((RasterProvider)prov).isRotated())
166
				throw new InitializeException("Rotation not supported tiling files", new Throwable());
167

  
168
			return (RasterProvider)prov;
169
		}
170

  
171
		return null;
172
	}
173

  
174
	/**
175
	 * Gets the internal provider used to feed the TileProvider
176
	 * @return
177
	 */
178
	public RasterProvider getInternalProvider() {
179
		return provider;
180
	}
181

  
182
	public Image getImageLegend() {
183
		return provider.getImageLegend();
184
	}
185

  
186
	public ColorInterpretation getColorInterpretation() {
187
		return provider.getColorInterpretation();
188
	}
189

  
190
	public String getFileSuffix() {
191
		try {
192
			return provider instanceof RemoteRasterProvider ? provider.getFileSuffix() : "tif";
193
		} catch(Throwable e) {
194
			//if wmts doesn't exists in the classpath
195
			return "tif";
196
		}
197
	}
198

  
199
	public File getRMFFile() {
200
		TileCacheManager  manager = TileCacheLocator.getManager();
201
		TileCache tileCache = manager.getTileCache(RasterLibrary.pathTileCache);
202

  
203
		String metadataDir = tiledLayer.getBaseLayerDirectory().substring(0, tiledLayer.getBaseLayerDirectory().lastIndexOf(File.separator) + 1) +
204
				  			tileCache.getConfigurationDirectory();
205

  
206
		File metadaDirFile = new File(metadataDir);
207
		if(!metadaDirFile.exists())
208
			metadaDirFile.mkdir();
209

  
210
		String path = metadataDir + File.separator + tiledLayer.getID() + ".rmf";
211

  
212
		try {
213
            if (!new File(path).exists() && provider != null && provider.getRMFFile() != null
214
                && provider.getRMFFile().exists()) {
215
                RasterLocator.getManager().getFileUtils().copyFile(provider.getRMFFile().getAbsolutePath(), path);
216
            }
217

  
218
			if(provider != null && provider.getColorTable() != null) {
219
				ColorTable colorTable = provider.getColorTable();
220
				RasterLocator.getManager().getProviderServices().saveObjectToRmfFile(path, ColorTable.class, colorTable);
221
			}
222
		} catch (LocatorException e) {
223
			logger.info("No se ha podido copiar el fichero RMF a la capa tileada", e);
224
		} catch (FileNotFoundException e) {
225
			logger.info("No se ha podido copiar el fichero RMF a la capa tileada", e);
226
		} catch (IOException e) {
227
			logger.info("No se ha podido copiar el fichero RMF a la capa tileada", e);
228
		} catch (RmfSerializerException e) {
229
			logger.info("No se ha podido copiar la tabla de color a la capa tileada", e);
230
		}
231
		return new File(path);
232
	}
233

  
234
	public TileProvider() throws NotSupportedExtensionException {
235
		super();
236
	}
237

  
238
	public void registerTileProviderFormats(Class<RasterProvider> c) {
239

  
240
	}
241

  
242
	/**
243
	 * Assigns the provider associated to this tile server
244
	 * @param prov
245
	 * @throws NotSupportedExtensionException
246
	 */
247
	public void setProvider(RasterProvider prov) throws InitializeException  {
248
		this.provider = prov;
249
		init(getDataStoreParameters(), getStoreServices());
250
	}
251

  
252
	public TileProvider(TileDataParametersImpl params,
253
			DataStoreProviderServices storeServices) throws InitializeException {
254
		super(params, storeServices, ToolsLocator.getDynObjectManager()
255
				.createDynObject(
256
						MetadataLocator.getMetadataManager().getDefinition(
257
								DataStore.METADATA_DEFINITION_NAME)));
258
		if(!params.isSecondLevelCache()) {
259
			try {
260
				provider = loadProvider(params, storeServices);
261
			} catch (ProviderNotRegisteredException e) {
262
				throw new InitializeException("Provider not registered", e);
263
			}
264
			init(params, storeServices);
265
			if(provider.getFileSizeByProvider() != null && provider.getFileSizeByProvider().length > 0)
266
				fileSize = provider.getFileSizeByProvider()[0];
267
		}
268
	}
269

  
270
	/**
271
	 * Creates the second level cache if the client has set a <code>TileServer</code> and the
272
	 * <code>CacheStruct</code> is different that the old one.
273
	 * <UL>
274
	 * <LI>First level cache without TileServer from the client: do nothing</LI>
275
	 * <LI>First level cache with TileServer from the client and the structure is
276
	 * different to the old one: Builds a second level TileProvider</LI>
277
	 * <LI>First level cache with TileServer from the client and the structure is
278
	 * equal to the old one: do nothing</LI>
279
	 * <LI>Second level cache: sets the TileServer</LI>
280
	 * </UL>
281
	 * @param params
282
	 * @param storeServices
283
	 * @throws NotSupportedExtensionException
284
	 */
285
	/*private void createsSecondLevelCache(TileDataParametersImpl params) throws NotSupportedExtensionException {
286
		//Se obtiene el TileServer que haya pasado el cliente en los par?metros si ha pasado alguno.
287
		TileServer tileServer = params.getTileServer();
288
		//Se obtiene el CacheStruct y se compara con el del provider
289
		CacheStruct cacheStruct = null;
290
		if(tileServer != null)
291
			cacheStruct = tileServer.getStruct();
292

  
293
		if(params.isSecondLevelCache()) { //Cache de segundo nivel
294
			this.secondLevelTileServer = tileServer;
295
		} else if(cacheStruct != null && !provider.getTileServer().getStruct().compare(cacheStruct)) { //Cache de primer nivel
296
			//Si son distintos habr? que crear una cach? de segundo nivel por lo que creamos un nuevo TileProvider
297
			//que tenga como par?metro el provider viejo
298
			TileDataParametersImpl par = new TileDataParametersImpl();
299
			par.setDataParameters(provider.getDataParameters());
300
			par.setTileServer(tileServer);
301
			par.setSecondLevelCache(true);
302
			TileProvider newProvider = new TileProvider(par, null);
303
			newProvider.setProvider(this.provider);
304
			//Al TileProvider actual se le asigna como provider el TileProvider creado
305
			this.provider = newProvider;
306
		}
307
	}*/
308

  
309
	/**
310
	 * Crea las referencias al fichero y carga
311
	 * las estructuras con la informaci?n y los metadatos.
312
	 * @param proj Proyecci?n
313
	 * @param param Parametros de carga
314
	 * @throws NotSupportedExtensionException
315
	 */
316
	public void init (DataStoreParameters params,
317
			DataStoreProviderServices storeServices) throws InitializeException  {
318
		setParam(storeServices, params);
319
		open = true;
320
		calculateDataType();
321
		calculateBandCount();
322
		calculateColorInterpretation();
323
		calculateTransparency();
324
		setColorTable(provider.getColorTable());
325
		noData = provider.getNoDataValue();
326
		uri = provider.getURIOfFirstProvider();
327
		proj = provider.getProjection();
328
		ownTransformation = provider.getAffineTransform();
329
		externalTransformation = (AffineTransform)ownTransformation.clone();
330

  
331
		createTiledLayer();
332

  
333
		//Force to deletes the layer if the flag is to true
334
		if(tiledLayer != null) {
335
			if(param instanceof TileDataParameters) {
336
				if(((TileDataParameters)param).isDeletingCache()) {
337
					TileCacheManager  manager = TileCacheLocator.getManager();
338
					TileCache tileCache = manager.getTileCache(RasterLibrary.pathTileCache);
339
					tileCache.removeLayer(tiledLayer);
340
					((TileDataParameters)param).deleteCache(false);
341
				}
342
			}
343
		}
344

  
345
		if(provider instanceof RemoteRasterProvider)
346
			stats = new RemoteDataStoreStatistics(provider);
347
	}
348

  
349
	/**
350
	 * Calculates the data type of this provider
351
	 * @return
352
	 */
353
	public void calculateDataType() {
354
		int[] datatype = null;
355
		if(provider.getDataType()[0] == Buffer.TYPE_BYTE && provider.getBandCount() == 3)
356
			datatype = new int[provider.getBandCount() + 1];
357
		else
358
			datatype = new int[provider.getBandCount()];
359
		for (int i = 0; i < provider.getDataType().length; i++) {
360
			datatype[i] = provider.getDataType()[i];
361
		}
362
		if(provider.getDataType()[0] == Buffer.TYPE_BYTE && provider.getBandCount() == 3)
363
			datatype[datatype.length - 1] = Buffer.TYPE_BYTE;
364
		setDataType(datatype);
365
	}
366

  
367
	/**
368
	 * Calculates the number of bands
369
	 */
370
	public void calculateBandCount() {
371
		bandCount = provider.getBandCount();
372
		if(provider.getDataType()[0] == Buffer.TYPE_BYTE && provider.getBandCount() == 3)
373
			bandCount ++;
374
	}
375

  
376
	/**
377
	 * Calculates the color interpretation
378
	 */
379
	public void calculateColorInterpretation() {
380
		ColorInterpretation ci = provider.getColorInterpretation();
381
		if(ci != null) {
382
			if(ci.isRGB() || ci.isBGR()) {
383
				ci = DataStoreColorInterpretation.createRGBAInterpretation();
384
			} else
385
				ci = ci.cloneColorInterpretation();
386
		} else {
387
			if(provider.getDataType()[0] == Buffer.TYPE_BYTE) {
388
				if(provider.getBandCount() == 3)
389
					ci = DataStoreColorInterpretation.createRGBAInterpretation();
390
				else
391
					ci = DataStoreColorInterpretation.createDefaultInterpretation(getBandCount());
392
			} else {
393
				if(getBandCount() == 1)
394
					ci = DataStoreColorInterpretation.createGrayInterpretation();
395
				else
396
					ci = DataStoreColorInterpretation.createDefaultInterpretation(getBandCount());
397
			}
398
		}
399

  
400
		super.setColorInterpretation(ci);
401
	}
402

  
403

  
404
	public void calculateTransparency() {
405
		if(provider.getTransparency() != null)
406
			transparency = provider.getTransparency().cloneTransparency();
407
		else
408
			transparency = new DataStoreTransparency(getColorInterpretation());
409
		if(getColorInterpretation() != null) {
410
			transparency.setColorInterpretation(getColorInterpretation());
411
			transparency.setTransparencyBand(getColorInterpretation().getAlphaBand());
412
			transparency.activeTransparency();
413
		}
414
	}
415

  
416
	/**
417
	 * Creates a new tiled layer if this hasn't been created yet or the ID has changed.
418
	 * An ID could changed because the file type has changed when the user uses WMTS properties.
419
	 */
420
	private void createTiledLayer() {
421
		TileCacheManager  manager = TileCacheLocator.getManager();
422
		TileCache tileCache = manager.getTileCache(RasterLibrary.pathTileCache);
423
		TiledLayer newLayer = tileCache.createLayer(provider.getTileServer(), TileCacheLibrary.DEFAULT_STRUCTURE);
424
		if(tiledLayer == null || newLayer.getID().compareTo(tiledLayer.getID()) != 0)
425
			tiledLayer = newLayer;
426
	}
427

  
428
	public void reload() {
429
		try {
430
			loadFromRmf(getRmfBlocksManager());
431
			calculateColorInterpretation();
432
			calculateTransparency();
433
		} catch (ParsingException e) {
434
			logger.debug("No se ha podido leer el RMF", e);
435
		}
436
	}
437

  
438
	public int getZoomLevels() {
439
		if(provider.getTileServer() != null)
440
			return provider.getTileServer().getStruct().getNumberOfLevels();
441
		return 0;
442
	}
443

  
444
	public int getNearestLevel(double pixelSize) {
445
		double[] pixelSizes = getPixelSizeByLevel();
446
		for (int i = 0; i < pixelSizes.length - 1; i++) {
447
			if(pixelSize <= pixelSizes[i] && pixelSize > pixelSizes[i + 1]) {
448
				return i;
449
			}
450
		}
451
		if(pixelSize < pixelSizes[getZoomLevels() - 1])
452
			return getZoomLevels() - 1;
453
		return 0;
454
	}
455

  
456
	/**
457
	 * Returns a list of pixel sizes by level
458
	 * @return
459
	 */
460
	public double[] getPixelSizeByLevel() {
461
		double[] list = new double[getZoomLevels()];
462
		CacheStruct struct = provider.getTileServer().getStruct();
463
		for (int i = 0; i < struct.getNumberOfLevels(); i++) {
464
			list[i] = math.adjustDouble(struct.getPixelSizeByLevel(i));
465
		}
466
		return list;
467
	}
468

  
469
	public Extent getCoordsInTheNearestLevel(Extent extent, int w, int h) {
470
		double[] pixelSizes = getPixelSizeByLevel();
471
		double currentPixelSize = extent.width() / (double)w;
472

  
473
		int level = 0;
474
		for (int i = 0; i < (pixelSizes.length - 1); i++) {
475
			if(currentPixelSize < pixelSizes[i] && currentPixelSize >= pixelSizes[i + 1]) {
476
				level = i + 1;
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff