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

History | View | Annotate | Download (5.65 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.List;
28
import org.apache.commons.lang3.StringUtils;
29

    
30
import org.gvsig.fmap.dal.exception.DataException;
31
import org.gvsig.tools.ToolsLocator;
32
import org.gvsig.tools.dynobject.DynObject;
33
import org.gvsig.tools.dynobject.DynStruct;
34
import org.gvsig.tools.dynobject.exception.DynFieldNotFoundException;
35
import org.gvsig.tools.persistence.PersistenceManager;
36
import org.gvsig.tools.persistence.PersistentState;
37
import org.gvsig.tools.persistence.exception.PersistenceException;
38

    
39
/**
40
 * Abstract feature store transform intended for giving a partial default
41
 * implementation of the {@link FeatureStoreTransform} interface to other
42
 * transform implementations. It is recommended to extend this class when
43
 * implementing new {@link FeatureStoreTransform}s.
44
 *
45
 * The {@link FeatureType} of this class is not persistent: it has to be
46
 * generated by the child implementations of this abstract class when they are
47
 * created using the persistence mechanism.
48
 *
49
 * @author gvSIG team
50
 * @version $Id$
51
 */
52
public abstract class AbstractFeatureStoreTransform
53
    implements
54
    FeatureStoreTransform {
55

    
56
    public static final String METADATA_DEFINITION_NAME = "FeatureStoreTransform";
57
    public static final String ABSTRACT_FEATURESTORE_DYNCLASS_NAME = "AbstractFeatureStoreTransform";
58

    
59
    private FeatureStore store;
60

    
61
    private FeatureType defaultFeatureType = null;
62
    private List featureTypes = new ArrayList();
63

    
64
    protected String name;
65

    
66
    protected String descripcion;
67

    
68
    private DynObject originalMetadata = null;
69

    
70
    public AbstractFeatureStoreTransform() {
71
        this(null, "");
72
    }
73

    
74
    public AbstractFeatureStoreTransform(String name, String description) {
75
        if( StringUtils.isEmpty(name) ) {
76
            this.name = this.getClass().getName();
77
        } else {
78
            this.name = name;
79
        }
80
        this.descripcion = description;
81
    }
82

    
83
    @Override
84
    public String getDescription() {
85
        return this.descripcion;
86
    }
87

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

    
93
    @Override
94
    public FeatureType getDefaultFeatureType() throws DataException {
95
        return defaultFeatureType;
96
    }
97

    
98
    @Override
99
    public List getFeatureTypes() throws DataException {
100
        return featureTypes;
101
    }
102

    
103
    @Override
104
    public void setFeatureStore(FeatureStore store) {
105
        this.store = store;
106
    }
107

    
108
    @Override
109
    public FeatureStore getFeatureStore() {
110
        return store;
111
    }
112
    
113
    @Override
114
    public boolean isTransformsOriginalValues() {
115
        return false;
116
    }
117

    
118
    protected void setFeatureTypes(List types, FeatureType defaultType) {
119
        this.featureTypes.clear();
120
        this.featureTypes.addAll(types);
121
        this.defaultFeatureType = defaultType;
122
    }
123

    
124
    public static void registerPersistent() {
125
        PersistenceManager persistenceManager = ToolsLocator.getPersistenceManager();
126
        DynStruct definition = persistenceManager.getDefinition(ABSTRACT_FEATURESTORE_DYNCLASS_NAME);
127

    
128
        if( definition == null ) {
129
            definition = persistenceManager.addDefinition(
130
                AbstractFeatureStoreTransform.class,
131
                ABSTRACT_FEATURESTORE_DYNCLASS_NAME,
132
                "AbstractFeatureStoreTransform Persistent definition",
133
                null,
134
                null
135
            );
136

    
137
            definition.addDynFieldObject("store")
138
                .setClassOfValue(FeatureStore.class)
139
                .setMandatory(false); // Mantenemos el campo por compatibilidad
140
                                      // con versiones anteriores a la 2.4, pero
141
                                      // ya no se recupera ni se guarda.
142
        }
143
    }
144

    
145
    @Override
146
    public void loadFromState(PersistentState state) throws PersistenceException {
147
//                this.store = (FeatureStore) state.get("store");
148
    }
149

    
150
    @Override
151
    public void saveToState(PersistentState state) throws PersistenceException {
152
//                state.set("store", store);        
153
    }
154

    
155
    @Override
156
    public final void setSourceMetadata(DynObject metadata) {
157
        this.originalMetadata = metadata;
158
    }
159

    
160
    protected DynObject getSourceMetadata() {
161
        return this.originalMetadata;
162
    }
163

    
164
    @Override
165
    public Object getDynValue(String name) throws DynFieldNotFoundException {
166
        throw new DynFieldNotFoundException(name, "transform");
167
    }
168

    
169
    @Override
170
    public boolean hasDynValue(String name) {
171
        return false;
172
    }
173

    
174
    @Override
175
    public void setDynValue(String name, Object value)
176
        throws DynFieldNotFoundException {
177
        throw new DynFieldNotFoundException(name, "transform");
178
    }
179

    
180
    @Override
181
    public Object clone() throws CloneNotSupportedException {
182
        return super.clone();
183

    
184
    }
185

    
186
}