Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / libraries / libFMap_dal / src / org / gvsig / fmap / dal / feature / impl / DefaultFeatureAttributeDescriptor.java @ 28947

History | View | Annotate | Download (4.97 KB)

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

    
3
import java.io.File;
4
import java.text.DateFormat;
5
import java.util.Date;
6
import java.util.HashMap;
7
import java.util.Iterator;
8
import java.util.Map;
9
import java.util.Map.Entry;
10

    
11
import org.cresques.cts.IProjection;
12
import org.gvsig.fmap.dal.DataTypes;
13
import org.gvsig.fmap.dal.feature.Feature;
14
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
15
import org.gvsig.fmap.dal.feature.exception.UnsupportedDataTypeException;
16
import org.gvsig.fmap.geom.Geometry;
17
import org.gvsig.tools.evaluator.Evaluator;
18

    
19
public class DefaultFeatureAttributeDescriptor implements
20
                FeatureAttributeDescriptor {
21

    
22
        protected boolean allowNull;
23
        protected int dataType;
24
        protected DateFormat dataFormat;
25
        protected Object defaultValue;
26
        protected int index;
27
        protected int maximumOccurrences;
28
        protected int minimumOccurrences;
29
        protected int size;
30
        protected String name;
31
        protected Class objectClass;
32
        protected int precision;
33
        protected Evaluator evaluator;
34
        protected boolean primaryKey;
35
        protected boolean readOnly;
36
        protected IProjection SRS;
37
        protected int geometryType;
38
        protected int geometrySubType;
39
        protected Map additionalInfo;
40
        protected boolean isAutomatic;
41

    
42

    
43
    private static final Class TYPE_CLASS[] = new Class[] {
44
            null,
45
            Boolean.class,
46
            Byte.class, // keep for formatting
47
        Character.class,
48
        Integer.class,
49
        Long.class,
50
        Float.class,
51
        Double.class,
52
        String.class,
53
        Date.class,
54
        Date.class,
55
        Date.class,
56
        Geometry.class,
57
        Object.class, //
58
        Feature.class,
59
        IProjection.class,
60
        File.class,
61
        new byte[] {}.getClass()
62

    
63
    };
64

    
65
        protected DefaultFeatureAttributeDescriptor() {
66
                this.allowNull = true;
67
                this.dataType = DataTypes.UNKNOWN;
68
                this.dataFormat = null;
69
                this.defaultValue = null;
70
                this.index = -1;
71
                this.maximumOccurrences = 0;
72
                this.minimumOccurrences = 0;
73
                this.size = 0;
74
                this.name = null;
75
                this.objectClass = null;
76
                this.precision = 0;
77
                this.evaluator = null;
78
                this.primaryKey = false;
79
                this.readOnly = false;
80
                this.SRS = null;
81
                this.geometryType = Geometry.TYPES.NULL;
82
                this.geometrySubType = Geometry.SUBTYPES.UNKNOWN;
83
                this.additionalInfo = null;
84
                this.isAutomatic = false;
85
        }
86

    
87
        protected DefaultFeatureAttributeDescriptor(
88
                        DefaultFeatureAttributeDescriptor other) {
89
                this.allowNull = other.allowNull;
90
                this.dataType = other.dataType;
91
                this.dataFormat = other.dataFormat;
92
                this.defaultValue = other.defaultValue;
93
                this.index = other.index;
94
                this.maximumOccurrences = other.maximumOccurrences;
95
                this.minimumOccurrences = other.minimumOccurrences;
96
                this.size = other.size;
97
                this.name = other.name;
98
                this.objectClass = other.objectClass;
99
                this.precision = other.precision;
100
                this.evaluator = other.evaluator;
101
                this.primaryKey = other.primaryKey;
102
                this.readOnly = other.readOnly;
103
                this.SRS = other.SRS;
104
                this.geometryType = other.geometryType;
105
                this.geometrySubType = other.geometrySubType;
106
                if (other.additionalInfo != null) {
107
                        Iterator iter = other.additionalInfo.entrySet().iterator();
108
                        Map.Entry entry;
109
                        this.additionalInfo = new HashMap();
110
                        while (iter.hasNext()) {
111
                                entry = (Entry) iter.next();
112
                                this.additionalInfo.put(entry.getKey(), entry.getValue());
113
                        }
114
                } else {
115
                        this.additionalInfo = null;
116
                }
117
                this.isAutomatic = other.isAutomatic;
118
        }
119

    
120
        public String getDataTypeName() {
121
                return DataTypes.TYPE_NAMES[this.getDataType()];
122
        }
123

    
124
        public FeatureAttributeDescriptor getCopy() {
125
                return new DefaultFeatureAttributeDescriptor(this);
126
        }
127

    
128
        public boolean allowNull() {
129
                return allowNull;
130
        }
131

    
132
        public int getDataType() {
133
                return this.dataType;
134
        }
135

    
136
        public DateFormat getDateFormat() {
137
                return this.dataFormat;
138
        }
139

    
140
        public Object getDefaultValue() {
141
                return this.defaultValue;
142
        }
143

    
144
        public Evaluator getEvaluator() {
145
                return this.evaluator;
146
        }
147

    
148
        public int getGeometryType() {
149
                return this.geometryType;
150
        }
151

    
152
        public int getGeometrySubType() {
153
                return this.geometrySubType;
154
        }
155

    
156
        public int getIndex() {
157
                return this.index;
158
        }
159

    
160
        protected FeatureAttributeDescriptor setIndex(int index) {
161
                this.index = index;
162
                return this;
163
        }
164

    
165
        public int getMaximumOccurrences() {
166
                return this.maximumOccurrences;
167
        }
168

    
169
        public int getMinimumOccurrences() {
170
                return this.minimumOccurrences;
171
        }
172

    
173
        public String getName() {
174
                return this.name;
175
        }
176

    
177
        public Class getObjectClass() {
178
                if (this.dataType > TYPE_CLASS.length || this.dataType < 0) {
179
                        throw new UnsupportedDataTypeException(this.name, this.dataType);
180
                }
181
                return TYPE_CLASS[this.dataType];
182
        }
183

    
184
        public int getPrecision() {
185
                return this.precision;
186
        }
187

    
188
        public IProjection getSRS() {
189
                return this.SRS;
190
        }
191

    
192
        public int getSize() {
193
                return this.size;
194
        }
195

    
196
        public boolean isPrimaryKey() {
197
                return this.primaryKey;
198
        }
199

    
200
        public boolean isReadOnly() {
201
                return this.readOnly;
202
        }
203

    
204
        public Object getAdditionalInfo(String infoName) {
205
                if (this.additionalInfo == null) {
206
                        return null;
207
                }
208
                return this.additionalInfo.get(infoName);
209
        }
210

    
211
        public boolean isAutomatic() {
212
                return this.isAutomatic;
213
        }
214

    
215
}