Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.dal / org.gvsig.fmap.dal.spi / src / main / java / org / gvsig / fmap / dal / raster / spi / AbstractCoverageStoreProvider.java @ 42775

History | View | Annotate | Download (6.01 KB)

1 40559 jjdelcerro
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
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 3
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
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24 40435 jjdelcerro
package org.gvsig.fmap.dal.raster.spi;
25
26
import org.gvsig.fmap.dal.DALLocator;
27
import org.gvsig.fmap.dal.DataServerExplorer;
28
import org.gvsig.fmap.dal.DataStoreParameters;
29
import org.gvsig.fmap.dal.exception.CloseException;
30
import org.gvsig.fmap.dal.exception.DataException;
31
import org.gvsig.fmap.dal.exception.InitializeException;
32
import org.gvsig.fmap.dal.exception.OpenException;
33
import org.gvsig.fmap.dal.exception.ReadException;
34
import org.gvsig.fmap.dal.exception.ValidateDataParametersException;
35
import org.gvsig.fmap.dal.raster.CoverageSelection;
36
import org.gvsig.fmap.dal.resource.spi.ResourceManagerProviderServices;
37
import org.gvsig.fmap.dal.resource.spi.ResourceProvider;
38
import org.gvsig.fmap.dal.spi.DataStoreProviderServices;
39
import org.gvsig.fmap.geom.primitive.Envelope;
40
import org.gvsig.tools.dispose.impl.AbstractDisposable;
41
import org.gvsig.tools.dynobject.DelegatedDynObject;
42
import org.gvsig.tools.dynobject.DynClass;
43
import org.gvsig.tools.dynobject.DynObject;
44
import org.gvsig.tools.dynobject.exception.DynFieldNotFoundException;
45
import org.gvsig.tools.dynobject.exception.DynMethodException;
46
import org.gvsig.tools.exception.BaseException;
47
48
49
/**
50
 * @author jmvivo
51
 *
52
 */
53
public abstract class AbstractCoverageStoreProvider extends AbstractDisposable
54
                implements CoverageStoreProvider {
55
        protected CoverageStoreProviderServices store;
56
        protected DelegatedDynObject metadata;
57
        protected DataStoreParameters parameters;
58
59
60
        protected AbstractCoverageStoreProvider(DataStoreParameters params,
61
                        DataStoreProviderServices storeServices, DynObject metadata) {
62
                init(params, storeServices, metadata);
63
        }
64
65
        protected AbstractCoverageStoreProvider(DataStoreParameters params,
66
                        DataStoreProviderServices storeServices) {
67
                init(params, storeServices, null);
68
        }
69
70
        protected AbstractCoverageStoreProvider() {
71
        }
72
73
        protected void init(DataStoreParameters params,
74
                        DataStoreProviderServices storeServices, DynObject metadata) {
75
                this.store = (CoverageStoreProviderServices) storeServices;
76
                this.metadata = (DelegatedDynObject) metadata;
77
                this.parameters = params;
78
        }
79
80
        /**
81
         * Gets the DataStoreParameters
82
         * @return DataStoreParameters
83
         */
84
        public DataStoreParameters getDataStoreParameters() {
85
                return parameters;
86
        }
87
88
        /**
89
         * Set metada container if this not set at construction time and only in one
90
         * time. In other case an Exception will be throw
91
         *
92
         * @param metadata
93
         */
94
        protected void setMetadata(DynObject metadata) {
95
                if (this.metadata != null) {
96
                        // FIXME Exception
97
                        throw new IllegalStateException();
98
                }
99
                this.metadata = (DelegatedDynObject) metadata;
100
        }
101
102
        protected ResourceProvider createResource(String type, Object[] params)
103
                        throws InitializeException {
104
                ResourceManagerProviderServices manager = (ResourceManagerProviderServices) DALLocator
105
                                .getResourceManager();
106
                ResourceProvider resource = manager.createAddResource(type, params);
107
                return resource;
108
        }
109
110
        public CoverageStoreProviderServices getStoreServices() {
111
                return this.store;
112
        }
113
114
        public String getClassName() {
115
                return this.getClass().getName();
116
        }
117
118
        public boolean allowWrite() {
119
                return false;
120
        }
121
122
        public CoverageSelection createCoverageSelection() throws DataException {
123
                return this.store.createDefaultCoverageSelection();
124
        }
125
126
        public void refresh() throws OpenException {
127
                // Do nothing by default
128
        }
129
130
        public void close() throws CloseException {
131
                // Do nothing by default
132
        }
133
134
        protected void doDispose() throws BaseException {
135
                this.metadata = null;
136
                this.store = null;
137
                this.parameters = null;
138
        }
139
140
        public Envelope getEnvelope() throws DataException {
141
                return null;
142
        }
143
144
        public abstract DataServerExplorer getExplorer() throws ReadException,
145
                        ValidateDataParametersException;
146
147
        public void delegate(DynObject dynObject) {
148
                if (this.metadata == null) {
149
                        return;
150
                }
151
                this.metadata.delegate(dynObject);
152
        }
153
154
        public DynClass getDynClass() {
155
                if (this.metadata == null) {
156
                        return null;
157
                }
158
                return this.metadata.getDynClass();
159
        }
160
161
        public Object getDynValue(String name) throws DynFieldNotFoundException {
162
                if (this.metadata == null) {
163
                        return null;
164
                }
165
                // TODO this.open??
166
                return this.metadata.getDynValue(name);
167
        }
168
169
        public boolean hasDynValue(String name) {
170
                if (this.metadata == null) {
171
                        return false;
172
                }
173
                // TODO this.open??
174
                return this.metadata.hasDynValue(name);
175
        }
176
177
        public void implement(DynClass dynClass) {
178
                if (this.metadata == null) {
179
                        return;
180
                }
181
                this.metadata.implement(dynClass);
182
183
        }
184
185 42775 jjdelcerro
        public Object invokeDynMethod(int code, Object[] args)
186 40435 jjdelcerro
                        throws DynMethodException {
187
                if (this.metadata == null) {
188
                        return null;
189
                }
190
                // TODO this.open??
191 42775 jjdelcerro
                return this.metadata.invokeDynMethod(this, code, args);
192 40435 jjdelcerro
        }
193
194 42775 jjdelcerro
        public Object invokeDynMethod(String name, Object[] args)
195 40435 jjdelcerro
                        throws DynMethodException {
196
                if (this.metadata == null) {
197
                        return null;
198
                }
199
                // TODO this.open??
200 42775 jjdelcerro
                return this.metadata.invokeDynMethod(this, name, args);
201 40435 jjdelcerro
        }
202
203
        public void setDynValue(String name, Object value)
204
                        throws DynFieldNotFoundException {
205
                if (this.metadata == null) {
206
                        return;
207
                }
208
                // TODO this.open??
209
                this.metadata.setDynValue(name, value);
210
        }
211
212
        public void clear() {
213
                if (metadata != null) {
214
                        metadata.clear();
215
                }
216
        }
217
}