Revision 46737 trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.impl/src/main/java/org/gvsig/fmap/dal/feature/impl/DefaultFeatureRules.java
DefaultFeatureRules.java | ||
---|---|---|
25 | 25 |
|
26 | 26 |
import java.util.ArrayList; |
27 | 27 |
import java.util.Iterator; |
28 |
import javax.json.JsonArray; |
|
29 |
import javax.json.JsonObject; |
|
30 |
import javax.json.JsonValue; |
|
28 | 31 |
import org.gvsig.expressionevaluator.Expression; |
29 | 32 |
import org.gvsig.expressionevaluator.impl.DefaultFeatureRuleExpression; |
30 | 33 |
|
... | ... | |
39 | 42 |
import org.gvsig.fmap.dal.feature.FeatureRule; |
40 | 43 |
import org.gvsig.fmap.dal.feature.FeatureRules; |
41 | 44 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
45 |
import org.gvsig.json.Json; |
|
46 |
import org.gvsig.json.JsonArrayBuilder; |
|
47 |
import org.gvsig.json.JsonManager; |
|
48 |
import org.gvsig.json.JsonObjectBuilder; |
|
49 |
import org.gvsig.json.SupportJson; |
|
50 |
import org.gvsig.json.SupportToJson; |
|
42 | 51 |
import org.gvsig.tools.dynobject.exception.DynFieldValidateException; |
43 | 52 |
import org.gvsig.tools.persistence.PersistentState; |
44 | 53 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
45 | 54 |
import org.slf4j.Logger; |
46 | 55 |
import org.slf4j.LoggerFactory; |
47 | 56 |
|
48 |
public class DefaultFeatureRules extends ArrayList<FeatureRule> implements FeatureRules { |
|
57 |
public class DefaultFeatureRules extends ArrayList<FeatureRule> implements FeatureRules, SupportJson {
|
|
49 | 58 |
|
50 | 59 |
private final static Logger LOGGER = LoggerFactory.getLogger(DefaultFeatureRules.class); |
51 | 60 |
|
... | ... | |
183 | 192 |
} |
184 | 193 |
} |
185 | 194 |
|
186 |
public static void selfRegister() { |
|
187 | 195 |
|
188 |
} |
|
189 |
|
|
190 | 196 |
@Override |
191 | 197 |
public void saveToState(PersistentState state) throws PersistenceException { |
192 | 198 |
state.set("rules", this.iterator()); |
... | ... | |
202 | 208 |
} |
203 | 209 |
} |
204 | 210 |
|
211 |
@Override |
|
212 |
public void fromJson(JsonObject json) { |
|
213 |
JsonArray items = json.getJsonArray("items"); |
|
214 |
if( items!=null ) { |
|
215 |
for (JsonValue item : items) { |
|
216 |
FeatureRule rule = (FeatureRule) Json.toObject(item); |
|
217 |
this.add(rule); |
|
218 |
} |
|
219 |
} |
|
220 |
} |
|
221 |
|
|
222 |
@Override |
|
223 |
public JsonObject toJson() { |
|
224 |
return this.toJsonBuilder().build(); |
|
225 |
} |
|
226 |
|
|
227 |
@Override |
|
228 |
public JsonObjectBuilder toJsonBuilder() { |
|
229 |
JsonArrayBuilder arraybuilder = Json.createArrayBuilder(); |
|
230 |
for (FeatureRule rule : this) { |
|
231 |
if( rule instanceof SupportJson ) { |
|
232 |
arraybuilder.add(((SupportJson)rule).toJsonBuilder()); |
|
233 |
} |
|
234 |
} |
|
235 |
JsonObjectBuilder builder = Json.createObjectBuilder(); |
|
236 |
builder.add_class(this); |
|
237 |
builder.add("items", arraybuilder); |
|
238 |
return builder; |
|
239 |
} |
|
240 |
|
|
241 |
public static void selfRegister() { |
|
242 |
Json.registerSerializer(DefaultFeatureRules.class); |
|
243 |
} |
|
244 |
|
|
205 | 245 |
} |
Also available in: Unified diff