root / branches / v2_0_0_prep / libraries / libFMap_dal / src / org / gvsig / fmap / dal / feature / impl / DefaultEditableFeatureType.java @ 24496
History | View | Annotate | Download (5.02 KB)
1 | 24496 | jmvivo | package org.gvsig.fmap.dal.feature.impl; |
---|---|---|---|
2 | 23754 | jjdelcerro | |
3 | import java.util.Iterator; |
||
4 | |||
5 | 24496 | jmvivo | import org.gvsig.fmap.dal.DataTypes; |
6 | import org.gvsig.fmap.dal.feature.EditableFeatureAttributeDescriptor; |
||
7 | import org.gvsig.fmap.dal.feature.EditableFeatureType; |
||
8 | import org.gvsig.fmap.dal.feature.FeatureType; |
||
9 | import org.gvsig.fmap.dal.feature.exceptions.DataListException; |
||
10 | import org.gvsig.fmap.dal.feature.exceptions.FeatureTypeIntegrityException; |
||
11 | 23754 | jjdelcerro | import org.gvsig.tools.evaluator.Evaluator; |
12 | |||
13 | public class DefaultEditableFeatureType extends DefaultFeatureType implements |
||
14 | EditableFeatureType { |
||
15 | |||
16 | /**
|
||
17 | *
|
||
18 | */
|
||
19 | private static final long serialVersionUID = -713976880396024389L; |
||
20 | |||
21 | private boolean hasStrongChanges; |
||
22 | private DefaultFeatureType source;
|
||
23 | |||
24 | public DefaultEditableFeatureType() {
|
||
25 | super();
|
||
26 | this.hasStrongChanges = false; |
||
27 | this.source = null; |
||
28 | } |
||
29 | |||
30 | protected DefaultEditableFeatureType(DefaultEditableFeatureType other) {
|
||
31 | super(other);
|
||
32 | 23772 | jjdelcerro | this.source = (DefaultFeatureType) other.getSource();
|
33 | 23754 | jjdelcerro | } |
34 | |||
35 | protected DefaultEditableFeatureType(DefaultFeatureType other) {
|
||
36 | super(other);
|
||
37 | this.source = other;
|
||
38 | } |
||
39 | |||
40 | public boolean hasStrongChanges() { |
||
41 | if (hasStrongChanges) {
|
||
42 | return true; |
||
43 | } |
||
44 | Iterator iter = this.iterator(); |
||
45 | DefaultEditableFeatureAttributeDescriptor attr; |
||
46 | while (iter.hasNext()) {
|
||
47 | attr = (DefaultEditableFeatureAttributeDescriptor) iter.next(); |
||
48 | if (attr.hasStrongChanges()) {
|
||
49 | return true; |
||
50 | } |
||
51 | } |
||
52 | return false; |
||
53 | } |
||
54 | |||
55 | public FeatureType getCopy() {
|
||
56 | return new DefaultEditableFeatureType(this); |
||
57 | } |
||
58 | |||
59 | public EditableFeatureType getEditable() {
|
||
60 | throw new UnsupportedOperationException(); |
||
61 | } |
||
62 | |||
63 | public boolean addAll(DefaultFeatureType other) { |
||
64 | Iterator iter = other.iterator();
|
||
65 | DefaultFeatureAttributeDescriptor attr; |
||
66 | DefaultEditableFeatureAttributeDescriptor editableAttr; |
||
67 | while (iter.hasNext()) {
|
||
68 | attr = (DefaultFeatureAttributeDescriptor) iter.next(); |
||
69 | if (attr instanceof DefaultEditableFeatureAttributeDescriptor) { |
||
70 | editableAttr = new DefaultEditableFeatureAttributeDescriptor(
|
||
71 | attr); |
||
72 | } else {
|
||
73 | editableAttr = new DefaultEditableFeatureAttributeDescriptor(
|
||
74 | attr); |
||
75 | } |
||
76 | super.add(editableAttr);
|
||
77 | } |
||
78 | return true; |
||
79 | } |
||
80 | |||
81 | 23772 | jjdelcerro | public FeatureType getSource() {
|
82 | 23754 | jjdelcerro | return source;
|
83 | } |
||
84 | |||
85 | public FeatureType getNotEditableCopy() {
|
||
86 | DefaultFeatureType copy = new DefaultFeatureType(this, false); |
||
87 | Iterator iter = this.iterator(); |
||
88 | DefaultFeatureAttributeDescriptor attr; |
||
89 | while (iter.hasNext()) {
|
||
90 | attr = (DefaultFeatureAttributeDescriptor) iter.next(); |
||
91 | copy.add(new DefaultFeatureAttributeDescriptor(attr));
|
||
92 | } |
||
93 | return copy;
|
||
94 | } |
||
95 | |||
96 | public EditableFeatureAttributeDescriptor add(String name, int type) { |
||
97 | DefaultEditableFeatureAttributeDescriptor attr = new DefaultEditableFeatureAttributeDescriptor();
|
||
98 | // FIXME: Comprobar que no hay nombres repetidos.
|
||
99 | attr.setName(name); |
||
100 | attr.setDataType(type); |
||
101 | attr.setIndex(this.size());
|
||
102 | super.add(attr);
|
||
103 | hasStrongChanges = true;
|
||
104 | return attr;
|
||
105 | } |
||
106 | |||
107 | public EditableFeatureAttributeDescriptor add(String name, int type, |
||
108 | int size) {
|
||
109 | hasStrongChanges = true;
|
||
110 | return this.add(name, type).setSize(size); |
||
111 | } |
||
112 | |||
113 | public EditableFeatureAttributeDescriptor add(String name, int type, |
||
114 | Evaluator evaluator) { |
||
115 | return this.add(name, type).setEvaluator(evaluator); |
||
116 | } |
||
117 | |||
118 | public Object remove(String name) { |
||
119 | DefaultFeatureAttributeDescriptor attr = (DefaultFeatureAttributeDescriptor) this
|
||
120 | .get(name); |
||
121 | if (attr == null) { |
||
122 | return null; |
||
123 | } |
||
124 | if (attr.getEvaluator() != null) { |
||
125 | hasStrongChanges = true;
|
||
126 | } |
||
127 | this.remove(attr);
|
||
128 | return attr;
|
||
129 | } |
||
130 | |||
131 | protected void fixAll() { |
||
132 | int i = 0; |
||
133 | Iterator iter = super.iterator(); |
||
134 | while (iter.hasNext()) {
|
||
135 | DefaultEditableFeatureAttributeDescriptor attr = (DefaultEditableFeatureAttributeDescriptor) iter |
||
136 | .next(); |
||
137 | attr.setIndex(i++); |
||
138 | attr.fixAll(); |
||
139 | } |
||
140 | } |
||
141 | |||
142 | 23772 | jjdelcerro | public void checkIntegrity() throws DataListException { |
143 | 23754 | jjdelcerro | Iterator iter = super.iterator(); |
144 | 23772 | jjdelcerro | FeatureTypeIntegrityException ex = null;
|
145 | |||
146 | 23754 | jjdelcerro | while (iter.hasNext()) {
|
147 | DefaultEditableFeatureAttributeDescriptor attr = (DefaultEditableFeatureAttributeDescriptor) iter |
||
148 | .next(); |
||
149 | try {
|
||
150 | attr.checkIntegrity(); |
||
151 | 23772 | jjdelcerro | } catch (Exception e) { |
152 | if (ex == null) { |
||
153 | ex = new FeatureTypeIntegrityException(this.getId()); |
||
154 | } |
||
155 | ex.add(e); |
||
156 | 23754 | jjdelcerro | } |
157 | } |
||
158 | 23772 | jjdelcerro | if (ex != null) { |
159 | throw ex;
|
||
160 | } |
||
161 | 23754 | jjdelcerro | } |
162 | |||
163 | public boolean remove(EditableFeatureAttributeDescriptor attribute) { |
||
164 | if (attribute.getEvaluator() != null) { |
||
165 | hasStrongChanges = true;
|
||
166 | } |
||
167 | if (!super.remove(attribute)) { |
||
168 | return false; |
||
169 | } |
||
170 | this.fixAll();
|
||
171 | return true; |
||
172 | } |
||
173 | |||
174 | public void setDefaultGeometryAttributeName(String name) { |
||
175 | DefaultFeatureAttributeDescriptor attr = (DefaultFeatureAttributeDescriptor) this
|
||
176 | .get(name); |
||
177 | if (attr == null) { |
||
178 | throw new IllegalArgumentException("Attribute '" + name |
||
179 | + "' not found.");
|
||
180 | } |
||
181 | 23894 | jjdelcerro | if (attr.getDataType() != DataTypes.GEOMETRY) {
|
182 | 23754 | jjdelcerro | throw new IllegalArgumentException("Attribute '" + name |
183 | + "' is not a geometry.");
|
||
184 | } |
||
185 | this.defaultGeometryAttributeName = name;
|
||
186 | this.defaultGeometryAttributeIndex = attr.getIndex();
|
||
187 | } |
||
188 | 24248 | jjdelcerro | |
189 | public void setHasOID(boolean hasOID) { |
||
190 | this.hasOID = hasOID;
|
||
191 | } |
||
192 | 23754 | jjdelcerro | } |