Statistics
| Revision:

root / branches / v2_0_0_prep / libraries / libFMap_dal / src / org / gvsig / fmap / dal / feature / AbstractFeatureStoreTransform.java @ 36632

History | View | Annotate | Download (3.13 KB)

1
package org.gvsig.fmap.dal.feature;
2

    
3
import java.util.ArrayList;
4
import java.util.List;
5

    
6
import org.gvsig.fmap.dal.exception.DataException;
7
import org.gvsig.tools.ToolsLocator;
8
import org.gvsig.tools.dynobject.DynStruct;
9
import org.gvsig.tools.persistence.PersistenceManager;
10
import org.gvsig.tools.persistence.PersistentState;
11
import org.gvsig.tools.persistence.exception.PersistenceException;
12

    
13
/**
14
 * Abstract feature store transform intended for giving a partial default implementation 
15
 * of the {@link FeatureStoreTransform} interface to other transform implementations. It is recommended
16
 * to extend this class when implementing new {@link FeatureStoreTransform}s.
17
 * 
18
 * The {@link FeatureType} of this class is not persistent: it has to be generated
19
 * by the child implementations of this abstract class when they are created
20
 * using the persistence mechanism.
21
 * 
22
 * @author gvSIG team
23
 * @version $Id$
24
 */
25
public abstract class AbstractFeatureStoreTransform implements
26
FeatureStoreTransform {
27
        public static final String ABSTRACT_FEATURESTORE_DYNCLASS_NAME = "AbstractFeatureStoreTransform";
28

    
29
        private FeatureStore store;
30

    
31
        private FeatureType defaultFeatureType = null;
32
        private List featureTypes = new ArrayList();
33

    
34
    protected String name;
35

    
36
    protected String descripcion;
37

    
38
        
39
    
40
    public AbstractFeatureStoreTransform() {
41
        this("", "");
42
    }
43

    
44
    public AbstractFeatureStoreTransform(String name, String description) {
45
        if( name == null || "".equals(name) ) {
46
            this.name = this.getClass().getSimpleName();
47
        } else {
48
            this.name = name;
49
        }
50
        this.descripcion = description;
51
    }
52
    
53
        public String getDescription() {
54
            return this.descripcion;
55
        }
56
        
57
        public String getName() {
58
            return this.name;
59
        }
60
        
61
        public FeatureType getDefaultFeatureType() throws DataException {
62
                return defaultFeatureType;
63
        }
64

    
65
        public List getFeatureTypes() throws DataException {
66
                return featureTypes;
67
        }
68

    
69
        public void setFeatureStore(FeatureStore store) {
70
                this.store = store;
71
        }
72

    
73
        public FeatureStore getFeatureStore() {
74
                return store;
75
        }
76

    
77
        protected void setFeatureTypes(List types, FeatureType defaultType) {
78
                this.featureTypes.clear();
79
                this.featureTypes.addAll(types);
80
                this.defaultFeatureType = defaultType;
81
        }
82

    
83
        public static void registerPersistent() {
84
            PersistenceManager persistenceManager = ToolsLocator.getPersistenceManager();
85
            DynStruct definition = persistenceManager.getDefinition(ABSTRACT_FEATURESTORE_DYNCLASS_NAME);
86

    
87
            if (definition == null){
88
                definition = persistenceManager.addDefinition(
89
                    AbstractFeatureStoreTransform.class, 
90
                    ABSTRACT_FEATURESTORE_DYNCLASS_NAME, 
91
                    "AbstractFeatureStoreTransform Persistent definition", 
92
                    null, 
93
                    null
94
                );
95

    
96
                definition.addDynFieldObject("store")
97
                    .setClassOfValue(FeatureStore.class)
98
                    .setMandatory(true);
99
            }
100
        }
101

    
102
        public void loadFromState(PersistentState state) throws PersistenceException {
103
                this.store = (FeatureStore) state.get("store");
104
        }
105

    
106
        public void saveToState(PersistentState state) throws PersistenceException {
107
                state.set("store", store);        
108
        }
109
}