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