001: /*
002: * Geotools2 - OpenSource mapping toolkit
003: * http://geotools.org
004: * (C) 2005-2006, GeoTools Project Managment Committee (PMC)
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation;
009: * version 2.1 of the License.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: */
017: package org.geotools.data;
018:
019: import java.util.Set;
020:
021: import junit.framework.TestCase;
022:
023: import org.geotools.feature.Name;
024: import org.geotools.feature.iso.TypeBuilder;
025: import org.geotools.referencing.CRS;
026: import org.opengis.feature.type.AttributeType;
027: import org.opengis.feature.type.ComplexType;
028: import org.opengis.feature.type.FeatureType;
029: import org.opengis.feature.type.GeometryType;
030: import org.opengis.feature.type.TypeFactory;
031: import org.opengis.referencing.crs.CoordinateReferenceSystem;
032:
033: import com.vividsolutions.jts.geom.Geometry;
034: import com.vividsolutions.jts.geom.Point;
035:
036: /**
037: *
038: * @author Gabriel Roldan, Axios Engineering
039: * @version $Id: ComplexTestData.java 25814 2007-06-12 12:03:41Z groldan $
040: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/unsupported/community-schemas/community-schema-ds/src/test/java/org/geotools/data/ComplexTestData.java $
041: * @since 2.4
042: */
043: public abstract class ComplexTestData extends TestCase {
044:
045: public static final String NSURI = "http://online.socialchange.net.au";
046:
047: public static final String GML_NSURI = "http://www.opengis.net/gml";
048:
049: /**
050: * <pre>
051: * <code>
052: * FeatureType[
053: * name = wq_plus
054: * identified = true
055: * super = Feature
056: * abstract = false
057: * binding = Feature.class
058: * restrictions = EMPTY_SET
059: * nillable = false
060: * defaultGeometry = #location
061: * descriptor = OrderedDescriptor(1, 1)[
062: * sequence = List[
063: * AttributeDescriptor(1, 1)[
064: * type = AttributeType[
065: * name = sitename
066: * identified = false
067: * super = null
068: * abstract = false
069: * binding = String.class
070: * restrictions = EMPTY_SET
071: * nillable = false
072: * ]
073: * ],
074: * AttributeDescriptor(0, 1)[
075: * type = AttributeType[
076: * name = anzlic_no
077: * identified = false
078: * super = null
079: * abstract = false
080: * binding = String.class
081: * restrictions = EMPTY_SET
082: * nillable = true
083: * ]
084: * ],
085: * AttributeDescriptor(0, 1)[
086: * type = GeometryAttribute[
087: * name = location
088: * identified = false
089: * super = HERE WE NEED TO REFER TO gml:LocationPropertyType
090: * abstract = false
091: * binding = Point.class
092: * restrictions = EMPTY_SET
093: * nillable = true
094: * ]
095: * ],
096: * AttributeDescriptor (0, Integer.MAX_VALUE)[
097: * type = ComplexType[
098: * name = measurement
099: * identified = true
100: * super = null
101: * abstract = false
102: * binding = null
103: * restrictions = EMPTY_SET
104: * nillable = true
105: * descriptor = OrderedDescriptor(0, Integer.MAX_VALUE)[
106: * AttributeDescriptor(1, 1)[
107: * type = AttributeType[
108: * name = determinand_description
109: * identified = false
110: * super = null
111: * abstract = false
112: * binding = String.class
113: * restrictions = EMPTY_SET
114: * nillable = false
115: * ]
116: * ],
117: * AttributeDescriptor(1, 1)[
118: * type = AttributeType[
119: * name = result
120: * identified = false
121: * super = null
122: * abstract = false
123: * binding = String.class
124: * restrictions = EMPTY_SET
125: * nillable = false
126: * ]
127: * ]
128: * ]//OrderedDescriptor
129: * ] //ComplexType
130: * ], //measurement
131: * AttributeDescriptor(0, 1)[
132: * type = AttributeType[
133: * name = project_no
134: * identified = false
135: * super = null
136: * abstract = false
137: * binding = String.class
138: * restrictions = EMPTY_SET
139: * nillable = false
140: * ]
141: * ]
142: * ]
143: * ]
144: * ]
145: * </code>
146: * </pre>
147: *
148: * @param typeFactory
149: * @param descFactory
150: * @return
151: */
152: public static FeatureType createExample01MultiValuedComplexProperty(
153: TypeFactory typeFactory) {
154: FeatureType wqPlusType;
155:
156: TypeBuilder builder = new TypeBuilder(typeFactory);
157: builder.setNamespaceURI(NSURI);
158:
159: builder.setName("sitename");
160: builder.setBinding(String.class);
161: AttributeType SITENAME = builder.attribute();
162:
163: builder.setName("anzlic_noType");
164: builder.setBinding(String.class);
165: AttributeType ANZLIC_NO = builder.attribute();
166:
167: builder.setName("locationType");
168: builder.setBinding(Point.class);
169: GeometryType LOCATION = builder.geometry();
170:
171: // build complex attribute
172: AttributeType MEASUREMENT = createMeasurementType(typeFactory);
173:
174: builder.setName("project_noType");
175: builder.setBinding(String.class);
176: AttributeType PROJECT_NO = builder.attribute();
177:
178: builder.setName("wq_plus");
179:
180: builder.cardinality(1, 1);
181: builder.addAttribute("sitename", SITENAME);
182:
183: builder.cardinality(0, 1);
184: builder.addAttribute("anzlic_no", ANZLIC_NO);
185:
186: builder.cardinality(0, 1);
187: builder.addAttribute("location", LOCATION);
188:
189: builder.cardinality(0, Integer.MAX_VALUE);
190: builder.addAttribute("measurement", MEASUREMENT);
191:
192: builder.cardinality(0, 1);
193: builder.addAttribute("project_no", PROJECT_NO);
194:
195: wqPlusType = builder.feature();
196:
197: return wqPlusType;
198: }
199:
200: /**
201: * A feature type that has various multi-valued properties.
202: * <p>
203: * Multi valued properties: meassurement(0:unbounded),
204: * sitename(1:unbounded).
205: *
206: * <pre>
207: * <code>
208: * </code>
209: * </pre>
210: *
211: * </p>
212: *
213: * @param typeFactory
214: * @param descFactory
215: * @return
216: */
217: public static FeatureType createExample02MultipleMultivalued(
218: TypeFactory typeFactory) {
219:
220: TypeBuilder builder = new TypeBuilder(typeFactory);
221: builder.setNamespaceURI(NSURI);
222:
223: AttributeType measurement = createMeasurementType(typeFactory);
224: AttributeType the_geom = builder.name("the_geom").bind(
225: Geometry.class).attribute();
226: AttributeType sitename = builder.name("sitename").bind(
227: String.class).attribute();
228:
229: builder.cardinality(0, Integer.MAX_VALUE);
230: builder.addAttribute("measurement", measurement);
231:
232: builder.cardinality(1, 1);
233: builder.addAttribute("the_geom", the_geom);
234:
235: builder.nillable(true);
236: builder.cardinality(1, Integer.MAX_VALUE);
237: builder.addAttribute("sitename", sitename);
238:
239: builder.setName("wq_plus");
240: FeatureType wqPlusType = builder.feature();
241: return wqPlusType;
242: }
243:
244: /**
245: * A feature may have multiple geometries
246: *
247: * <pre><code>
248: * <xs:complexType name="measurement_Type">
249: * <xs:sequence>
250: * <xs:element name="determinand_description" type="xs:string"/>
251: * <xs:element name="result" type="xs:string"/>
252: * </xs:sequence>
253: * <xs:attribute ref="gml:id" use="optional"/>
254: * </xs:complexType>
255: *
256: * <xs:complexType name="wq_plus_Type" xmlns:xs="http://www.w3.org/2001/XMLSchema">
257: * <xs:complexContent>
258: * <xs:extension base="gml:AbstractFeatureType">
259: * <xs:sequence>
260: * <xs:element name="measurement" maxOccurs="unbounded" type="sco:measurement_Type"/>
261: *
262: * <xs:element name="location" type="gml:LocationPropertyType"/>
263: * <xs:element name="nearestSlimePit" type="gml:PointPropertyType"/>
264: * <xs:element name="sitename" maxOccurs="unbounded" nillable="false" type="xs:string" />
265: * </xs:sequence>
266: * </xs:extension>
267: * </xs:complexContent>
268: * </xs:complexType>
269: *
270: * <xs:element name='wq_plus' type='sco:wq_plus_Type' substitutionGroup="gml:_Feature" />
271: * </code></pre>
272: *
273: * @param typeFactory
274: * @param descFactory
275: * @return
276: */
277: public static FeatureType createExample03MultipleGeometries(
278: TypeFactory typeFactory) {
279: TypeBuilder builder = new TypeBuilder(typeFactory);
280: builder.setNamespaceURI(NSURI);
281:
282: AttributeType measurement = createMeasurementType(typeFactory);
283:
284: AttributeType gmlLocationAssociation = createGmlLocation(typeFactory);
285:
286: AttributeType gmlPointAssociation = createGmlPoint(typeFactory);
287:
288: builder.setName("wq_plus");
289: builder.cardinality(0, Integer.MAX_VALUE);
290: builder.addAttribute("measurement", measurement);
291:
292: builder.cardinality(1, 1);
293: builder.nillable(true);
294: builder.addAttribute("location", gmlLocationAssociation);
295:
296: builder.cardinality(1, 1);
297: builder.nillable(true);
298: builder.addAttribute("nearestSlimePit", gmlPointAssociation);
299:
300: builder.cardinality(1, Integer.MAX_VALUE);
301: builder.addAttribute("sitename", String.class);
302:
303: // use the second geometry attribute as the default one just for testing
304: builder.defaultGeometry("nearestSlimePit");
305:
306: FeatureType wqPlusType = builder.feature();
307:
308: return wqPlusType;
309: }
310:
311: /**
312: *
313: * @param typeFactory
314: * @param descFactory
315: * @return
316: */
317: public static FeatureType createExample04Type(
318: TypeFactory typeFactory) {
319: TypeBuilder builder = new TypeBuilder(typeFactory);
320: builder.setNamespaceURI(NSURI);
321:
322: builder.cardinality(1, Integer.MAX_VALUE);
323: builder.addAttribute("name", String.class);
324:
325: builder.setName(GML_NSURI);
326: builder.cardinality(1, Integer.MAX_VALUE);
327: builder.addAttribute("name", String.class);
328:
329: builder.setNamespaceURI(NSURI);
330: builder.setName("wq_plus");
331:
332: FeatureType wqPlusType = builder.feature();
333: return wqPlusType;
334: }
335:
336: /**
337: * Creates a FeatureType for the Road
338: *
339: * <pre><code>
340: * <xs:element name="roadRef" type="sco:RoadPropertyType"/>
341: * <xs:element name="junctionRef" type="sco:JunctionPropertyType"/>
342: *
343: * <xs:complexType name="RoadPropertyType">
344: * <xs:annotation>
345: * <xs:documentation>Container for a road - follow gml:AssociationType pattern.</xs:documentation>
346: * </xs:annotation>
347: * <xs:sequence minOccurs="0">
348: * <xs:element ref="sco:Road" />
349: * </xs:sequence>
350: * <xs:attributeGroup ref="gml:AssociationAttributeGroup" />
351: * </xs:complexType>
352: *
353: * <xs:complexType name="JunctionPropertyType">
354: * <xs:annotation>
355: * <xs:documentation>Container for a junction - follow gml:AssociationType pattern.</xs:documentation>
356: * </xs:annotation>
357: * <xs:sequence minOccurs="0">
358: * <xs:element ref="sco:Junction" />
359: * </xs:sequence>
360: * <xs:attributeGroup ref="gml:AssociationAttributeGroup" />
361: * </xs:complexType>
362: *
363: * <xs:complexType name="RoadType">
364: * <xs:complexContent>
365: * <xs:extension base="gml:AbstractFeatureType">
366: * <xs:sequence>
367: * <xs:element name="geom" type="gml:CurvePropertyType" minOccurs="0" />
368: * <xs:element ref="sco:junctionRef" minOccurs="0" maxOccurs="unbounded" />
369: * </xs:sequence>
370: * </xs:extension>
371: * </xs:complexContent>
372: * </xs:complexType>
373: *
374: * <xs:complexType name="JunctionType">
375: * <xs:complexContent>
376: * <xs:extension base="gml:AbstractFeatureType">
377: * <xs:sequence>
378: * <xs:element ref="sco:roadRef" />
379: * <xs:element name="direction" type="xs:int" />
380: * </xs:sequence>
381: * </xs:extension>
382: * </xs:complexContent>
383: * </xs:complexType>
384: *
385: * <xs:element name='Junction' type='sco:JunctionType' substitutionGroup="gml:_Feature" />
386: * <xs:element name='Road' type='sco:RoadType' substitutionGroup="gml:_Feature" />
387: *
388: * </code></pre>
389: *
390: */
391: /*
392: * public static FeatureType createExample05RoadType(TypeFactory
393: * typeFactory, DescriptorFactory descFactory) { List<Descriptor>
394: * roadContents = new ArrayList<Descriptor>();
395: *
396: * //create association type to reference junction GenericName
397: * junctionTypeName = new GenericName(NSURI, "Junction"); AttributeType
398: * junctionReference = typeFactory.createAssociationType(junctionTypeName);
399: *
400: * List<Descriptor> junctionRefContents = new ArrayList<Descriptor>();
401: * junctionRefContents.add(descFactory.node(junctionReference, 1, 1));
402: *
403: * Descriptor junctionPropertySchema =
404: * descFactory.ordered(junctionRefContents, 0, 1); ComplexType junctionRef =
405: * typeFactory.createType(new GenericName("functionRef"),
406: * junctionPropertySchema);
407: *
408: *
409: * //create junction type List<Descriptor> junctionContents = new ArrayList<Descriptor>();
410: *
411: * FeatureType roadType = typeFactory.createFeatureType(new
412: * GenericName(NSURI), roadSchema, null);
413: *
414: * List<Descriptor>roadRefContents = new ArrayList<Descriptor>();
415: *
416: * roadRefContents.add(descFactory.node(RoadType, 1, 1)); Descriptor
417: * roadRefDesc = descFactory.ordered(roadRefContents, 0, 1); ComplexType
418: * roadRef = typeFactory.createType(new GenericName(NSURI, "roadRef"),
419: * roadRefDesc); AttributeType direction = typeFactory.createType(new
420: * GenericName(NSURI, "direction"), Integer.class);
421: * junctionContents.add(descFactory.node(direction, 1, 1)); }
422: */
423:
424: public static FeatureType createExample05JunctionType(
425: TypeFactory typeFactory) {
426: return null;
427: }
428:
429: public static ComplexType createMeasurementType(
430: TypeFactory typeFactory) {
431: TypeBuilder builder = new TypeBuilder(typeFactory);
432: builder.setNamespaceURI(NSURI);
433:
434: builder.setName("determinand_description");
435: builder.setBinding(String.class);
436: AttributeType detdesc = builder.attribute();
437:
438: builder.setName("result");
439: builder.setBinding(String.class);
440:
441: AttributeType result = builder.attribute();
442:
443: builder.setName("measurementType");
444: builder.cardinality(1, 1);
445: builder.addAttribute("determinand_description", detdesc);
446: builder.addAttribute("result", result);
447:
448: ComplexType measurement = builder.complex();
449:
450: return measurement;
451: }
452:
453: /**
454: * Creates a representation of a gml:LocationPropertyType association. This
455: * would be better done by obtaining the type from a registry, so we can
456: * have GML2TypeRegistry, GML3TypeRegistry, DefaultTypeRegistry, etc.
457: *
458: * @return
459: */
460: public static AttributeType createGmlLocation(
461: TypeFactory typeFactory) {
462: TypeBuilder builder = new TypeBuilder(typeFactory);
463: builder.setNamespaceURI(GML_NSURI);
464: builder.setName("LocationPropertyType");
465: builder.setBinding(Point.class);
466:
467: AttributeType type = builder.geometry();
468:
469: return type;
470: }
471:
472: /**
473: * Creates a representation of a gml:PointPropertyType association as an
474: * AttributeType. This would be better done by obtaining the type from a
475: * registry, so we can have GML2TypeRegistry, GML3TypeRegistry,
476: * DefaultTypeRegistry, etc.
477: *
478: * @return
479: */
480: public static AttributeType createGmlPoint(TypeFactory typeFactory) {
481: TypeBuilder builder = new TypeBuilder(typeFactory);
482: builder.setNamespaceURI(GML_NSURI);
483:
484: builder.setName("PointPropertyType");
485: CoordinateReferenceSystem fakeCrs = null;
486: try {
487: fakeCrs = CRS.decode("EPSG:4326");
488: } catch (Exception e) {
489: e.printStackTrace();
490: throw new RuntimeException(e);
491: }
492: builder.setCRS(fakeCrs);
493: builder.setBinding(Point.class);
494:
495: GeometryType type = builder.geometry();
496: return type;
497: }
498:
499: /**
500: * Asserts the corresponding properties of <code>type</code> for equality
501: * with the provided parameter values
502: *
503: * @param type
504: * @param name
505: * @param binding
506: * @param restrictions
507: * @param identified
508: * @param _abstract
509: * @param superType
510: * @param nillable
511: */
512: public static void checkType(AttributeType type, Name name,
513: Class binding, Set/* <Filter> */restrictions,
514: boolean identified, boolean _abstract,
515: AttributeType superType) {
516:
517: assertNotNull(type);
518: assertEquals(name, type.getName());
519: assertEquals(binding, type.getBinding());
520: assertNotNull(type.getRestrictions());
521: assertEquals(restrictions, type.getRestrictions());
522: assertEquals(identified, type.isIdentified());
523: assertEquals(_abstract, type.isAbstract());
524: assertEquals(superType, type.getSuper());
525: }
526:
527: }
|