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;
006:
007: import org.eclipse.xsd.XSDAttributeDeclaration;
008: import org.eclipse.xsd.XSDElementDeclaration;
009: import org.eclipse.xsd.XSDSchema;
010: import org.geotools.xml.impl.AttributeHandler;
011: import org.geotools.xml.impl.DocumentHandler;
012: import org.geotools.xml.impl.ElementHandler;
013: import org.geotools.xml.impl.ElementHandlerImpl;
014: import org.geotools.xml.impl.Handler;
015: import org.geotools.xml.impl.HandlerFactory;
016: import org.geotools.xml.impl.ParserHandler;
017: import org.vfny.geoserver.global.Data;
018: import org.vfny.geoserver.global.FeatureTypeInfo;
019: import java.io.IOException;
020: import java.util.Iterator;
021: import java.util.logging.Level;
022: import java.util.logging.Logger;
023: import javax.xml.namespace.QName;
024:
025: /**
026: * Special handler factory which creates handlers for elements which are
027: * defined as wfs feature types.
028: *
029: * @author Justin Deoliveira, The Open Planning Project
030: *
031: */
032: public class WFSHandlerFactory implements HandlerFactory {
033: static Logger logger = org.geotools.util.logging.Logging
034: .getLogger("org.geoserver.wfs");
035:
036: /**
037: * Catalog reference
038: */
039: Data catalog;
040:
041: /**
042: * Schema Builder
043: */
044: FeatureTypeSchemaBuilder schemaBuilder;
045:
046: public WFSHandlerFactory(Data catalog,
047: FeatureTypeSchemaBuilder schemaBuilder) {
048: this .catalog = catalog;
049: this .schemaBuilder = schemaBuilder;
050: }
051:
052: public DocumentHandler createDocumentHandler(ParserHandler parser) {
053: return null;
054: }
055:
056: public ElementHandler createElementHandler(QName name,
057: Handler parent, ParserHandler parser) {
058: String namespaceURI = name.getNamespaceURI();
059:
060: if (namespaceURI == null) {
061: //assume default
062: namespaceURI = catalog.getDefaultNameSpace().getURI();
063: }
064:
065: try {
066: //look for a FeatureType
067: FeatureTypeInfo meta = catalog.getFeatureTypeInfo(name
068: .getLocalPart(), namespaceURI);
069:
070: if (meta != null) {
071: //found it
072: XSDSchema schema = schemaBuilder.build(meta, null);
073:
074: for (Iterator e = schema.getElementDeclarations()
075: .iterator(); e.hasNext();) {
076: XSDElementDeclaration element = (XSDElementDeclaration) e
077: .next();
078:
079: if (name.getLocalPart().equals(element.getName())) {
080: return new ElementHandlerImpl(element, parent,
081: parser);
082: }
083: }
084: }
085: } catch (IOException e) {
086: logger.log(Level.WARNING, "Error building schema", e);
087: }
088:
089: return null;
090: }
091:
092: public ElementHandler createElementHandler(XSDElementDeclaration e,
093: Handler parent, ParserHandler parser) {
094: return null;
095: }
096:
097: public AttributeHandler createAttributeHandler(
098: XSDAttributeDeclaration a, Handler parent,
099: ParserHandler parser) {
100: return null;
101: }
102: }
|