root / branches / v2_0_0_prep / libraries / libFMap_dal / src / org / gvsig / fmap / dal / feature / impl / DefaultFeatureType.java @ 24505
History | View | Annotate | Download (5.31 KB)
1 |
package org.gvsig.fmap.dal.feature.impl; |
---|---|
2 |
|
3 |
import java.lang.ref.WeakReference; |
4 |
import java.util.ArrayList; |
5 |
import java.util.Iterator; |
6 |
import java.util.List; |
7 |
import java.util.UUID; |
8 |
|
9 |
import org.gvsig.fmap.dal.exception.DataException; |
10 |
import org.gvsig.fmap.dal.feature.EditableFeatureType; |
11 |
import org.gvsig.fmap.dal.feature.Feature; |
12 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
13 |
import org.gvsig.fmap.dal.feature.FeatureRules; |
14 |
import org.gvsig.fmap.dal.feature.FeatureType; |
15 |
import org.gvsig.tools.exception.NotYetImplemented; |
16 |
|
17 |
public class DefaultFeatureType extends ArrayList implements FeatureType { |
18 |
|
19 |
/**
|
20 |
*
|
21 |
*/
|
22 |
private static final long serialVersionUID = -7988721447349282215L; |
23 |
|
24 |
private DefaultFeatureRules rules;
|
25 |
private boolean hasEvaluators; |
26 |
protected String defaultGeometryAttributeName; |
27 |
protected int defaultGeometryAttributeIndex; |
28 |
private String id; |
29 |
protected boolean hasOID; |
30 |
|
31 |
protected DefaultFeatureType() {
|
32 |
this.id = getNewId();
|
33 |
this.rules = new DefaultFeatureRules(); |
34 |
this.hasEvaluators = false; |
35 |
this.defaultGeometryAttributeName = null; |
36 |
this.defaultGeometryAttributeIndex = -1; |
37 |
} |
38 |
|
39 |
protected DefaultFeatureType(DefaultFeatureType other) {
|
40 |
initialize(other, true);
|
41 |
} |
42 |
|
43 |
protected DefaultFeatureType(DefaultFeatureType other,
|
44 |
boolean copyAttributes) {
|
45 |
initialize(other, copyAttributes); |
46 |
} |
47 |
|
48 |
synchronized private String getNewId() { |
49 |
return UUID.randomUUID().toString(); // FIXME: to libCompat |
50 |
} |
51 |
|
52 |
protected void initialize(DefaultFeatureType other, boolean copyAttributes) { |
53 |
this.id = other.getId();
|
54 |
if (copyAttributes) {
|
55 |
this.addAll(other);
|
56 |
} |
57 |
this.defaultGeometryAttributeName = other.defaultGeometryAttributeName;
|
58 |
this.hasEvaluators = other.hasEvaluators;
|
59 |
this.rules = (DefaultFeatureRules) other.rules.getCopy();
|
60 |
this.defaultGeometryAttributeIndex = other.defaultGeometryAttributeIndex;
|
61 |
} |
62 |
|
63 |
public String getId() { |
64 |
return this.id; |
65 |
} |
66 |
|
67 |
public Object get(String name) { |
68 |
return super.get(this.getIndex(name)); |
69 |
} |
70 |
|
71 |
public FeatureAttributeDescriptor getAttributeDescriptor(String name) { |
72 |
return (FeatureAttributeDescriptor) super.get(this.getIndex(name)); |
73 |
} |
74 |
|
75 |
public FeatureAttributeDescriptor getAttributeDescriptor(int index) { |
76 |
return (FeatureAttributeDescriptor) super.get(index); |
77 |
} |
78 |
|
79 |
public FeatureType getCopy() {
|
80 |
return new DefaultFeatureType(this); |
81 |
} |
82 |
|
83 |
public int getDefaultGeometryAttributeIndex() { |
84 |
return this.defaultGeometryAttributeIndex; |
85 |
} |
86 |
|
87 |
public String getDefaultGeometryAttributeName() { |
88 |
return this.defaultGeometryAttributeName; |
89 |
} |
90 |
|
91 |
public EditableFeatureType getEditable() {
|
92 |
return new DefaultEditableFeatureType(this); |
93 |
} |
94 |
|
95 |
public int getIndex(String name) { |
96 |
FeatureAttributeDescriptor attr; |
97 |
Iterator iter = this.iterator(); |
98 |
while (iter.hasNext()) {
|
99 |
attr = (FeatureAttributeDescriptor) iter.next(); |
100 |
if (attr.getName().equals(name)) {
|
101 |
return attr.getIndex();
|
102 |
} |
103 |
} |
104 |
return -1; |
105 |
} |
106 |
|
107 |
public FeatureRules getRules() {
|
108 |
return this.rules; |
109 |
} |
110 |
|
111 |
public boolean hasEvaluators() { |
112 |
return this.hasEvaluators; |
113 |
} |
114 |
|
115 |
public List getSRSs() { |
116 |
// FIXME: Falta por implementar
|
117 |
throw new NotYetImplemented(); |
118 |
} |
119 |
|
120 |
public String getDefaultSRS() { |
121 |
return this.getAttributeDescriptor( |
122 |
this.getDefaultGeometryAttributeIndex()).getSRS();
|
123 |
} |
124 |
|
125 |
public void validateFeature(Feature feature, int mode) { |
126 |
// TODO Auto-generated method stub
|
127 |
throw new NotYetImplemented(); |
128 |
} |
129 |
|
130 |
public FeatureType getSubtype(String[] names) throws DataException { |
131 |
return new SubtypeFeatureType(this, names); |
132 |
} |
133 |
|
134 |
public boolean isSubtypeOf(FeatureType featureType) { |
135 |
return false; |
136 |
} |
137 |
|
138 |
|
139 |
|
140 |
class SubtypeFeatureType extends DefaultFeatureType { |
141 |
/**
|
142 |
*
|
143 |
*/
|
144 |
private static final long serialVersionUID = 6913732960073922540L; |
145 |
WeakReference parent;
|
146 |
|
147 |
SubtypeFeatureType(DefaultFeatureType parent, String[] names) |
148 |
throws DataException {
|
149 |
super(parent, false); |
150 |
DefaultFeatureAttributeDescriptor attrcopy; |
151 |
DefaultFeatureAttributeDescriptor attr; |
152 |
for (int i = 0; i < names.length; i++) { |
153 |
attr = (DefaultFeatureAttributeDescriptor) parent |
154 |
.getAttributeDescriptor(names[i]); |
155 |
if (attr == null) { |
156 |
throw new SubtypeFeatureTypeNameException(names[i], parent |
157 |
.getId()); |
158 |
} |
159 |
attrcopy = new DefaultFeatureAttributeDescriptor(attr);
|
160 |
this.add(attrcopy);
|
161 |
attrcopy.index = i; |
162 |
} |
163 |
this.parent = new WeakReference(parent); |
164 |
} |
165 |
|
166 |
public FeatureType getSubtype(String[] names) throws DataException { |
167 |
return new SubtypeFeatureType((DefaultFeatureType) this.parent |
168 |
.get(), names); |
169 |
} |
170 |
|
171 |
public boolean isSubtypeOf(FeatureType featureType) { |
172 |
if (featureType == null) { |
173 |
return false; |
174 |
} |
175 |
FeatureType parent = (FeatureType) this.parent.get();
|
176 |
return featureType.equals(parent);
|
177 |
} |
178 |
|
179 |
public EditableFeatureType getEditable() {
|
180 |
throw new UnsupportedOperationException(); |
181 |
} |
182 |
} |
183 |
|
184 |
public class SubtypeFeatureTypeNameException extends DataException { |
185 |
|
186 |
/**
|
187 |
*
|
188 |
*/
|
189 |
private static final long serialVersionUID = -4414242486723260101L; |
190 |
private final static String MESSAGE_FORMAT = "Attribute name '%(name)s' not found in type (%(type)s)."; |
191 |
private final static String MESSAGE_KEY = "_SubtypeFeatureTypeNameException"; |
192 |
|
193 |
public SubtypeFeatureTypeNameException(String name, String type) { |
194 |
super(MESSAGE_FORMAT, MESSAGE_KEY, serialVersionUID);
|
195 |
setValue("name", name);
|
196 |
setValue("type", type);
|
197 |
} |
198 |
} |
199 |
|
200 |
public boolean hasOID() { |
201 |
return hasOID;
|
202 |
} |
203 |
|
204 |
|
205 |
} |