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_0_0;
006:
007: import java.io.IOException;
008: import java.util.Collection;
009: import java.util.Iterator;
010:
011: import net.opengis.ows.OwsFactory;
012: import net.opengis.wfs.WfsFactory;
013: import org.eclipse.xsd.util.XSDSchemaLocationResolver;
014: import org.geoserver.wfs.xml.FeatureTypeSchemaBuilder;
015: import org.geoserver.wfs.xml.WFSHandlerFactory;
016: import org.geoserver.wfs.xml.gml3.AbstractGeometryTypeBinding;
017: import org.geotools.feature.FeatureType;
018: import org.geotools.filter.v1_0.OGCBBOXTypeBinding;
019: import org.geotools.filter.v1_0.OGCConfiguration;
020: import org.geotools.filter.v1_1.OGC;
021: import org.geotools.gml2.FeatureTypeCache;
022: import org.geotools.gml2.GMLConfiguration;
023: import org.geotools.gml2.bindings.GML;
024: import org.geotools.xml.BindingConfiguration;
025: import org.geotools.xml.Configuration;
026: import org.geotools.xml.OptionalComponentParameter;
027: import org.opengis.referencing.crs.CoordinateReferenceSystem;
028: import org.picocontainer.MutablePicoContainer;
029: import org.picocontainer.Parameter;
030: import org.picocontainer.defaults.SetterInjectionComponentAdapter;
031: import org.vfny.geoserver.global.Data;
032: import org.vfny.geoserver.global.FeatureTypeInfo;
033: import org.vfny.geoserver.global.GeoServer;
034:
035: /**
036: * Parser configuration for wfs 1.0.
037: *
038: * @author Justin Deoliveira, The Open Planning Project
039: * TODO: this class duplicates a lot of what is is in the 1.1 configuration, merge them
040: */
041: public class WFSConfiguration extends Configuration {
042: Data catalog;
043: FeatureTypeSchemaBuilder schemaBuilder;
044:
045: public WFSConfiguration(Data catalog,
046: FeatureTypeSchemaBuilder schemaBuilder) {
047: super ();
048:
049: this .catalog = catalog;
050: this .schemaBuilder = schemaBuilder;
051:
052: catalog.getGeoServer().addListener(new GeoServer.Listener() {
053:
054: public void changed() {
055: flush();
056: }
057: });
058:
059: addDependency(new OGCConfiguration());
060: addDependency(new GMLConfiguration());
061: }
062:
063: public Data getCatalog() {
064: return catalog;
065: }
066:
067: public String getNamespaceURI() {
068: return WFS.NAMESPACE;
069: }
070:
071: public String getSchemaFileURL() {
072: return getSchemaLocationResolver().resolveSchemaLocation(null,
073: WFS.NAMESPACE, "WFS-transaction.xsd");
074: }
075:
076: public BindingConfiguration getBindingConfiguration() {
077: return new WFSBindingConfiguration();
078: }
079:
080: public XSDSchemaLocationResolver getSchemaLocationResolver() {
081: return new WFSSchemaLocationResolver();
082: }
083:
084: public void configureContext(MutablePicoContainer context) {
085: super .configureContext(context);
086:
087: context.registerComponentInstance(OwsFactory.eINSTANCE);
088: context.registerComponentInstance(WfsFactory.eINSTANCE);
089: context.registerComponentInstance(new WFSHandlerFactory(
090: catalog, schemaBuilder));
091: context.registerComponentInstance(catalog);
092:
093: //TODO: this code is copied from the 1.1 configuration, FACTOR IT OUT!!!
094: //seed the cache with entries from the catalog
095: FeatureTypeCache featureTypeCache = (FeatureTypeCache) context
096: .getComponentInstanceOfType(FeatureTypeCache.class);
097:
098: try {
099: Collection featureTypes = catalog.getFeatureTypeInfos()
100: .values();
101:
102: for (Iterator f = featureTypes.iterator(); f.hasNext();) {
103: FeatureTypeInfo meta = (FeatureTypeInfo) f.next();
104: FeatureType featureType = meta.getFeatureType();
105:
106: featureTypeCache.put(featureType);
107: }
108: } catch (IOException e) {
109: throw new RuntimeException(e);
110: }
111: }
112:
113: protected void configureBindings(MutablePicoContainer bindings) {
114: super .configureBindings(bindings);
115:
116: //override the GMLAbstractFeatureTypeBinding
117: bindings.registerComponentImplementation(
118: GML.AbstractFeatureType,
119: GMLAbstractFeatureTypeBinding.class);
120:
121: //use setter injection for AbstractGeometryType bindign to allow an
122: // optional crs to be set in teh binding context for parsing, this crs
123: // is set by the binding of a parent element.
124: // note: it is important that this component adapter is non-caching so
125: // that the setter property gets updated properly every time
126: bindings.registerComponent(new SetterInjectionComponentAdapter(
127: GML.AbstractGeometryType,
128: AbstractGeometryTypeBinding.class,
129: new Parameter[] { new OptionalComponentParameter(
130: CoordinateReferenceSystem.class) }));
131:
132: // use setter injection for OGCBBoxTypeBinding to allow an
133: // optional crs to be set in teh binding context for parsing, this crs
134: // is set by the binding of a parent element.
135: // note: it is important that this component adapter is non-caching so
136: // that the setter property gets updated properly every time
137: bindings.registerComponent(new SetterInjectionComponentAdapter(
138: OGC.BBOXType, OGCBBOXTypeBinding.class,
139: new Parameter[] { new OptionalComponentParameter(
140: CoordinateReferenceSystem.class) }));
141:
142: }
143: }
|