Author: jeichar Date: 2006-07-27 01:10:49 -0700 (Thu, 27 Jul 2006) New Revision: 20730 Added: geotools/branches/2.2.x/module/main/src/org/geotools/xml/XMLHandlerHin= ts.java geotools/branches/2.2.x/plugin/wfs/src/org/geotools/data/wfs/LogWriter= Decorator.java geotools/branches/2.2.x/plugin/wfs/src/org/geotools/data/wfs/WFSFeatur= eType.java Modified: geotools/branches/2.2.x/module/main/src/org/geotools/xml/FlowHandler.j= ava geotools/branches/2.2.x/module/main/src/org/geotools/xml/SchemaFactory= .java geotools/branches/2.2.x/module/main/src/org/geotools/xml/XMLSAXHandler= .java geotools/branches/2.2.x/module/main/src/org/geotools/xml/gml/FCBuffer.= java geotools/branches/2.2.x/module/main/src/org/geotools/xml/gml/FCFlowHan= dler.java geotools/branches/2.2.x/module/main/src/org/geotools/xml/gml/GMLComple= xTypes.java geotools/branches/2.2.x/plugin/wfs/src/org/geotools/data/ows/WFSCapabi= lities.java geotools/branches/2.2.x/plugin/wfs/src/org/geotools/data/wfs/WFSDataSt= ore.java geotools/branches/2.2.x/plugin/wfs/src/org/geotools/data/wfs/WFSFeatur= eReader.java geotools/branches/2.2.x/plugin/wfs/src/org/geotools/data/wfs/WFSTransa= ctionState.java Log: added support for hidden feature type schemas and for declaring what sche= mas to use Modified: geotools/branches/2.2.x/module/main/src/org/geotools/xml/FlowHa= ndler.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- geotools/branches/2.2.x/module/main/src/org/geotools/xml/FlowHandler.= java 2006-07-26 22:43:18 UTC (rev 20729) +++ geotools/branches/2.2.x/module/main/src/org/geotools/xml/FlowHandler.= java 2006-07-27 08:10:49 UTC (rev 20730) @@ -26,8 +26,6 @@ * */ public interface FlowHandler { - public final static String FLOW_HANDLER_HINT =3D "FLOW_HANDLER_HINT"= ; - /** * If this method returns true, the XMLSAXHandler will abort parsing= . * Modified: geotools/branches/2.2.x/module/main/src/org/geotools/xml/Schema= Factory.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- geotools/branches/2.2.x/module/main/src/org/geotools/xml/SchemaFactor= y.java 2006-07-26 22:43:18 UTC (rev 20729) +++ geotools/branches/2.2.x/module/main/src/org/geotools/xml/SchemaFactor= y.java 2006-07-27 08:10:49 UTC (rev 20730) @@ -26,10 +26,12 @@ import java.util.Collections; import java.util.Enumeration; import java.util.HashMap; +import java.util.HashSet; import java.util.Iterator; import java.util.LinkedList; import java.util.List; import java.util.Map; +import java.util.Set; import java.util.logging.Level; =20 import javax.xml.parsers.ParserConfigurationException; @@ -224,6 +226,7 @@ return (Schema[])l.toArray(new Schema[l.size()]); } =20 + =20 private synchronized Schema getRealInstance(URI targetNamespace) { Schema r =3D (Schema) schemas.get(targetNamespace); =20 @@ -266,8 +269,9 @@ level); } =20 - private synchronized Schema getRealInstance(URI targetNamespace, + private synchronized Schema getRealInstance(URI targetNamespace2, URI desiredSchema, Level level) throws SAXException { + URI targetNamespace=3DtargetNamespace2; if ((targetNamespace =3D=3D null) || (schemas.get(targetNamespac= e) =3D=3D null)) { setParser(); =20 @@ -277,18 +281,22 @@ try { parser.parse(desiredSchema.toString(), contentHandler); } catch (IOException e) { + // TODO error handler should be notified of a connection= exception: operation timed out. throw new SAXException(e); } =20 + Schema schema =3D contentHandler.getSchema(); if ((targetNamespace =3D=3D null) || "".equals(targetNamespa= ce)) { - return contentHandler.getSchema(); + targetNamespace=3Dschema.getTargetNamespace(); } =20 - schemas.put(targetNamespace, contentHandler.getSchema()); - - // } + if( schemas.get(targetNamespace)!=3Dnull ){ + schema=3Dmerge(schema, (Schema) schemas.get(targetNamesp= ace)); + } + schemas.put(targetNamespace, schema); + return schema; } else { - if (!((Schema) schemas.get(targetNamespace)).includesURI( + if ( !((Schema) schemas.get(targetNamespace)).includesURI( desiredSchema)) { Schema sh =3D (Schema) schemas.get(targetNamespace); setParser(); @@ -319,48 +327,48 @@ return getInstance().getRealInstance(targetNamespace, is1, level= ); } =20 - private synchronized Schema getRealInstance(URI targetNamespace, + private synchronized Schema getRealInstance(URI targetNamespace2, InputStream is1, Level level) throws SAXException { + URI targetNamespace=3DtargetNamespace2; + =20 if ((targetNamespace =3D=3D null) || (schemas.get(targetNamespac= e) =3D=3D null)) { - setParser(); + XSISAXHandler contentHandler =3D parseSchema(is1, level); =20 - XSISAXHandler contentHandler =3D getSAXHandler(null); // no = uri - XSISAXHandler.setLogLevel(level); - - try { - parser.parse(is1, contentHandler); - } catch (IOException e) { - throw new SAXException(e); + if ((targetNamespace =3D=3D null) || "".equals(targetNamespa= ce)) { + targetNamespace=3DcontentHandler.getSchema().getTargetNa= mespace(); } =20 - if (targetNamespace =3D=3D null) { - return contentHandler.getSchema(); + Schema schema =3D contentHandler.getSchema(); + if( schemas.get(targetNamespace)!=3Dnull ){ + schema=3Dmerge(schema, (Schema) schemas.get(targetNamesp= ace)); } - + =20 schemas.put(targetNamespace, contentHandler.getSchema()); =20 - // } } else { - // no way to test is it's already part ... so assume it's no= t already included Schema sh =3D (Schema) schemas.get(targetNamespace); - setParser(); + XSISAXHandler contentHandler =3D parseSchema(is1, level); =20 - XSISAXHandler contentHandler =3D getSAXHandler(null); // no = uri - XSISAXHandler.setLogLevel(level); - - try { - parser.parse(is1, contentHandler); - } catch (IOException e) { - throw new SAXException(e); - } - sh =3D merge(sh, contentHandler.getSchema()); schemas.put(targetNamespace, sh); // over-write } - return (Schema) schemas.get(targetNamespace); } =20 + private XSISAXHandler parseSchema( InputStream is1, Level level ) th= rows SAXException { + setParser(); + + XSISAXHandler contentHandler =3D getSAXHandler(null); + XSISAXHandler.setLogLevel(level); + + try { + parser.parse(is1, contentHandler); + } catch (IOException e) { + throw new SAXException(e); + } + return contentHandler; + } + /* * Creates a new Schema from merging the two schemas passed in. for = instance * information, such as id, or version, s1 takes precedence. @@ -832,4 +840,5 @@ return Collections.EMPTY_MAP; } } + =20 } Added: geotools/branches/2.2.x/module/main/src/org/geotools/xml/XMLHandle= rHints.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- geotools/branches/2.2.x/module/main/src/org/geotools/xml/XMLHandlerHi= nts.java 2006-07-26 22:43:18 UTC (rev 20729) +++ geotools/branches/2.2.x/module/main/src/org/geotools/xml/XMLHandlerHi= nts.java 2006-07-27 08:10:49 UTC (rev 20730) @@ -0,0 +1,86 @@ +package org.geotools.xml; + +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; +import java.util.Set; + +/** + * Hint object with known parameters for XML parsing. + *=20 + * @author Jesse + */ +public class XMLHandlerHints implements Map { + + /**=20 + * Declares the schemas to use for parsing. =20 + * Value must be a java.util.Map of <String,URI> objects + * where String is the Namespace and URI is the URL to use to load t= he schema.=20 + */ + public static final String NAMESPACE_MAPPING =3D "NAMESPACE_MAPPING"= ; + /** Declares a FlowHandler for the parser to use */ + public final static String FLOW_HANDLER_HINT =3D "FLOW_HANDLER_HINT"= ; + /** Tells the parser to "Stream" */ + public static final String STREAM_HINT =3D "org.geotools.xml.gml.STR= EAM_HINT"; + + private Map map=3Dnew HashMap(); + public void clear() { + map.clear(); + } + + public boolean containsKey( Object key ) { + return map.containsKey(key); + } + + public boolean containsValue( Object value ) { + return map.containsValue(value); + } + + public Set entrySet() { + return map.entrySet(); + } + + public boolean equals( Object o ) { + return map.equals(o); + } + + public Object get( Object key ) { + return map.get(key); + } + + public int hashCode() { + return map.hashCode(); + } + + public boolean isEmpty() { + return map.isEmpty(); + } + + public Set keySet() { + return map.keySet(); + } + + public Object put( Object arg0, Object arg1 ) { + return map.put(arg0, arg1); + } + + public void putAll( Map arg0 ) { + map.putAll(arg0); + } + + public Object remove( Object key ) { + return map.remove(key); + } + + public int size() { + return map.size(); + } + + public Collection values() { + return map.values(); + } + =20 + =20 + =20 + +} Modified: geotools/branches/2.2.x/module/main/src/org/geotools/xml/XMLSAX= Handler.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- geotools/branches/2.2.x/module/main/src/org/geotools/xml/XMLSAXHandle= r.java 2006-07-26 22:43:18 UTC (rev 20729) +++ geotools/branches/2.2.x/module/main/src/org/geotools/xml/XMLSAXHandle= r.java 2006-07-27 08:10:49 UTC (rev 20730) @@ -22,6 +22,7 @@ import java.net.URISyntaxException; import java.util.HashMap; import java.util.Iterator; +import java.util.List; import java.util.Map; import java.util.Stack; import java.util.logging.Level; @@ -33,6 +34,7 @@ import org.geotools.xml.handlers.DocumentHandler; import org.geotools.xml.handlers.ElementHandlerFactory; import org.geotools.xml.handlers.IgnoreHandler; +import org.geotools.xml.schema.Schema; import org.xml.sax.Attributes; import org.xml.sax.InputSource; import org.xml.sax.Locator; @@ -215,8 +217,8 @@ } =20 private void checkStatus() throws StopException { - if (this.hints !=3D null && hints.get(FlowHandler.FLOW_HANDLER_HINT) != =3D null) { - FlowHandler handler =3D (FlowHandler) hints.get(FlowHandler.FLOW_HAND= LER_HINT); + if (this.hints !=3D null && hints.get(XMLHandlerHints.FLOW_HANDLER_HIN= T) !=3D null) { + FlowHandler handler =3D (FlowHandler) hints.get(XMLHandlerHints.FLOW_= HANDLER_HINT); if (handler.shouldStop(hints)) { throw new StopException(); } @@ -297,15 +299,29 @@ String prefix =3D (String) schemaProxy.get(targ)= ; URI targUri =3D null; =20 - try { - targUri =3D (instanceDocument =3D=3D null) ?= new URI(uri) - : insta= nceDocument + + boolean set =3D false; + if (hints!=3Dnull && hints.containsKey(XMLHandle= rHints.NAMESPACE_MAPPING)){ + + Map schemas=3D(Map) hints.get(XMLHandlerHint= s.NAMESPACE_MAPPING); + =20 + if( schemas.containsKey(targ) ){ + ehf.startPrefixMapping(prefix, targ, (UR= I) schemas.get(targ)); + set=3Dtrue; + break; + } + } + =20 + if(!set){ + try { + targUri =3D (instanceDocument =3D=3D nul= l) ? new URI(uri) + : instanceDocument .resolve(uri); - } catch (URISyntaxException e1) { - logger.warning(e1.toString()); + } catch (URISyntaxException e1) { + logger.warning(e1.toString()); + } + ehf.startPrefixMapping(prefix, targ, targUri= ); } - - ehf.startPrefixMapping(prefix, targ, targUri); schemaProxy.remove(targ); } } @@ -319,7 +335,6 @@ String prefix =3D (String) schemaProxy.get(targ); ehf.startPrefixMapping(prefix, targ); =20 - // schemaProxy.remove(targ); it.remove(); } } Modified: geotools/branches/2.2.x/module/main/src/org/geotools/xml/gml/FC= Buffer.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- geotools/branches/2.2.x/module/main/src/org/geotools/xml/gml/FCBuffer= .java 2006-07-26 22:43:18 UTC (rev 20729) +++ geotools/branches/2.2.x/module/main/src/org/geotools/xml/gml/FCBuffer= .java 2006-07-27 08:10:49 UTC (rev 20730) @@ -21,6 +21,7 @@ import java.util.Calendar; import java.util.Date; import java.util.HashMap; +import java.util.Map; import java.util.NoSuchElementException; import java.util.logging.Level; import java.util.logging.Logger; @@ -29,7 +30,7 @@ import org.geotools.feature.Feature; import org.geotools.feature.FeatureType; import org.geotools.xml.DocumentFactory; -import org.geotools.xml.FlowHandler; +import org.geotools.xml.XMLHandlerHints; import org.xml.sax.SAXException; =20 =20 @@ -295,7 +296,11 @@ } =20 logger.finest("waiting for parser"); - Thread.yield(); + try { + Thread.sleep(200); + } catch (InterruptedException e) { + //just continue; + } =20 if (lastUpdate.before(new Date(Calendar.getInstance().getTim= eInMillis() - timeout))) { exception =3D new SAXException("Timeout"); @@ -342,12 +347,8 @@ * @see java.lang.Runnable#run() */ public void run() { - HashMap hints =3D new HashMap(); - hints.put(GMLComplexTypes.STREAM_HINT, this); - hints.put(FlowHandler.FLOW_HANDLER_HINT, new FCFlowHandler()); - if( this.ft!=3Dnull ){ - hints.put("DEBUG_INFO_FEATURE_TYPE_NAME", ft.getTypeName()); - } + XMLHandlerHints hints =3D new XMLHandlerHints(); + initHints(hints); try { DocumentFactory.getInstance(document, hints); =20 @@ -364,6 +365,17 @@ } =20 /** + * Called before parsing the FeatureCollection. Subclasses may over= ride to set their custom hints. =20 + */ + protected void initHints(XMLHandlerHints hints) { + hints.put(XMLHandlerHints.STREAM_HINT, this); + hints.put(XMLHandlerHints.FLOW_HANDLER_HINT, new FCFlowHandler()= ); + if( this.ft!=3Dnull ){ + hints.put("DEBUG_INFO_FEATURE_TYPE_NAME", ft.getTypeName()); + } + } + + /** * DOCUMENT ME! * * @author $author$ Modified: geotools/branches/2.2.x/module/main/src/org/geotools/xml/gml/FC= FlowHandler.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- geotools/branches/2.2.x/module/main/src/org/geotools/xml/gml/FCFlowHa= ndler.java 2006-07-26 22:43:18 UTC (rev 20729) +++ geotools/branches/2.2.x/module/main/src/org/geotools/xml/gml/FCFlowHa= ndler.java 2006-07-27 08:10:49 UTC (rev 20730) @@ -16,6 +16,8 @@ package org.geotools.xml.gml; =20 import org.geotools.xml.FlowHandler; +import org.geotools.xml.XMLHandlerHints; + import java.util.Map; =20 /** @@ -25,8 +27,8 @@ */ public class FCFlowHandler implements FlowHandler { public boolean shouldStop(Map hints) { - if ((hints !=3D null) && (hints.get(GMLComplexTypes.STREAM_HINT)= !=3D null)) { - FCBuffer buffer =3D (FCBuffer) hints.get(GMLComplexTypes.STR= EAM_HINT); + if ((hints !=3D null) && (hints.get(XMLHandlerHints.STREAM_HINT)= !=3D null)) { + FCBuffer buffer =3D (FCBuffer) hints.get(XMLHandlerHints.STR= EAM_HINT); =20 if (buffer.getInternalState() =3D=3D FCBuffer.STOP) { return true; Modified: geotools/branches/2.2.x/module/main/src/org/geotools/xml/gml/GM= LComplexTypes.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- geotools/branches/2.2.x/module/main/src/org/geotools/xml/gml/GMLCompl= exTypes.java 2006-07-26 22:43:18 UTC (rev 20729) +++ geotools/branches/2.2.x/module/main/src/org/geotools/xml/gml/GMLCompl= exTypes.java 2006-07-27 08:10:49 UTC (rev 20730) @@ -34,11 +34,13 @@ import org.geotools.feature.FeatureCollection; import org.geotools.feature.FeatureIterator; import org.geotools.feature.FeatureType; +import org.geotools.feature.FeatureTypeBuilder; import org.geotools.feature.FeatureTypeFactory; import org.geotools.feature.GeometryAttributeType; import org.geotools.feature.IllegalAttributeException; import org.geotools.feature.SchemaException; import org.geotools.xml.PrintHandler; +import org.geotools.xml.XMLHandlerHints; import org.geotools.xml.gml.FCBuffer.StopException; import org.geotools.xml.gml.GMLSchema.AttributeList; import org.geotools.xml.gml.GMLSchema.GMLAttribute; @@ -100,8 +102,6 @@ } =20 =20 - /** DOCUMENT ME! */ - public static final String STREAM_HINT =3D "org.geotools.xml.gml.STR= EAM_HINT"; private static final String STREAM_FEATURE_NAME_HINT =3D "org.geotoo= ls.xml.gml.STREAM_FEATURE_NAME_HINT"; =20 static void encode(Element e, Geometry g, PrintHandler output) @@ -4148,7 +4148,7 @@ public Object getValue(Element element, ElementValue[] value, Attributes attrs, Map hints) throws SAXException { =20 - if ((hints =3D=3D null) || (hints.get(STREAM_HINT) =3D=3D nu= ll)) { + if ((hints =3D=3D null) || (hints.get(XMLHandlerHints.STREAM= _HINT) =3D=3D null)) { return getFeature(element, value, attrs, hints, null); } =20 @@ -4159,8 +4159,8 @@ String nm =3D (String) hints.get(STREAM_FEATURE_NAME_HINT); Feature f; if ((nm !=3D null) && nm.equals(element.getName())) { - f =3D getFeature(element, value, attrs, hints, ((FCBuffe= r) hints.get(STREAM_HINT)).ft); - stream(f, (FCBuffer) hints.get(STREAM_HINT)); + f =3D getFeature(element, value, attrs, hints, ((FCBuffe= r) hints.get(XMLHandlerHints.STREAM_HINT)).ft); + stream(f, (FCBuffer) hints.get(XMLHandlerHints.STREAM_HI= NT)); =20 return null; } @@ -4557,11 +4557,11 @@ */ public Object getValue(Element element, ElementValue[] value, Attributes attrs, Map hints){ - if ((hints =3D=3D null) || (hints.get(STREAM_HINT) =3D=3D nu= ll)) { + if ((hints =3D=3D null) || (hints.get(XMLHandlerHints.STREAM= _HINT) =3D=3D null)) { return getCollection(attrs,value); } =20 - FCBuffer fcb =3D (FCBuffer) hints.get(STREAM_HINT); + FCBuffer fcb =3D (FCBuffer) hints.get(XMLHandlerHints.STREAM= _HINT); fcb.state =3D FCBuffer.FINISH; =20 return null; @@ -4572,7 +4572,7 @@ * java.util.Map) */ public boolean cache(Element element, Map hints) { - if ((hints =3D=3D null) || (hints.get(STREAM_HINT) =3D=3D nu= ll)) { + if ((hints =3D=3D null) || (hints.get(XMLHandlerHints.STREAM= _HINT) =3D=3D null)) { return true; } =20 @@ -6383,7 +6383,7 @@ URI ftNS =3D element.getType().getNamespace(); logger.finest("Creating feature type for " + ftName + ":" + ftNS= ); =20 - FeatureTypeFactory typeFactory =3D FeatureTypeFactory.newInstanc= e(ftName); + FeatureTypeBuilder typeFactory =3D FeatureTypeBuilder.newInstanc= e(ftName); typeFactory.setNamespace(ftNS); typeFactory.setName(ftName); =20 Modified: geotools/branches/2.2.x/plugin/wfs/src/org/geotools/data/ows/WF= SCapabilities.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- geotools/branches/2.2.x/plugin/wfs/src/org/geotools/data/ows/WFSCapab= ilities.java 2006-07-26 22:43:18 UTC (rev 20729) +++ geotools/branches/2.2.x/plugin/wfs/src/org/geotools/data/ows/WFSCapab= ilities.java 2006-07-27 08:10:49 UTC (rev 20730) @@ -66,7 +66,7 @@ if(name !=3Dnull){ int index =3D name.indexOf(':');=20 if(index!=3D-1 && typename.equals(name.substring(index+= 1))){ - =09 + return fsd; } } } Added: geotools/branches/2.2.x/plugin/wfs/src/org/geotools/data/wfs/LogWr= iterDecorator.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- geotools/branches/2.2.x/plugin/wfs/src/org/geotools/data/wfs/LogWrite= rDecorator.java 2006-07-26 22:43:18 UTC (rev 20729) +++ geotools/branches/2.2.x/plugin/wfs/src/org/geotools/data/wfs/LogWrite= rDecorator.java 2006-07-27 08:10:49 UTC (rev 20730) @@ -0,0 +1,45 @@ +package org.geotools.data.wfs; + +import java.io.IOException; +import java.io.Writer; +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * A decorator that writes to the log as well as the wrapped writer. + *=20 + * @author Jesse + * @since 1.1.0 + */ +public class LogWriterDecorator extends Writer { + + private Writer delegate; + private Level level; + + StringBuffer buffer=3Dnew StringBuffer();=20 + =20 + public LogWriterDecorator( Writer w, Level logLevel ) { + this.delegate=3Dw; + this.level=3DlogLevel; + } + + public void close() throws IOException { + delegate.close(); + Logger.getLogger("org.geotools.data.wfs").log(level, buffer.toSt= ring()); + buffer=3Dnew StringBuffer(); + } + + public void flush() throws IOException { + delegate.flush(); + Logger.getLogger("org.geotools.data.wfs").log(level, buffer.toSt= ring()); + buffer=3Dnew StringBuffer(); + } + + public void write( char[] cbuf, int off, int len ) throws IOExceptio= n { + char[] msg =3D new char[len]; + System.arraycopy(cbuf, off, msg, 0, len); + buffer.append(msg); + delegate.write(cbuf, off, len); + } + +} \ No newline at end of file Modified: geotools/branches/2.2.x/plugin/wfs/src/org/geotools/data/wfs/WF= SDataStore.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- geotools/branches/2.2.x/plugin/wfs/src/org/geotools/data/wfs/WFSDataS= tore.java 2006-07-26 22:43:18 UTC (rev 20729) +++ geotools/branches/2.2.x/plugin/wfs/src/org/geotools/data/wfs/WFSDataS= tore.java 2006-07-27 08:10:49 UTC (rev 20730) @@ -29,6 +29,7 @@ import java.net.MalformedURLException; import java.net.PasswordAuthentication; import java.net.URI; +import java.net.URISyntaxException; import java.net.URL; import java.net.URLEncoder; import java.util.HashMap; @@ -36,6 +37,7 @@ import java.util.List; import java.util.Map; import java.util.logging.Level; +import java.util.logging.Logger; import java.util.zip.GZIPInputStream; =20 import javax.naming.OperationNotSupportedException; @@ -51,6 +53,7 @@ import org.geotools.data.crs.ForceCoordinateSystemFeatureReader; import org.geotools.data.ows.FeatureSetDescription; import org.geotools.data.ows.WFSCapabilities; +import org.geotools.data.wfs.Action.DeleteAction; import org.geotools.feature.FeatureType; import org.geotools.feature.FeatureTypeBuilder; import org.geotools.feature.FeatureTypes; @@ -252,6 +255,8 @@ =20 private Map fidMap=3Dnew HashMap(); =20 + private Map xmlSchemaCache=3Dnew HashMap(); + /** * @see org.geotools.data.AbstractDataStore#getTypeNames() */ @@ -285,7 +290,7 @@ =20 // TODO sanity check for request with capabilities obj =20 - FeatureType t =3D null; + FeatureType t=3Dnull; SAXException sax =3D null; IOException io =3D null; if (((protocol & POST_PROTOCOL) =3D=3D POST_PROTOCOL) && (t =3D=3D= null)) { @@ -342,21 +347,42 @@ if(ftName!=3Dnull){ try { t =3D FeatureTypeBuilder.newFeatureType(t.getAttributeTypes= (),ftName=3D=3Dnull?typeName:ftName,t.getNamespace(),t.isAbstract(),t.get= Ancestors(),t.getDefaultGeometry()); + =20 } catch (SchemaException e1) { WFSDataStoreFactory.logger.warning(e1.getMessage()); } } - + try{ + URL url =3D getDescribeFeatureTypeURLGet(typeName); + if( url!=3Dnull ) + t=3Dnew WFSFeatureType(t, new URI(url.toString())); + }catch (URISyntaxException e) { + throw (RuntimeException) new RuntimeException( e ); + } if (t !=3D null) { featureTypeCache.put(typeName, t); } =20 return t; } - =20 + // protected for testing protected FeatureType getSchemaGet(String typeName) throws SAXException, IOException { + URL getUrl =3D getDescribeFeatureTypeURLGet(typeName); + HttpURLConnection hc =3D getConnection(getUrl,auth,false); + + InputStream is =3D getInputStream(hc); + Schema schema; + try{ + schema =3D SchemaFactory.getInstance(null, is); + }finally{ + is.close(); + } + return parseDescribeFeatureTypeResponse(typeName, schema); + } + + private URL getDescribeFeatureTypeURLGet( String typeName ) throws M= alformedURLException { URL getUrl =3D capabilities.getDescribeFeatureType().getGet(); =20 if (getUrl =3D=3D null) { @@ -390,22 +416,27 @@ url +=3D ("&TYPENAME=3D" + typeName); =20 getUrl =3D new URL(url); - HttpURLConnection hc =3D getConnection(getUrl,auth,false); + return getUrl; + } =20 - InputStream is =3D getInputStream(hc); - Schema schema =3D SchemaFactory.getInstance(null, is); + static FeatureType parseDescribeFeatureTypeResponse( String typeName= , Schema schema ) throws SAXException { Element[] elements =3D schema.getElements(); + + if (elements =3D=3D null) { + return null; // not found + } + Element element =3D null; =20 String ttname =3D typeName.substring(typeName.indexOf(":") + 1); =20 - for (int i =3D 0; (i < elements.length) && (element =3D=3D null)= ; i++) - + for (int i =3D 0; (i < elements.length) && (element =3D=3D null)= ; i++) { // HACK -- namspace related -- should be checking ns as oppo= sed to removing prefix if (typeName.equals(elements[i].getName()) || ttname.equals(elements[i].getName())) { element =3D elements[i]; } + } =20 if (element =3D=3D null) { return null; @@ -413,6 +444,7 @@ =20 FeatureType ft =3D GMLComplexTypes.createFeatureType(element); =20 + return ft; } =20 @@ -455,34 +487,14 @@ osw.close(); =20 InputStream is =3D getInputStream(hc); - Schema schema =3D SchemaFactory.getInstance(null, is); - Element[] elements =3D schema.getElements(); - - if (elements =3D=3D null) { - return null; // not found + Schema schema; + try{ + schema =3D SchemaFactory.getInstance(null, is); + }finally{ + is.close(); } =20 - Element element =3D null; - - String ttname =3D typeName.substring(typeName.indexOf(":") + 1); - - for (int i =3D 0; (i < elements.length) && (element =3D=3D null)= ; i++) { - // HACK -- namspace related -- should be checking ns as oppo= sed to removing prefix - if (typeName.equals(elements[i].getName()) - || ttname.equals(elements[i].getName())) { - element =3D elements[i]; - } - } - - if (element =3D=3D null) { - return null; - } - - FeatureType ft =3D GMLComplexTypes.createFeatureType(element); - - is.close(); - - return ft; + return parseDescribeFeatureTypeResponse(typeName, schema); } =20 // protected for testing @@ -552,6 +564,8 @@ =20 url +=3D ("&TYPENAME=3D" + URLEncoder.encode(request.getTypeName= (), "UTF-8")); =20 + Logger.getLogger("org.geotools.data.wfs").fine(url); + =20 getUrl =3D new URL(url); HttpURLConnection hc =3D getConnection(getUrl,auth,false); =20 @@ -568,7 +582,7 @@ } =20 WFSFeatureReader ft =3D WFSFeatureReader.getFeatureReader(is, bu= fferSize, - timeout, ts, getSchema(request.getTypeName())); + timeout, ts, (WFSFeatureType)getSchema(request.getTypeNa= me())); =20 return ft; } @@ -669,6 +683,9 @@ =20 // write request Writer w =3D new OutputStreamWriter(os); + if( Logger.getLogger("org.geotools.data.wfs").isLoggable(Level.F= INE) ){ + w=3Dnew LogWriterDecorator(w, Level.FINE); + } Map hints =3D new HashMap(); hints.put(DocumentWriter.BASE_ELEMENT, WFSSchema.getInstance().getElements()[2]); // GetFeature @@ -699,7 +716,7 @@ } =20 WFSFeatureReader ft =3D WFSFeatureReader.getFeatureReader(is, bu= fferSize, - timeout, ts, getSchema(query.getTypeName())); + timeout, ts, (WFSFeatureType)getSchema(query.getTypeName= ())); =20 return ft; } @@ -991,5 +1008,6 @@ throw new NullPointerException(); fidMap.put(original, finalFid); } + } =20 Modified: geotools/branches/2.2.x/plugin/wfs/src/org/geotools/data/wfs/WF= SFeatureReader.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- geotools/branches/2.2.x/plugin/wfs/src/org/geotools/data/wfs/WFSFeatu= reReader.java 2006-07-26 22:43:18 UTC (rev 20729) +++ geotools/branches/2.2.x/plugin/wfs/src/org/geotools/data/wfs/WFSFeatu= reReader.java 2006-07-27 08:10:49 UTC (rev 20730) @@ -21,9 +21,11 @@ import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.URI; +import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import java.util.List; +import java.util.Map; import java.util.NoSuchElementException; =20 import org.geotools.data.FeatureReader; @@ -33,8 +35,8 @@ import org.geotools.feature.FeatureType; import org.geotools.feature.IllegalAttributeException; import org.geotools.xml.DocumentFactory; +import org.geotools.xml.XMLHandlerHints; import org.geotools.xml.gml.FCBuffer; -import org.geotools.xml.gml.GMLComplexTypes; import org.xml.sax.SAXException; =20 =20 @@ -53,7 +55,7 @@ private int insertSearchIndex =3D -1; =20 private WFSFeatureReader(InputStream is, int capacity, int timeout, - WFSTransactionState trans, FeatureType ft) { + WFSTransactionState trans, WFSFeatureType ft) { //document may be null super(null, capacity, timeout,ft); this.is =3D is; @@ -71,14 +73,14 @@ * @throws SAXException */ public static FeatureReader getFeatureReader(URI document, int capac= ity, - int timeout, WFSTransactionState transaction, FeatureType ft) th= rows SAXException { + int timeout, WFSTransactionState transaction, WFSFeatureType ft)= throws SAXException { HttpURLConnection hc; =20 try { hc =3D (HttpURLConnection) document.toURL().openConnection()= ; =20 return getFeatureReader(hc.getInputStream(), capacity, timeo= ut, - transaction,ft); + transaction, ft); } catch (MalformedURLException e) { logger.warning(e.toString()); throw new SAXException(e); @@ -99,10 +101,10 @@ * @throws SAXException */ public static WFSFeatureReader getFeatureReader(InputStream is, - int capacity, int timeout, WFSTransactionState transaction, Feat= ureType ft) + int capacity, int timeout, WFSTransactionState transaction, WFSF= eatureType ft) throws SAXException { WFSFeatureReader fc =3D new WFSFeatureReader(is, capacity, timeo= ut, - transaction,ft); + transaction, ft); fc.start(); // calls run =20 if (fc.exception !=3D null) { @@ -116,8 +118,8 @@ * @see java.lang.Runnable#run() */ public void run() { - HashMap hints =3D new HashMap(); - hints.put(GMLComplexTypes.STREAM_HINT, this); + XMLHandlerHints hints =3D new XMLHandlerHints(); + initHints(hints); =20 try { try { @@ -141,6 +143,17 @@ } } =20 + protected void initHints( XMLHandlerHints hints ) { + super.initHints(hints); + + if( ft instanceof WFSFeatureType){ + Map schemas=3Dnew HashMap(1); + WFSFeatureType wfsFT=3D(WFSFeatureType) ft; + schemas.put(wfsFT.getNamespace().toString(), wfsFT.getSchema= URI()); + hints.put(XMLHandlerHints.NAMESPACE_MAPPING, schemas); + } + } + =20 /** *=20 * @see org.geotools.data.FeatureReader#hasNext() Added: geotools/branches/2.2.x/plugin/wfs/src/org/geotools/data/wfs/WFSFe= atureType.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- geotools/branches/2.2.x/plugin/wfs/src/org/geotools/data/wfs/WFSFeatu= reType.java 2006-07-26 22:43:18 UTC (rev 20729) +++ geotools/branches/2.2.x/plugin/wfs/src/org/geotools/data/wfs/WFSFeatu= reType.java 2006-07-27 08:10:49 UTC (rev 20730) @@ -0,0 +1,125 @@ +/* uDig - User Friendly Desktop Internet GIS client + * http://udig.refractions.net + * (C) 2004, Refractions Research Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + */ +package org.geotools.data.wfs; + +import java.net.URI; + +import org.geotools.feature.AttributeType; +import org.geotools.feature.Feature; +import org.geotools.feature.FeatureType; +import org.geotools.feature.GeometryAttributeType; +import org.geotools.feature.IllegalAttributeException; + +/** + * A FeatureType that adds the information about the XMLSchema used to c= reate the FeatureType. =20 + * @author Jesse + * @since 1.1.0 + */ +class WFSFeatureType implements FeatureType { + FeatureType delegate; + private URI schemaURI; + + public WFSFeatureType( FeatureType delegate, URI schemaURI ) { + this.delegate =3D delegate; + this.schemaURI=3DschemaURI; + } + + public Feature create( Object[] attributes, String featureID ) throw= s IllegalAttributeException { + return delegate.create(attributes, featureID); + } + + public Feature create( Object[] attributes ) throws IllegalAttribute= Exception { + return delegate.create(attributes); + } + + public Feature duplicate( Feature feature ) throws IllegalAttributeE= xception { + return delegate.duplicate(feature); + } + + public boolean equals( Object arg0 ) { + if( !(arg0 instanceof WFSFeatureType) ) + return false; + WFSFeatureType ft=3D(WFSFeatureType) arg0; + return delegate.equals(ft.delegate); + } + + public int find( AttributeType type ) { + return delegate.find(type); + } + + public int find( String attName ) { + return delegate.find(attName); + } + + public FeatureType[] getAncestors() { + return delegate.getAncestors(); + } + + public int getAttributeCount() { + return delegate.getAttributeCount(); + } + + public AttributeType getAttributeType( int position ) { + return delegate.getAttributeType(position); + } + + public AttributeType getAttributeType( String xPath ) { + return delegate.getAttributeType(xPath); + } + + public AttributeType[] getAttributeTypes() { + return delegate.getAttributeTypes(); + } + + public GeometryAttributeType getDefaultGeometry() { + return delegate.getDefaultGeometry(); + } + + public URI getNamespace() { + return delegate.getNamespace(); + } + + public String getTypeName() { + return delegate.getTypeName(); + } + + public boolean hasAttributeType( String xPath ) { + return delegate.hasAttributeType(xPath); + } + + public int hashCode() { + return delegate.hashCode(); + } + + public boolean isAbstract() { + return delegate.isAbstract(); + } + + public boolean isDescendedFrom( FeatureType type ) { + return delegate.isDescendedFrom(type); + } + + public boolean isDescendedFrom( URI nsURI, String typeName ) { + return delegate.isDescendedFrom(nsURI, typeName); + } + + public URI getSchemaURI() { + return schemaURI; + } + =20 + public String toString() { + return delegate.toString(); + } +} Modified: geotools/branches/2.2.x/plugin/wfs/src/org/geotools/data/wfs/WF= STransactionState.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- geotools/branches/2.2.x/plugin/wfs/src/org/geotools/data/wfs/WFSTrans= actionState.java 2006-07-26 22:43:18 UTC (rev 20729) +++ geotools/branches/2.2.x/plugin/wfs/src/org/geotools/data/wfs/WFSTrans= actionState.java 2006-07-27 08:10:49 UTC (rev 20730) @@ -220,10 +220,13 @@ =20 // write request Writer w =3D new OutputStreamWriter(os); + if( Logger.getLogger("org.geotools.data.wfs").isLoggable(Level.F= INE) ){ + w=3Dnew LogWriterDecorator(w, Level.FINE); + } =20 DocumentWriter.writeDocument(this, WFSSchema.getInstance(), w, h= ints); - os.flush(); - os.close(); + w.flush(); + w.close(); =20 InputStream is =3D this.ds.getInputStream(hc); =20 |