001: /* Copyright (c) 2001 - 2007 TOPP - www.openplans.org. All rights reserved.
002: * This code is licensed under the GPL 2.0 license, availible at the root
003: * application directory.
004: */
005: package org.geoserver.wfs.xml.v1_1_0;
006:
007: import net.opengis.wfs.WfsFactory;
008: import org.eclipse.xsd.util.XSDSchemaLocationResolver;
009: import org.eclipse.xsd.util.XSDSchemaLocator;
010: import org.geoserver.ows.xml.v1_0.OWSConfiguration;
011: import org.geoserver.wfs.xml.FeatureTypeSchemaBuilder;
012: import org.geoserver.wfs.xml.PropertyTypePropertyExtractor;
013: import org.geoserver.wfs.xml.WFSHandlerFactory;
014: import org.geoserver.wfs.xml.XSQNameBinding;
015: import org.geoserver.wfs.xml.filter.v1_1.FilterTypeBinding;
016: import org.geoserver.wfs.xml.filter.v1_1.PropertyNameTypeBinding;
017: import org.geoserver.wfs.xml.gml3.AbstractGeometryTypeBinding;
018: import org.geoserver.wfs.xml.gml3.CircleTypeBinding;
019: import org.geoserver.wfs.xml.xs.DateBinding;
020: import org.geotools.feature.FeatureType;
021: import org.geotools.filter.v1_0.OGCBBOXTypeBinding;
022: import org.geotools.filter.v1_1.OGC;
023: import org.geotools.filter.v1_1.OGCConfiguration;
024: import org.geotools.gml2.FeatureTypeCache;
025: import org.geotools.gml3.GMLConfiguration;
026: import org.geotools.gml3.bindings.GML;
027: import org.geotools.xml.BindingConfiguration;
028: import org.geotools.xml.Configuration;
029: import org.geotools.xml.OptionalComponentParameter;
030: import org.geotools.xs.bindings.XS;
031: import org.opengis.referencing.crs.CoordinateReferenceSystem;
032: import org.picocontainer.MutablePicoContainer;
033: import org.picocontainer.Parameter;
034: import org.picocontainer.defaults.SetterInjectionComponentAdapter;
035: import org.vfny.geoserver.global.Data;
036: import org.vfny.geoserver.global.FeatureTypeInfo;
037: import org.vfny.geoserver.global.GeoServer;
038:
039: import java.io.IOException;
040: import java.util.Collection;
041: import java.util.Iterator;
042:
043: public class WFSConfiguration extends Configuration {
044: /**
045: * catalog
046: */
047: protected Data catalog;
048:
049: /**
050: * Schema builder
051: */
052: protected FeatureTypeSchemaBuilder schemaBuilder;
053:
054: public WFSConfiguration(Data catalog,
055: FeatureTypeSchemaBuilder schemaBuilder) {
056: super ();
057:
058: this .catalog = catalog;
059: this .schemaBuilder = schemaBuilder;
060:
061: catalog.getGeoServer().addListener(new GeoServer.Listener() {
062:
063: public void changed() {
064: flush();
065: }
066: });
067:
068: addDependency(new OGCConfiguration());
069: addDependency(new GMLConfiguration());
070: addDependency(new OWSConfiguration());
071: }
072:
073: public Data getCatalog() {
074: return catalog;
075: }
076:
077: public void addDependency(Configuration dependency) {
078: //override to make public
079: super .addDependency(dependency);
080: }
081:
082: public String getNamespaceURI() {
083: return WFS.NAMESPACE;
084: }
085:
086: public String getSchemaFileURL() {
087: return getSchemaLocationResolver().resolveSchemaLocation(null,
088: WFS.NAMESPACE, "wfs.xsd");
089: }
090:
091: public BindingConfiguration getBindingConfiguration() {
092: return new WFSBindingConfiguration();
093: }
094:
095: public XSDSchemaLocationResolver getSchemaLocationResolver() {
096: return new WFSSchemaLocationResolver();
097: }
098:
099: protected XSDSchemaLocator createSchemaLocator() {
100: return new WFSSchemaLocator(this , catalog, schemaBuilder);
101: }
102:
103: public void configureContext(MutablePicoContainer context) {
104: super .configureContext(context);
105:
106: context.registerComponentInstance(WfsFactory.eINSTANCE);
107: context.registerComponentInstance(new WFSHandlerFactory(
108: catalog, schemaBuilder));
109: context.registerComponentInstance(catalog);
110: context
111: .registerComponentImplementation(PropertyTypePropertyExtractor.class);
112:
113: //seed the cache with entries from the catalog
114: FeatureTypeCache featureTypeCache = (FeatureTypeCache) context
115: .getComponentInstanceOfType(FeatureTypeCache.class);
116:
117: try {
118: Collection featureTypes = catalog.getFeatureTypeInfos()
119: .values();
120:
121: for (Iterator f = featureTypes.iterator(); f.hasNext();) {
122: FeatureTypeInfo meta = (FeatureTypeInfo) f.next();
123: FeatureType featureType = meta.getFeatureType();
124:
125: featureTypeCache.put(featureType);
126: }
127: } catch (IOException e) {
128: throw new RuntimeException(e);
129: }
130: }
131:
132: protected void configureBindings(MutablePicoContainer container) {
133: //register our custom bindings
134: container.registerComponentImplementation(XS.DATE,
135: DateBinding.class);
136: container.registerComponentImplementation(OGC.Filter,
137: FilterTypeBinding.class);
138: container.registerComponentImplementation(OGC.PropertyNameType,
139: PropertyNameTypeBinding.class);
140: container.registerComponentImplementation(GML.CircleType,
141: CircleTypeBinding.class);
142:
143: //use setter injection for AbstractGeometryType bindign to allow an
144: // optional crs to be set in teh binding context for parsing, this crs
145: // is set by the binding of a parent element.
146: // note: it is important that this component adapter is non-caching so
147: // that the setter property gets updated properly every time
148: container
149: .registerComponent(new SetterInjectionComponentAdapter(
150: GML.AbstractGeometryType,
151: AbstractGeometryTypeBinding.class,
152: new Parameter[] { new OptionalComponentParameter(
153: CoordinateReferenceSystem.class) }));
154:
155: // use setter injection for OGCBBoxTypeBinding to allow an
156: // optional crs to be set in teh binding context for parsing, this crs
157: // is set by the binding of a parent element.
158: // note: it is important that this component adapter is non-caching so
159: // that the setter property gets updated properly every time
160: container
161: .registerComponent(new SetterInjectionComponentAdapter(
162: OGC.BBOXType,
163: OGCBBOXTypeBinding.class,
164: new Parameter[] { new OptionalComponentParameter(
165: CoordinateReferenceSystem.class) }));
166:
167: // override XSQName binding
168: container.registerComponentImplementation(XS.QNAME,
169: XSQNameBinding.class);
170: }
171: }
|