Statistics
| Revision:

gvsig-raster / org.gvsig.raster.tilecache / trunk / org.gvsig.raster.tilecache / org.gvsig.raster.tilecache.io / src / main / java / org / gvsig / raster / tilecache / io / TileDataParametersImpl.java @ 4271

History | View | Annotate | Download (6.1 KB)

1
/* gvSIG. Geographic Information System of the Valencian Government
2
*
3
* Copyright (C) 2007-2008 Infrastructures and Transports Department
4
* of the Valencian Government (CIT)
5
*
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License
8
* as published by the Free Software Foundation; either version 2
9
* of the License, or (at your option) any later version.
10
*
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
* GNU General Public License for more details.
15
*
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
* MA  02110-1301, USA.
20
*
21
*/
22

    
23
package org.gvsig.raster.tilecache.io;
24

    
25
import java.net.URI;
26

    
27
import org.gvsig.fmap.dal.DataParameters;
28
import org.gvsig.fmap.dal.coverage.store.parameter.RasterDataParameters;
29
import org.gvsig.fmap.dal.coverage.store.parameter.TileDataParameters;
30
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemStoreParameters;
31
import org.gvsig.raster.cache.tile.provider.TileServer;
32
import org.gvsig.raster.impl.store.AbstractRasterDataParameters;
33
import org.gvsig.raster.impl.store.AbstractRasterFileDataParameters;
34
import org.gvsig.tools.ToolsLocator;
35
import org.gvsig.tools.dynobject.DelegatedDynObject;
36
import org.gvsig.tools.dynobject.DynStruct;
37
import org.gvsig.tools.persistence.PersistenceManager;
38

    
39
/**
40
 * Parameters for the <code>TileProvider</code>
41
 * @author Nacho Brodin (nachobrodin@gmail.com)
42
 */
43
public class TileDataParametersImpl extends AbstractRasterFileDataParameters implements TileDataParameters {
44
        public static final String       FIELD_PARAMETERS      = "parameters";
45
        public static final String       FIELD_SECONDLEVEL     = "secondlevel";
46
        public static final String       FIELD_NAME            = "name";
47
        private static final String      FIELD_DELETECACHE     = "deletecache";
48

    
49
        private DelegatedDynObject       delegatedDynObject    = null;
50
        private TileServer               tileServer            = null;
51

    
52
        public TileDataParametersImpl() {
53
                super();
54
                initialize();
55
        }
56

    
57
        protected void initialize() {
58
                this.delegatedDynObject = (DelegatedDynObject) ToolsLocator
59
                                .getDynObjectManager().createDynObject(
60
                                                registerDynClass());
61
        }
62

    
63
        public static DynStruct registerDynClass() {
64
                PersistenceManager manager = ToolsLocator.getPersistenceManager();
65
                DynStruct definition = manager.getDefinition("TileDataParameters_Persistent");
66
                if( definition == null ) {
67
                        definition = manager.addDefinition(
68
                                        TileDataParametersImpl.class,
69
                                        "TileDataParameters_Persistent",
70
                                        "TileDataParameters Persistency",
71
                                        null,
72
                                        null
73
                                        );
74
                }
75

    
76
                AbstractRasterDataParameters.registerDynClass(definition);
77

    
78
                definition.addDynFieldObject(FIELD_PARAMETERS)
79
                .setDescription("Provider")
80
                .setClassOfValue(RasterDataParameters.class)
81
                .setMandatory(true);
82

    
83
                definition.addDynFieldBoolean(FIELD_SECONDLEVEL)
84
                .setDescription("SecondLevelProvider")
85
                .setMandatory(false);
86

    
87
                definition.addDynFieldString(FIELD_NAME)
88
                .setDescription("Name")
89
                .setMandatory(false);
90

    
91
                definition.addDynFieldBoolean(FIELD_DELETECACHE)
92
                .setDescription("Flag to delete cache the next request")
93
                .setMandatory(false);
94
                return definition;
95
        }
96

    
97
        /**
98
         * Sets the <code>DataParameters</code>
99
         * @param params
100
         */
101
        public void setDataParameters(DataParameters params) {
102
                this.setDynValue(FIELD_PARAMETERS, params);
103
        }
104

    
105
        public DataParameters getDataParameters() {
106
                return (DataParameters) this.getDynValue(FIELD_PARAMETERS);
107
        }
108

    
109
        /**
110
         * Sets the <code>TileServer</code>
111
         * @param tileServer
112
         */
113
        public void setTileServer(TileServer tileServer) {
114
                this.tileServer = tileServer;
115
        }
116

    
117
        /**
118
         * Gets the <code>TileServer</code>
119
         * @return
120
         */
121
        public TileServer getTileServer() {
122
                return tileServer;
123
        }
124

    
125
        /**
126
         * Returns true if this provider is for the second level of cach?
127
         * @return
128
         */
129
        public boolean isSecondLevelCache() {
130
                Object obj = this.getDynValue(FIELD_SECONDLEVEL);
131
                if(obj != null && obj instanceof Boolean)
132
                        return ((Boolean)obj).booleanValue();
133
                return false;
134
        }
135

    
136
        /**
137
         * Sets the flag to inform to the provider that is a second level provider
138
         * @param secondLevel
139
         */
140
        public void setSecondLevelCache(boolean secondLevel) {
141
                this.setDynValue(FIELD_SECONDLEVEL, new Boolean(secondLevel));
142
        }
143

    
144
        /**
145
         * Gets the name
146
         * @return
147
         */
148
        public String getName() {
149
                DataParameters p = getDataParameters();
150
                if(p != null) {
151
                        if(p instanceof FilesystemStoreParameters) {
152
                                return ((FilesystemStoreParameters)p).getFile().getAbsolutePath();
153
            } else {
154
                return ((RasterDataParameters) p).getURI().getPath();
155
            }
156
                }
157
                return null;
158
        }
159

    
160
        @Override
161
        public URI getURI() {
162
                if(this.getDynValue(FIELD_URI) == null) {
163
                        DataParameters p = getDataParameters();
164
                        if(p != null) {
165
                                if(p instanceof FilesystemStoreParameters) {
166
                                        return ((FilesystemStoreParameters)p).getFile().toURI();
167
                                } else {
168
                    return ((RasterDataParameters)p).getURI();
169
                                }
170
                        }
171
                }
172
                return (URI) this.getDynValue(FIELD_URI);
173
        }
174

    
175

    
176
        //**********************************************
177

    
178
        public String getDataStoreName() {
179
                return TileProvider.NAME;
180
        }
181

    
182
        public String getDescription() {
183
                return TileProvider.DESCRIPTION;
184
        }
185

    
186
        public String getExplorerName() {
187
                return TileServerExplorer.NAME;
188
        }
189

    
190
        public boolean isValid() {
191
                return (this.getDataParameters() != null);
192
        }
193

    
194
        protected DelegatedDynObject getDelegatedDynObject() {
195
                return delegatedDynObject;
196
        }
197

    
198
        /**
199
         * Sets the flag to delete the cache
200
         * @param deleteCache
201
         */
202
        public void deleteCache(boolean deleteCache) {
203
                this.setDynValue(FIELD_DELETECACHE, new Boolean(deleteCache));
204
        }
205

    
206
        /**
207
         * Returns true if the cache is going to be deleted
208
         * @return
209
         */
210
        public boolean isDeletingCache() {
211
                Boolean b = (Boolean)getDynValue(FIELD_DELETECACHE);
212
                if(b != null)
213
                        return ((Boolean)getDynValue(FIELD_DELETECACHE)).booleanValue();
214
                else
215
                        return false;
216
        }
217

    
218
        public boolean isSourceTiled() {
219
                return true;
220
        }
221
}