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 @ 46875

History | View | Annotate | Download (6.05 KB)

1
/**
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
package org.gvsig.fmap.dal.feature;
25

    
26
import java.util.ArrayList;
27
import java.util.HashMap;
28
import java.util.List;
29
import java.util.Map;
30
import org.apache.commons.lang3.StringUtils;
31
import org.gvsig.fmap.dal.DataStore;
32

    
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
 * 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
 * @author gvSIG team
53
 * @version $Id$
54
 */
55
public abstract class AbstractFeatureStoreTransform
56
    implements
57
    FeatureStoreTransform {
58

    
59
    public static final String METADATA_DEFINITION_NAME = "FeatureStoreTransform";
60
    public static final String ABSTRACT_FEATURESTORE_DYNCLASS_NAME = "AbstractFeatureStoreTransform";
61

    
62
    private FeatureStore store;
63

    
64
    private FeatureType defaultFeatureType = null;
65
    private List featureTypes = new ArrayList();
66

    
67
    protected String name;
68

    
69
    protected String descripcion;
70

    
71
    private DynObject originalMetadata = null;
72

    
73
    private final Map<String, Object> metadataValues = new HashMap<>();
74

    
75
    public AbstractFeatureStoreTransform() {
76
        this(null, "");
77
    }
78

    
79
    public AbstractFeatureStoreTransform(String name, String description) {
80
        if( StringUtils.isEmpty(name) ) {
81
            this.name = this.getClass().getName();
82
        } else {
83
            this.name = name;
84
        }
85
        this.descripcion = description;
86
    }
87

    
88
    @Override
89
    public String getDescription() {
90
        return this.descripcion;
91
    }
92

    
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
    
118
    @Override
119
    public boolean isTransformsOriginalValues() {
120
        return false;
121
    }
122

    
123
    protected void setFeatureTypes(List types, FeatureType defaultType) {
124
        this.featureTypes.clear();
125
        this.featureTypes.addAll(types);
126
        this.defaultFeatureType = defaultType;
127
    }
128

    
129
    public static void registerPersistent() {
130
        PersistenceManager persistenceManager = ToolsLocator.getPersistenceManager();
131
        DynStruct definition = persistenceManager.getDefinition(ABSTRACT_FEATURESTORE_DYNCLASS_NAME);
132

    
133
        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

    
142
            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

    
150
    @Override
151
    public void loadFromState(PersistentState state) throws PersistenceException {
152
//                this.store = (FeatureStore) state.get("store");
153
    }
154

    
155
    @Override
156
    public void saveToState(PersistentState state) throws PersistenceException {
157
//                state.set("store", store);        
158
    }
159

    
160
    @Override
161
    public final void setSourceMetadata(DynObject metadata) {
162
        this.originalMetadata = metadata;
163
    }
164

    
165
    protected DynObject getSourceMetadata() {
166
        return this.originalMetadata;
167
    }
168

    
169
    @Override
170
    public Object getDynValue(String name) throws DynFieldNotFoundException {
171
        if(metadataValues.containsKey(name)) {
172
            return metadataValues.get(name);
173
        }
174
        return null;
175
    }
176

    
177
    @Override
178
    public boolean hasDynValue(String name) {
179
        if(metadataValues.containsKey(name)) {
180
            return true;
181
        }
182
        return false;
183
    }
184
    
185
    @Override
186
    public void setDynValue(String name, Object value)
187
        throws DynFieldNotFoundException {
188
        metadataValues.put(name, value);
189
    }
190
    
191
    @Override
192
    public Object clone() throws CloneNotSupportedException {
193
        return super.clone();
194

    
195
    }
196

    
197
    @Override
198
    public void apply(FeatureStore store) {
199
    }
200

    
201
    @Override
202
    public void revoke(FeatureStore store) {
203
    }
204

    
205
}