01: package org.geotools.xml.gml;
02:
03: import org.geotools.feature.DefaultAttributeType;
04: import org.geotools.feature.type.GeometricAttributeType;
05: import org.opengis.filter.Filter;
06: import org.opengis.referencing.crs.CoordinateReferenceSystem;
07:
08: import com.vividsolutions.jts.geom.GeometryCollection;
09: import com.vividsolutions.jts.geom.GeometryFactory;
10: import com.vividsolutions.jts.geom.LineString;
11: import com.vividsolutions.jts.geom.MultiLineString;
12: import com.vividsolutions.jts.geom.MultiPoint;
13: import com.vividsolutions.jts.geom.MultiPolygon;
14: import com.vividsolutions.jts.geom.Point;
15: import com.vividsolutions.jts.geom.Polygon;
16:
17: /**
18: * Created for GML generated FeatureTypes. Represents a Choice type.
19: *
20: *
21: * This is temporary and only for use by the parser. It should never be public or in common use.
22: *
23: * @author Jesse
24: */
25: class ChoiceAttributeTypeImpl extends DefaultAttributeType implements
26: ChoiceAttributeType {
27:
28: private Class[] types;
29:
30: public ChoiceAttributeTypeImpl(String name, Class[] types,
31: Class defaultType, boolean nillable, int min, int max,
32: Object defaultValue, Filter f) {
33: super (name, defaultType, nillable, min, max, defaultValue, f);
34: this .types = types;
35: }
36:
37: public Class[] getChoices() {
38: return types;
39: }
40:
41: public Object convert(Object obj) {
42: return obj;
43: }
44:
45: static class Geometry extends GeometricAttributeType implements
46: ChoiceAttributeType.Geometry {
47:
48: private Class[] types;
49:
50: public Geometry(String name, Class[] types, Class defaultType,
51: boolean nillable, int min, int max,
52: Object defaultValue, CoordinateReferenceSystem cs,
53: Filter filter) {
54: super (name, defaultType, nillable, min, max, defaultValue,
55: cs, filter);
56: this .types = types;
57: }
58:
59: public Class[] getChoices() {
60: return types;
61: }
62:
63: public Object convert(Object obj) {
64: GeometryFactory fac = new GeometryFactory();
65: if (getType() == MultiPolygon.class
66: && obj instanceof Polygon) {
67: return fac
68: .createMultiPolygon(new Polygon[] { (Polygon) obj });
69: }
70: if (getType() == MultiPoint.class && obj instanceof Point) {
71: return fac
72: .createMultiPoint(new Point[] { (Point) obj });
73: }
74: if (getType() == MultiLineString.class
75: && obj instanceof LineString) {
76: return fac
77: .createMultiLineString(new LineString[] { (LineString) obj });
78: }
79: if (getType() == GeometryCollection.class
80: && obj instanceof Geometry) {
81: return fac
82: .createGeometryCollection(new com.vividsolutions.jts.geom.Geometry[] { (com.vividsolutions.jts.geom.Geometry) obj });
83: }
84:
85: return obj;
86: }
87:
88: }
89:
90: }
|