001: package org.geotools.feature.iso.simple;
002:
003: import java.util.Collection;
004: import java.util.Date;
005: import java.util.List;
006:
007: import org.geotools.feature.iso.collection.MemorySimpleFeatureCollection;
008: import org.opengis.feature.Association;
009: import org.opengis.feature.Attribute;
010: import org.opengis.feature.ComplexAttribute;
011: import org.opengis.feature.Feature;
012: import org.opengis.feature.FeatureCollection;
013: import org.opengis.feature.GeometryAttribute;
014: import org.opengis.feature.simple.BooleanAttribute;
015: import org.opengis.feature.simple.NumericAttribute;
016: import org.opengis.feature.simple.SimpleFeature;
017: import org.opengis.feature.simple.SimpleFeatureCollection;
018: import org.opengis.feature.simple.SimpleFeatureCollectionType;
019: import org.opengis.feature.simple.SimpleFeatureFactory;
020: import org.opengis.feature.simple.SimpleFeatureType;
021: import org.opengis.feature.simple.TemporalAttribute;
022: import org.opengis.feature.simple.TextAttribute;
023: import org.opengis.feature.type.AssociationDescriptor;
024: import org.opengis.feature.type.AssociationType;
025: import org.opengis.feature.type.AttributeDescriptor;
026: import org.opengis.feature.type.AttributeType;
027: import org.opengis.feature.type.ComplexType;
028: import org.opengis.feature.type.FeatureCollectionType;
029: import org.opengis.feature.type.FeatureType;
030: import org.opengis.feature.type.Name;
031: import org.opengis.feature.type.PropertyType;
032: import org.opengis.geometry.coordinate.GeometryFactory;
033: import org.opengis.referencing.crs.CRSFactory;
034: import org.opengis.referencing.crs.CoordinateReferenceSystem;
035:
036: /**
037: * A SimpleFeatureFactory that produces an implementation that directly wraps an
038: * array of object values.
039: * <p>
040: * This implementation is designed to be as close to the previous geotools
041: * DefaultFeature implementation as possible while still meeting the
042: * requirements of the GeoAPI feature model.
043: * <p>
044: * This implementation is marked as a SimpleFeature (as it is only capable of
045: * storing directly bound Types with no multiplicity.
046: * </p>
047: * <p>
048: * Although the use of SimpleFeatureFactory is straight forward and direct we
049: * have chosen to implement FeatureFactory as well, this allows any and all code
050: * to work with SimpleFeatures (as a SimpleFeatureType by definition will only
051: * describe content that can be created via this factory).
052: * </p>
053: *
054: * @author Jody
055: */
056: public class ArraySimpleFeatureFactory implements SimpleFeatureFactory {
057: /**
058: * Q: Why do I need this? I am not making content? only holding it.
059: * A: Anyone producing may need this.
060: */
061: CRSFactory crsFactory;
062:
063: /**
064: * Q: Why do I need this? I am not making content? only holding it.
065: * A: Anyone producing may need this.
066: */
067: GeometryFactory gf;
068:
069: public CRSFactory getCRSFactory() {
070: return crsFactory;
071: }
072:
073: public void setCRSFactory(CRSFactory factory) {
074: crsFactory = factory;
075: }
076:
077: public GeometryFactory getGeometryFactory() {
078: return gf;
079: }
080:
081: public void setGeometryFactory(GeometryFactory geometryFactory) {
082: this .gf = geometryFactory;
083: }
084:
085: /**
086: * Direct creation of a SimpleFeature from a provided SimpleFeatureType, it
087: * is understood that the provided array of values maps directly to the
088: * attribute descriptors in the provided type.
089: *
090: * @param type
091: * SimpleFeatureType of the created Feature, non null
092: * @param id
093: * To be used as the Feature ID for the created Feature, non null
094: * @param values
095: * Attribute values for the created feature, if <code>null</code>
096: * the created feature will be empty
097: */
098: public SimpleFeature createSimpleFeature(SimpleFeatureType type,
099: String fid, Object[] values) {
100: return new ArraySimpleFeature(type, fid, values);
101: }
102:
103: /**
104: * Constructs a MemorySimpleFeatureCollection, not often used as datastores
105: * will provide a custom collection (for an example see PostGIS).
106: *
107: * @param type
108: * Type of the collection being created, non null
109: * @param id
110: * Feature ID of the collection being created, non null
111: * @param contents
112: * Initial contents (ie Collection<SimpleFeatures>) or
113: * <code>null</code>
114: * @return
115: */
116:
117: public SimpleFeatureCollection createSimpleFeatureCollection(
118: SimpleFeatureCollectionType type, String fid) {
119: return new MemorySimpleFeatureCollection(type, fid);
120: }
121:
122: /**
123: * Create a stub associations descriptor, will be used as a parameter to
124: * by createFeatureCollectio
125: * <p>
126: * This is only used by generic feature model code following a
127: * SimpleFeatureCollectionType to the letter, we will unwrap the
128: * create association and make use of the reference type directly.
129: * </p>
130: */
131: public AssociationDescriptor createAssociationDescriptor(
132: final AssociationType associationType, final Name name,
133: int min, int max) {
134: return new AssociationDescriptor() {
135: public AssociationType getType() {
136: return associationType;
137: }
138:
139: public int getMinOccurs() {
140: return 1;
141: }
142:
143: public int getMaxOccurs() {
144: return 1;
145: }
146:
147: public void putUserData(Object arg0, Object arg1) {
148: }
149:
150: public Object getUserData(Object arg0) {
151: return null;
152: }
153:
154: public Name getName() {
155: return name;
156: }
157:
158: public PropertyType type() {
159: return associationType.getReferenceType();
160: }
161: };
162: }
163:
164: public Association createAssociation(Attribute arg0,
165: AssociationDescriptor arg1) {
166: // TODO Auto-generated method stub
167: return null;
168: }
169:
170: public AttributeDescriptor createAttributeDescriptor(
171: AttributeType arg0, Name arg1, int arg2, int arg3,
172: boolean arg4) {
173: // TODO Auto-generated method stub
174: return null;
175: }
176:
177: public Attribute createAttribute(Object arg0,
178: AttributeDescriptor arg1, String arg2) {
179: // TODO Auto-generated method stub
180: return null;
181: }
182:
183: public BooleanAttribute createBooleanAttribute(Boolean arg0,
184: AttributeDescriptor arg1) {
185: // TODO Auto-generated method stub
186: return null;
187: }
188:
189: public NumericAttribute createNumericAttribute(Number arg0,
190: AttributeDescriptor arg1) {
191: // TODO Auto-generated method stub
192: return null;
193: }
194:
195: public TextAttribute createTextAttribute(CharSequence arg0,
196: AttributeDescriptor arg1) {
197: // TODO Auto-generated method stub
198: return null;
199: }
200:
201: public TemporalAttribute createTemporalAttribute(Date arg0,
202: AttributeDescriptor arg1) {
203: // TODO Auto-generated method stub
204: return null;
205: }
206:
207: public GeometryAttribute createGeometryAttribute(Object arg0,
208: AttributeDescriptor arg1, String arg2,
209: CoordinateReferenceSystem arg3) {
210: // TODO Auto-generated method stub
211: return null;
212: }
213:
214: public ComplexAttribute createComplexAttribute(Collection arg0,
215: AttributeDescriptor arg1, String arg2) {
216: throw new UnsupportedOperationException(
217: "Simple Feature Collection cannot be used with complex attribute");
218: }
219:
220: public ComplexAttribute createComplexAttribute(Collection arg0,
221: ComplexType arg1, String arg2) {
222: throw new UnsupportedOperationException(
223: "Simple Feature Collection cannot be used with complex attribute");
224: }
225:
226: public Feature createFeature(Collection arg0,
227: AttributeDescriptor arg1, String arg2) {
228: throw new UnsupportedOperationException(
229: "Simple Feature Collection cannot be used as a complex attribute");
230: }
231:
232: public Feature createFeature(Collection values, FeatureType type,
233: String id) {
234: return new ArraySimpleFeature((SimpleFeatureType) type, id,
235: values.toArray());
236: }
237:
238: public FeatureCollection createFeatureCollection(Collection arg0,
239: AttributeDescriptor arg1, String arg2) {
240: throw new UnsupportedOperationException(
241: "Simple Feature Collection cannot be used as a complex attribute");
242: }
243:
244: public FeatureCollection createFeatureCollection(
245: Collection properties, FeatureCollectionType type, String id) {
246: return new MemorySimpleFeatureCollection(
247: (SimpleFeatureCollectionType) type, id);
248: }
249:
250: //
251: // Will not implement
252: //
253: public SimpleFeatureCollection createSimpleFeatureCollection(
254: AttributeDescriptor descriptor, String arg1) {
255: throw new UnsupportedOperationException(
256: "Simple Feature Collection cannot be used as a complex attribute");
257: }
258:
259: public SimpleFeature createSimpleFeature(List attributes,
260: SimpleFeatureType type, String id) {
261: // TODO Auto-generated method stub
262: return null;
263: }
264:
265: }
|