001: package org.geotools;
002:
003: import org.geotools.feature.iso.FeatureTypes;
004: import org.geotools.feature.iso.AttributeFactoryImpl;
005: import org.geotools.feature.iso.TypeBuilder;
006: import org.geotools.feature.iso.simple.SimpleFeatureTypes;
007: import org.geotools.feature.iso.simple.SimpleFeatures;
008: import org.geotools.feature.iso.simple.SimpleFeatureBuilder;
009: import org.geotools.feature.iso.simple.SimpleTypeBuilder;
010: import org.geotools.feature.iso.type.TypeFactoryImpl;
011: import org.geotools.filter.FilterFactoryImpl;
012: import org.picocontainer.defaults.ConstructorInjectionComponentAdapter;
013: import org.picocontainer.defaults.DefaultPicoContainer;
014:
015: import com.vividsolutions.jts.geom.GeometryFactory;
016:
017: /**
018: * This class sets up a sample container with the default implementations
019: * implemented by module main.
020: * <p>
021: * For the test container we are using PicoContainer because it is well suited
022: * to quick sanity checks like test cases. For a real industrial strength
023: * solution please use something like Spring or JBoss containers (both of which
024: * can be used in a client application and can be configured via XML).
025: * </p>
026: * <p>
027: * The following are avaiable:
028: * <ul>
029: * <li>TypeFactory - TypeFactoryImpl
030: * <li>AttributeFactory - TypeFactoryImpl
031: * </ul>
032: * <p>
033: * <p>
034: * With this as a base instances of the following builders can be requested,
035: * they will arrive ready to go with no additional setup.
036: * <ul>
037: * <li>TypeBuilder - TypeBuilderImpl
038: * <li>ComplexAttributeBuilder - ComplexAttributeBuilderImpl
039: * </ul>
040: * <p>
041: * Here is a sample use:
042: *
043: * <pre><code>
044: * TestContainer container = new TestContainer();
045: * ComplexAttributeBuilder builder = TestContainer
046: * .getComponentInstanceOfType(ComplexAttributeBuilder.class);
047: *
048: * build.setType(roadFeatureType); // aka a FeatureType
049: * Feature road1, road2;
050: *
051: * road1 = builder.add("name", "hwy 31a").add("geom", hwy1).build("Road.31a");
052: * road2 = builder.add("name", "hwy 32").add("geom", hwy2).build("Road.32");
053: * </code></pre>
054: *
055: * For a discussion of the pros/cons using a container please review the
056: * developers documentation. Or try writing any geotools program using the
057: * "traditional" FactoryFinder approach.
058: * </p>
059: *
060: * @author Jody Garnett, Refractions Research Inc.
061: */
062: public class TestContainer extends DefaultPicoContainer {
063: private static final long serialVersionUID = 654566278905574585L;
064:
065: private TestContainer() {
066: }
067:
068: /**
069: * This will produce a TestContainer for use with the "default"
070: * implementation of the feature model.
071: * <ul>
072: * <li>TypeFactoryImpl - creates "default" implementation
073: * <li>AttributeFactoryImpl - creates "default" implementations
074: * </ul>
075: * We have also included support for the following builders interfaces and
076: * utility classes "out of the box".
077: * <ul>
078: * <li>AttributeTypeBuilder
079: * <li>GeometryTypeBuilder
080: * <li>ComplexTypeBuilder
081: * <li>FeatureTypeBuilder
082: * <li>FeatureCollectionTypeBuilder
083: * <li>FeatureBuilder
084: * <li>FeatureCollectionBuilder
085: * <li>FeatureTypes
086: * </ul>
087: *
088: * @return Test Container used to test the "default" implementation of the
089: * type system.
090: */
091: public static TestContainer normal() {
092: TestContainer c = new TestContainer();
093:
094: // factories
095: c.registerComponentImplementation(TypeFactoryImpl.class);
096: c.registerComponentImplementation(AttributeFactoryImpl.class);
097: c.registerComponentImplementation(GeometryFactory.class);
098: c.registerComponentImplementation(FilterFactoryImpl.class);
099:
100: // builders (utility classes for creation)
101: c.registerComponent(new ConstructorInjectionComponentAdapter(
102: TypeBuilder.class, TypeBuilder.class));
103:
104: // utilities
105: c.registerComponentImplementation(FeatureTypes.class);
106:
107: return c;
108: }
109:
110: /**
111: * TestContainer used to work with the "simple" implementation of the
112: * feature model.
113: * <ul>
114: * <li>TypeFactorySimple - TODO implement simple factory support
115: * <li>AttributeFactorySimple - TODO implement simple feature support
116: * </ul>
117: * We have also included support for the following builders and utility
118: * classes "out of the box".
119: * <ul>
120: * <li>SimpleFeatureTypeBuilder
121: * <li>SimpleFeatureCollectionTypeBuilder
122: * <li>SimpleFeatureBuilder
123: * <li>SimpleFeatureCollectionBuilder
124: * <li>SimpleFeatureTypes
125: * <li>SimpleFeatures
126: * </ul>
127: *
128: * @return
129: */
130: public static TestContainer simple() {
131: TestContainer c = new TestContainer();
132:
133: // factories
134: c.registerComponentImplementation(TypeFactoryImpl.class);
135: c.registerComponentImplementation(AttributeFactoryImpl.class);
136: c.registerComponentImplementation(GeometryFactory.class);
137: c.registerComponentImplementation(FilterFactoryImpl.class);
138:
139: // builders (utility classes for creation)
140: c.registerComponentImplementation(SimpleTypeBuilder.class);
141: c.registerComponentImplementation(SimpleFeatureBuilder.class);
142:
143: // utilities
144: c.registerComponentImplementation(SimpleFeatureTypes.class);
145: c.registerComponentImplementation(SimpleFeatures.class);
146:
147: return c;
148: }
149:
150: }
|