Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.dal / org.gvsig.fmap.dal.api / src / main / java / org / gvsig / fmap / dal / feature / AbstractFeatureStoreTransform.java @ 47778

History | View | Annotate | Download (6.05 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.feature;
25
26
import java.util.ArrayList;
27 46875 fdiaz
import java.util.HashMap;
28 40435 jjdelcerro
import java.util.List;
29 46875 fdiaz
import java.util.Map;
30 43215 jjdelcerro
import org.apache.commons.lang3.StringUtils;
31 46875 fdiaz
import org.gvsig.fmap.dal.DataStore;
32 40435 jjdelcerro
33
import org.gvsig.fmap.dal.exception.DataException;
34
import org.gvsig.tools.ToolsLocator;
35
import org.gvsig.tools.dynobject.DynObject;
36
import org.gvsig.tools.dynobject.DynStruct;
37
import org.gvsig.tools.dynobject.exception.DynFieldNotFoundException;
38
import org.gvsig.tools.persistence.PersistenceManager;
39
import org.gvsig.tools.persistence.PersistentState;
40
import org.gvsig.tools.persistence.exception.PersistenceException;
41
42
/**
43 43215 jjdelcerro
 * Abstract feature store transform intended for giving a partial default
44
 * implementation of the {@link FeatureStoreTransform} interface to other
45
 * transform implementations. It is recommended to extend this class when
46
 * implementing new {@link FeatureStoreTransform}s.
47
 *
48
 * The {@link FeatureType} of this class is not persistent: it has to be
49
 * generated by the child implementations of this abstract class when they are
50
 * created using the persistence mechanism.
51
 *
52 40435 jjdelcerro
 * @author gvSIG team
53
 * @version $Id$
54
 */
55 43215 jjdelcerro
public abstract class AbstractFeatureStoreTransform
56
    implements
57
    FeatureStoreTransform {
58
59 40435 jjdelcerro
    public static final String METADATA_DEFINITION_NAME = "FeatureStoreTransform";
60 43215 jjdelcerro
    public static final String ABSTRACT_FEATURESTORE_DYNCLASS_NAME = "AbstractFeatureStoreTransform";
61 40435 jjdelcerro
62 43215 jjdelcerro
    private FeatureStore store;
63 40435 jjdelcerro
64 43215 jjdelcerro
    private FeatureType defaultFeatureType = null;
65
    private List featureTypes = new ArrayList();
66 40435 jjdelcerro
67
    protected String name;
68
69
    protected String descripcion;
70
71
    private DynObject originalMetadata = null;
72
73 46875 fdiaz
    private final Map<String, Object> metadataValues = new HashMap<>();
74
75 40435 jjdelcerro
    public AbstractFeatureStoreTransform() {
76
        this(null, "");
77
    }
78
79
    public AbstractFeatureStoreTransform(String name, String description) {
80 43215 jjdelcerro
        if( StringUtils.isEmpty(name) ) {
81 40435 jjdelcerro
            this.name = this.getClass().getName();
82
        } else {
83
            this.name = name;
84
        }
85
        this.descripcion = description;
86 43215 jjdelcerro
    }
87 40435 jjdelcerro
88 43215 jjdelcerro
    @Override
89
    public String getDescription() {
90
        return this.descripcion;
91 40435 jjdelcerro
    }
92 43215 jjdelcerro
93
    @Override
94
    public String getName() {
95
        return this.name;
96
    }
97
98
    @Override
99
    public FeatureType getDefaultFeatureType() throws DataException {
100
        return defaultFeatureType;
101
    }
102
103
    @Override
104
    public List getFeatureTypes() throws DataException {
105
        return featureTypes;
106
    }
107
108
    @Override
109
    public void setFeatureStore(FeatureStore store) {
110
        this.store = store;
111
    }
112
113
    @Override
114
    public FeatureStore getFeatureStore() {
115
        return store;
116
    }
117 40435 jjdelcerro
118 43215 jjdelcerro
    @Override
119
    public boolean isTransformsOriginalValues() {
120
        return false;
121
    }
122 40435 jjdelcerro
123 43215 jjdelcerro
    protected void setFeatureTypes(List types, FeatureType defaultType) {
124
        this.featureTypes.clear();
125
        this.featureTypes.addAll(types);
126
        this.defaultFeatureType = defaultType;
127
    }
128 40435 jjdelcerro
129 43215 jjdelcerro
    public static void registerPersistent() {
130
        PersistenceManager persistenceManager = ToolsLocator.getPersistenceManager();
131
        DynStruct definition = persistenceManager.getDefinition(ABSTRACT_FEATURESTORE_DYNCLASS_NAME);
132 40435 jjdelcerro
133 43215 jjdelcerro
        if( definition == null ) {
134
            definition = persistenceManager.addDefinition(
135
                AbstractFeatureStoreTransform.class,
136
                ABSTRACT_FEATURESTORE_DYNCLASS_NAME,
137
                "AbstractFeatureStoreTransform Persistent definition",
138
                null,
139
                null
140
            );
141 40435 jjdelcerro
142 43215 jjdelcerro
            definition.addDynFieldObject("store")
143
                .setClassOfValue(FeatureStore.class)
144
                .setMandatory(false); // Mantenemos el campo por compatibilidad
145
                                      // con versiones anteriores a la 2.4, pero
146
                                      // ya no se recupera ni se guarda.
147
        }
148
    }
149 40435 jjdelcerro
150 43215 jjdelcerro
    @Override
151
    public void loadFromState(PersistentState state) throws PersistenceException {
152
//                this.store = (FeatureStore) state.get("store");
153
    }
154 40435 jjdelcerro
155 43215 jjdelcerro
    @Override
156
    public void saveToState(PersistentState state) throws PersistenceException {
157
//                state.set("store", store);
158
    }
159 40435 jjdelcerro
160 43215 jjdelcerro
    @Override
161
    public final void setSourceMetadata(DynObject metadata) {
162
        this.originalMetadata = metadata;
163
    }
164 40435 jjdelcerro
165 43215 jjdelcerro
    protected DynObject getSourceMetadata() {
166
        return this.originalMetadata;
167
    }
168 40435 jjdelcerro
169 43215 jjdelcerro
    @Override
170
    public Object getDynValue(String name) throws DynFieldNotFoundException {
171 46875 fdiaz
        if(metadataValues.containsKey(name)) {
172
            return metadataValues.get(name);
173
        }
174
        return null;
175 43215 jjdelcerro
    }
176 40435 jjdelcerro
177 43215 jjdelcerro
    @Override
178
    public boolean hasDynValue(String name) {
179 46875 fdiaz
        if(metadataValues.containsKey(name)) {
180
            return true;
181
        }
182 43215 jjdelcerro
        return false;
183
    }
184 46875 fdiaz
185 43215 jjdelcerro
    @Override
186
    public void setDynValue(String name, Object value)
187
        throws DynFieldNotFoundException {
188 46875 fdiaz
        metadataValues.put(name, value);
189 43215 jjdelcerro
    }
190 46875 fdiaz
191 43215 jjdelcerro
    @Override
192
    public Object clone() throws CloneNotSupportedException {
193
        return super.clone();
194 40435 jjdelcerro
195 43215 jjdelcerro
    }
196
197 46875 fdiaz
    @Override
198
    public void apply(FeatureStore store) {
199
    }
200
201
    @Override
202
    public void revoke(FeatureStore store) {
203
    }
204
205 40435 jjdelcerro
}