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

History | View | Annotate | Download (5.65 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
import java.util.List;
28 43215 jjdelcerro
import org.apache.commons.lang3.StringUtils;
29 40435 jjdelcerro
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 43215 jjdelcerro
 * 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 40435 jjdelcerro
 * @author gvSIG team
50
 * @version $Id$
51
 */
52 43215 jjdelcerro
public abstract class AbstractFeatureStoreTransform
53
    implements
54
    FeatureStoreTransform {
55
56 40435 jjdelcerro
    public static final String METADATA_DEFINITION_NAME = "FeatureStoreTransform";
57 43215 jjdelcerro
    public static final String ABSTRACT_FEATURESTORE_DYNCLASS_NAME = "AbstractFeatureStoreTransform";
58 40435 jjdelcerro
59 43215 jjdelcerro
    private FeatureStore store;
60 40435 jjdelcerro
61 43215 jjdelcerro
    private FeatureType defaultFeatureType = null;
62
    private List featureTypes = new ArrayList();
63 40435 jjdelcerro
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 43215 jjdelcerro
        if( StringUtils.isEmpty(name) ) {
76 40435 jjdelcerro
            this.name = this.getClass().getName();
77
        } else {
78
            this.name = name;
79
        }
80
        this.descripcion = description;
81 43215 jjdelcerro
    }
82 40435 jjdelcerro
83 43215 jjdelcerro
    @Override
84
    public String getDescription() {
85
        return this.descripcion;
86 40435 jjdelcerro
    }
87 43215 jjdelcerro
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 40435 jjdelcerro
113 43215 jjdelcerro
    @Override
114
    public boolean isTransformsOriginalValues() {
115
        return false;
116
    }
117 40435 jjdelcerro
118 43215 jjdelcerro
    protected void setFeatureTypes(List types, FeatureType defaultType) {
119
        this.featureTypes.clear();
120
        this.featureTypes.addAll(types);
121
        this.defaultFeatureType = defaultType;
122
    }
123 40435 jjdelcerro
124 43215 jjdelcerro
    public static void registerPersistent() {
125
        PersistenceManager persistenceManager = ToolsLocator.getPersistenceManager();
126
        DynStruct definition = persistenceManager.getDefinition(ABSTRACT_FEATURESTORE_DYNCLASS_NAME);
127 40435 jjdelcerro
128 43215 jjdelcerro
        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 40435 jjdelcerro
137 43215 jjdelcerro
            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 40435 jjdelcerro
145 43215 jjdelcerro
    @Override
146
    public void loadFromState(PersistentState state) throws PersistenceException {
147
//                this.store = (FeatureStore) state.get("store");
148
    }
149 40435 jjdelcerro
150 43215 jjdelcerro
    @Override
151
    public void saveToState(PersistentState state) throws PersistenceException {
152
//                state.set("store", store);
153
    }
154 40435 jjdelcerro
155 43215 jjdelcerro
    @Override
156
    public final void setSourceMetadata(DynObject metadata) {
157
        this.originalMetadata = metadata;
158
    }
159 40435 jjdelcerro
160 43215 jjdelcerro
    protected DynObject getSourceMetadata() {
161
        return this.originalMetadata;
162
    }
163 40435 jjdelcerro
164 43215 jjdelcerro
    @Override
165
    public Object getDynValue(String name) throws DynFieldNotFoundException {
166
        throw new DynFieldNotFoundException(name, "transform");
167
    }
168 40435 jjdelcerro
169 43215 jjdelcerro
    @Override
170
    public boolean hasDynValue(String name) {
171
        return false;
172
    }
173 40435 jjdelcerro
174 43215 jjdelcerro
    @Override
175
    public void setDynValue(String name, Object value)
176
        throws DynFieldNotFoundException {
177
        throw new DynFieldNotFoundException(name, "transform");
178
    }
179 40435 jjdelcerro
180 43215 jjdelcerro
    @Override
181
    public Object clone() throws CloneNotSupportedException {
182
        return super.clone();
183 40435 jjdelcerro
184 43215 jjdelcerro
    }
185
186 40435 jjdelcerro
}