Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
  • 3 commits
  • 9 files changed
  • 0 commit comments
  • 1 contributor
View
6 ...process-wps/src/main/java/gov/usgs/cida/gdp/wps/parser/GMLStreamingFeatureCollection.java
@@ -1,7 +1,7 @@
package gov.usgs.cida.gdp.wps.parser;
import gov.usgs.cida.gdp.wps.util.GMLUtil;
-import gov.usgs.cida.gdp.wps.util.xml.GDPFeatureParser;
+import org.geotools.xml.PullParser;
import java.io.BufferedInputStream;
import java.io.File;
@@ -274,7 +274,7 @@ private SimpleFeature wrap(SimpleFeature base) {
private final class StreamingFeatureIterator implements FeatureIterator<Feature>, Iterator<Feature> {
- private GDPFeatureParser parser;
+ private PullParser parser;
private InputStream bufferedInputStream;
private InputStream fileInputStream;
private Filter filter;
@@ -298,7 +298,7 @@ private StreamingFeatureIterator(Filter filter, boolean wrap) throws ParserConfi
Configuration newConfiguration = GMLUtil.generateGMLConfiguration(file);
- parser = new GDPFeatureParser(
+ parser = new PullParser(
newConfiguration,
bufferedInputStream,
SimpleFeature.class);
View
129 gdp-process-wps/src/main/java/gov/usgs/cida/gdp/wps/util/xml/GDPDelegatingHandler.java
@@ -1,129 +0,0 @@
-package gov.usgs.cida.gdp.wps.util.xml;
-
-
-import javax.xml.namespace.QName;
-
-import org.eclipse.xsd.XSDElementDeclaration;
-import org.eclipse.xsd.XSDFactory;
-import org.eclipse.xsd.XSDSchemaContent;
-import org.geotools.xml.ElementInstance;
-import org.geotools.xml.InstanceComponent;
-import org.geotools.xml.Node;
-import org.geotools.xml.ParserDelegate;
-import org.geotools.xml.impl.DocumentHandler;
-import org.geotools.xml.impl.ElementHandler;
-import org.geotools.xml.impl.ElementImpl;
-import org.geotools.xml.impl.Handler;
-import org.geotools.xml.impl.NodeImpl;
-import org.picocontainer.MutablePicoContainer;
-import org.xml.sax.Attributes;
-import org.xml.sax.SAXException;
-
-/**
- *
- *
- * @source $URL$
- */
-public class GDPDelegatingHandler implements DocumentHandler, ElementHandler {
-
- ParserDelegate delegate;
- Handler parent;
- QName elementName;
- NodeImpl parseTree;
-
- GDPDelegatingHandler( ParserDelegate delegate, QName elementName, Handler parent) {
- this.delegate = delegate;
- this.parent = parent;
- this.elementName = elementName;
-
- //create a parse tree
- XSDElementDeclaration e = XSDFactory.eINSTANCE.createXSDElementDeclaration();
- e.setTargetNamespace( elementName.getNamespaceURI() );
- e.setName( elementName.getLocalPart() );
-
- ElementImpl instance = new ElementImpl( e );
- instance.setName( elementName.getLocalPart() );
- instance.setNamespace( elementName.getNamespaceURI() );
-
- parseTree = new NodeImpl( instance );
- }
-
- public void setContext(MutablePicoContainer context) {
- }
-
- public MutablePicoContainer getContext() {
- return null;
- }
-
-
- public XSDElementDeclaration getElementDeclaration() {
- return ((ElementInstance)parseTree.getComponent()).getElementDeclaration();
- }
-
- public Handler getParentHandler() {
- return parent;
- }
-
- public Handler createChildHandler(QName name) {
- return new GDPDelegatingHandler( delegate, name, this );
- }
-
- public void startChildHandler(Handler child) {
- }
-
- public void endChildHandler(Handler child) {
- }
-
- public InstanceComponent getComponent() {
- return null;
- }
-
- public Node getParseNode() {
- return parseTree;
- }
-
- public XSDSchemaContent getSchemaContent() {
- return null;
- }
-
- public void startDocument() throws SAXException {
- delegate.startDocument();
- }
-
- public void endDocument() throws SAXException {
- delegate.endDocument();
- }
-
- @Override
- public void startPrefixMapping(String prefix, String uri) throws SAXException {
- delegate.startPrefixMapping(prefix, uri);
- }
-
- public void startElement(QName name, Attributes attributes)
- throws SAXException {
-
- if ( !( parent instanceof GDPDelegatingHandler ) ) {
- parent.startChildHandler( this );
- }
-
- delegate.startElement(name.getNamespaceURI(), name.getLocalPart(),
- qname(name) , attributes);
- }
-
- public void characters(char[] ch, int start, int length)
- throws SAXException {
- delegate.characters( ch, start, length );
- }
-
- public void endElement(QName name) throws SAXException {
- delegate.endElement( name.getNamespaceURI(), name.getLocalPart(), qname( name ) );
- }
-
- public void endPrefixMapping(String prefix) throws SAXException {
- delegate.endPrefixMapping(prefix);
- }
-
- String qname( QName name ) {
- return name.getNamespaceURI() != null ? name.getPrefix() + ":" + name.getLocalPart() : name.getLocalPart();
- }
-}
View
98 gdp-process-wps/src/main/java/gov/usgs/cida/gdp/wps/util/xml/GDPDocumentHandlerImpl.java
@@ -1,98 +0,0 @@
-package gov.usgs.cida.gdp.wps.util.xml;
-
-import javax.xml.namespace.QName;
-
-import org.eclipse.xsd.XSDSchemaContent;
-import org.geotools.xml.InstanceComponent;
-import org.geotools.xml.Node;
-import org.geotools.xml.impl.DocumentHandler;
-import org.geotools.xml.impl.Handler;
-import org.geotools.xml.impl.HandlerImpl;
-
-
-/**
- *
- *
- * @source $URL$
- */
-public class GDPDocumentHandlerImpl extends HandlerImpl implements DocumentHandler {
- /** factory used to create a handler for the root element **/
- GDPHandlerFactory factory;
-
- /** root node of the parse tree */
- Node tree;
-
- //ElementHandler handler;
-
- /** the parser */
- GDPParserHandler parser;
-
- public GDPDocumentHandlerImpl(GDPHandlerFactory factory, GDPParserHandler parser) {
- this.factory = factory;
- this.parser = parser;
- }
-
- public XSDSchemaContent getSchemaContent() {
- return null;
- }
-
- public InstanceComponent getComponent() {
- return null;
- }
-
- public Object getValue() {
- //jsut return the root of the parse tree's value
- if (tree != null) {
- return tree.getValue();
- }
-
- // //just return the root handler value
- // if (handler != null) {
- // return handler.getValue();
- // }
- return null;
- }
-
- public Node getParseNode() {
- return tree;
- }
-
- public Handler createChildHandler(QName qName) {
- return factory.createElementHandler(qName, this, parser);
- }
-
- // public List getChildHandlers() {
- // if ( handler == null ) {
- // return Collections.EMPTY_LIST;
- // }
- //
- // ArrayList list = new ArrayList();
- // list.add( handler );
- //
- // return list;
- // }
- public void startChildHandler(Handler child) {
- this.tree = child.getParseNode();
-
- //this.handler = (ElementHandler) child;
- }
-
- public void endChildHandler(Handler child) {
- //this.handler = null;
- }
-
- public Handler getParentHandler() {
- //always null, this is the root handler
- return null;
- }
-
- // public ElementHandler getDocumentElementHandler() {
- // return handler;
- // }
-
- public void startDocument() {
- }
-
- public void endDocument() {
- }
-}
View
369 gdp-process-wps/src/main/java/gov/usgs/cida/gdp/wps/util/xml/GDPElementHandlerImpl.java
@@ -1,369 +0,0 @@
-package gov.usgs.cida.gdp.wps.util.xml;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.logging.Level;
-
-import javax.xml.namespace.QName;
-
-import org.eclipse.xsd.XSDAttributeDeclaration;
-import org.eclipse.xsd.XSDComplexTypeDefinition;
-import org.eclipse.xsd.XSDElementDeclaration;
-import org.eclipse.xsd.XSDFactory;
-import org.eclipse.xsd.XSDSchemaContent;
-import org.eclipse.xsd.XSDSimpleTypeDefinition;
-import org.eclipse.xsd.XSDTypeDefinition;
-import org.eclipse.xsd.util.XSDConstants;
-import org.eclipse.xsd.util.XSDUtil;
-import org.geotools.xml.AttributeInstance;
-import org.geotools.xml.Binding;
-import org.geotools.xml.ElementInstance;
-import org.geotools.xml.InstanceComponent;
-import org.geotools.xml.Node;
-import org.geotools.xml.SchemaIndex;
-import org.geotools.xml.Schemas;
-import org.geotools.xml.Text;
-import org.geotools.xml.TextInstance;
-import org.geotools.xml.impl.AttributeImpl;
-import org.geotools.xml.impl.BindingFactoryImpl;
-import org.geotools.xml.impl.ContextInitializer;
-import org.geotools.xml.impl.ElementHandler;
-import org.geotools.xml.impl.ElementImpl;
-import org.geotools.xml.impl.ElementInitializer;
-import org.geotools.xml.impl.Handler;
-import org.geotools.xml.impl.HandlerImpl;
-import org.geotools.xml.impl.NodeImpl;
-import org.geotools.xml.impl.ParseExecutor;
-import org.geotools.xml.impl.ParserHandler;
-import org.picocontainer.defaults.DefaultPicoContainer;
-import org.xml.sax.Attributes;
-import org.xml.sax.SAXException;
-
-
-/**
- *
- *
- * @source $URL$
- */
-public class GDPElementHandlerImpl extends HandlerImpl implements ElementHandler {
- /** parent handler **/
- Handler parent;
-
- /** the element declaration **/
- XSDElementDeclaration content;
-
- /** the element instance **/
- ElementImpl element;
-
- /** the running parser */
- GDPParserHandler parser;
-
- /** the element type strategy **/
- Binding strategy;
-
- /** child handlers **/
- //ArrayList childHandlers;
-
- /** parse tree for the element **/
- NodeImpl node;
-
- /** parsed value **/
- Object value;
-
- public GDPElementHandlerImpl(XSDElementDeclaration content, Handler parent, GDPParserHandler parser) {
- this.content = content;
- this.parent = parent;
- this.parser = parser;
-
- //childHandlers = new ArrayList();
- }
-
- public void startElement(QName qName, Attributes attributes)
- throws SAXException {
- //clear handler list
- //childHandlers.clear();
-
- //create the attributes
- List atts = new ArrayList();
-
- for (int i = 0; i < attributes.getLength(); i++) {
- String rawAttQName = attributes.getQName(i);
-
- if (rawAttQName != null) {
- //ignore namespace declarations
- if (rawAttQName.startsWith("xmlns:")) {
- continue;
- }
-
- //ignore xsi:schemaLocation
- if (rawAttQName.endsWith("schemaLocation")) {
- String prefix = "";
-
- if (rawAttQName.indexOf(':') != -1) {
- prefix = rawAttQName.substring(0, rawAttQName.indexOf(':'));
- }
-
- String uri = parser.getNamespaceSupport().getURI(prefix);
-
- if ((uri != null) && uri.equals(XSDConstants.SCHEMA_INSTANCE_URI_2001)) {
- continue;
- }
- }
- }
-
- // String qName = attributes.getQName(i);
- //
- //
- // //ignore schema location attribute
- // if ( attributes.getQName(i) != null && attributes.getQName(index))
- //
- String uri = attributes.getURI(i);
- String name = attributes.getLocalName(i);
-
- QName attQName = new QName(uri, name);
-
- XSDAttributeDeclaration decl = Schemas.getAttributeDeclaration(content, attQName);
-
- if (decl == null) {
- //check wether unknown attributes should be parsed
- if (!parser.isStrict()) {
- if (parser.getLogger().isLoggable(Level.FINE)) {
- parser.getLogger().fine("Parsing unknown attribute: " + attQName);
- }
-
- //create a mock attribute and continue
- decl = XSDFactory.eINSTANCE.createXSDAttributeDeclaration();
- decl.setName(attQName.getLocalPart());
- decl.setTargetNamespace(attQName.getNamespaceURI());
-
- //set the type to be of string
- XSDSimpleTypeDefinition type = (XSDSimpleTypeDefinition) XSDUtil.getSchemaForSchema(XSDUtil.SCHEMA_FOR_SCHEMA_URI_2001)
- .getSimpleTypeIdMap()
- .get("string");
-
- decl.setTypeDefinition(type);
- }
- }
-
- //TODO: validate, if there is no declaration for an attribute, then
- //TODO: make sure no required attributes are missing
- // validation should fail, this is being side stepped for now until
- // a good way of handling the namespace attributes on the root
- // element, for now we just ignore attributes we dont find in the
- // schema
- if (decl != null) {
- AttributeInstance att = new AttributeImpl(decl);
- att.setNamespace(decl.getTargetNamespace());
- att.setName(decl.getName());
- att.setText(attributes.getValue(i));
-
- atts.add(att);
- } else {
- parser.getLogger().warning("Could not find attribute declaration: " + attQName);
- }
- }
-
- //create the element
- element = new ElementImpl(content);
- element.setNamespace(qName.getNamespaceURI());
- element.setName(qName.getLocalPart());
- element.setAttributes((AttributeInstance[]) atts.toArray(new AttributeInstance[atts.size()]));
-
- //create the parse tree for the node
- node = new NodeImpl(element);
-
- //parse the attributes
- for (int i = 0; i < element.getAttributes().length; i++) {
- AttributeInstance attribute = element.getAttributes()[i];
- GDPParseExecutor executor = new GDPParseExecutor(attribute, null, parent.getContext(), parser);
-
- parser.getBindingWalker()
- .walk(attribute.getAttributeDeclaration(), executor, parent.getContext());
-
- Object parsed = executor.getValue();
- node.addAttribute(new NodeImpl(attribute, parsed));
- }
-
-
- // trigger the leading edge initialize callback
- ElementInitializer initer = new ElementInitializer(element, node, parent.getContext());
- parser.getBindingWalker().walk(element.getElementDeclaration(), initer, container(), parent.getContext());
-
- //create context for children
- //TODO: this should only be done if the element is complex, this class
- // needs to be split into two, one for complex, other for simple
- setContext(new DefaultPicoContainer(parent.getContext()));
-
- //set the context on the binding factory
- ((BindingFactoryImpl) parser.getBindingFactory()).setContext(getContext());
-
- //"start" the child handler
- parent.startChildHandler(this);
-
- // ContextInitializer initer = new ContextInitializer(element, node,
- // getContext());
- // parser.getBindingWalker().walk(element .getElementDeclaration(), initer, getContext() );
- }
-
- public void characters(char[] ch, int start, int length)
- throws SAXException {
-
- //simply add the text to the element
- element.addText(ch, start, length);
-
- if (isMixed()) {
- String text = new String(ch, start, length);
- node.addChild(new NodeImpl(TextInstance.INSTANCE, new Text(text)));
- }
- }
-
- public void endElement(QName qName) throws SAXException {
- if (isMixed()) {
- ((NodeImpl)node).collapseWhitespace();
- }
-
- GDPParseExecutor executor = new GDPParseExecutor(element, node, getParentHandler().getContext(),
- parser);
- parser.getBindingWalker()
- .walk(element.getElementDeclaration(), executor, container(),
- getParentHandler().getContext());
-
- //cache the parsed value
- value = executor.getValue();
-
- if (value == null) {
- //TODO: instead of continuuing, just remove the element from
- // the parent, or figure out if the element is 'optional' and
- // remove
- if (parser.getLogger().isLoggable(Level.FINE)) {
- parser.getLogger().fine("Binding for " + element.getName() + " returned null");
- }
- }
-
- //set the value for this node in the parse tree
- node.setValue(value);
-
- //end this child handler
- parent.endChildHandler(this);
-
- //kill the context
- parent.getContext().removeChildContainer(getContext());
- }
-
- public Handler createChildHandler(QName qName) {
- return getChildHandlerInternal(qName);
- }
-
- private Handler getChildHandlerInternal(QName qName) {
- SchemaIndex index = parser.getSchemaIndex();
-
- XSDElementDeclaration element = index.getChildElement(content, qName);
-
- if (element != null) {
- //TODO: determine wether the element is complex or simple, and create
- ElementHandler handler = parser.getHandlerFactory()
- .createElementHandler(element, this, parser);
-
- return handler;
- }
-
- //could not find the element as a direct child of the parent, check
- // for a global element, and then check its substituation group
- element = index.getElementDeclaration(qName);
-
- if (element != null) {
- XSDElementDeclaration sub = element.getSubstitutionGroupAffiliation();
-
- if (sub != null) {
- QName subQName = new QName(sub.getTargetNamespace(), sub.getName());
- Handler handler = getChildHandlerInternal(subQName);
-
- if (handler != null) {
- //this means that hte element is substituatable for an
- // actual child. now we have have choice, do we return
- // a handler for the actual element, or the element it
- // substituable for - the answer is to check the bindings
- //TODO: ask the binding
- handler = parser.getHandlerFactory().createElementHandler(element, this, parser);
-
- return handler;
- }
- }
- }
-
- //if
- return null;
- }
-
- private XSDTypeDefinition container() {
- //get the containing type (we do this for anonymous complex types)
- XSDTypeDefinition container = null;
- if (getParentHandler().getComponent() != null) {
- container = getParentHandler().getComponent().getTypeDefinition();
- }
- return container;
- }
-
- // public List getChildHandlers() {
- // return childHandlers;
- // }
- public void startChildHandler(Handler child) {
- //childHandlers.add(child);
- node.addChild(child.getParseNode());
-
- //initialize the context for the handler
- if (child instanceof ElementHandler) {
- //get the containing type (we do this for anonymous complex types)
- ElementInstance childInstance = (ElementInstance) child.getComponent();
- ContextInitializer initer = new ContextInitializer(childInstance, node,
- child.getContext());
- parser.getBindingWalker().walk(element.getElementDeclaration(), initer, container(), getContext());
- }
- }
-
- public void endChildHandler(Handler child) {
- //add the node to the parse tree
- //childHandlers.remove(child);
- }
-
- public Handler getParentHandler() {
- return parent;
- }
-
- public XSDSchemaContent getSchemaContent() {
- return content;
- }
-
- public Node getParseNode() {
- return node;
- }
-
- public XSDElementDeclaration getElementDeclaration() {
- return content;
- }
-
- public InstanceComponent getComponent() {
- return element;
- }
-
- public void setComponent(ElementImpl element) {
- this.element = element;
- }
-
- public Object getValue() {
- return value;
- }
-
- boolean isMixed() {
- if (!parser.isHandleMixedContent()) {
- return false;
- }
-
- return content.getType() != null && content.getType() instanceof XSDComplexTypeDefinition
- && ((XSDComplexTypeDefinition)content.getType()).isMixed();
- }
-
- public String toString() {
- return (node != null) ? node.toString() : "";
- }
-}
View
65 gdp-process-wps/src/main/java/gov/usgs/cida/gdp/wps/util/xml/GDPHandlerFactory.java
@@ -1,65 +0,0 @@
-package gov.usgs.cida.gdp.wps.util.xml;
-
-
-import javax.xml.namespace.QName;
-
-import org.eclipse.xsd.XSDElementDeclaration;
-import org.geotools.xml.impl.DocumentHandler;
-import org.geotools.xml.impl.ElementHandler;
-import org.geotools.xml.impl.Handler;
-
-
-/**
- * Factory used to create element handler objects during the processing of an
- * instance document.
- *
- * @author Justin Deoliveira,Refractions Reserach Inc.,jdeolive@refractions.net
- *
- *
- *
- *
- * @source $URL$
- */
-public interface GDPHandlerFactory {
- /**
- * Creates a handler for the root element of a document.
- */
- DocumentHandler createDocumentHandler(GDPParserHandler parser);
-
- /**
- * Creates an element hander for a global or top level element in a document.
- *
- * @param qName The qualified name identifying the element.
- * @param parent The parent handler.
- * @param parser The content handler driving the parser.
- *
- * @return A new element handler, or null if one could not be created.
- */
- ElementHandler createElementHandler(QName qName, Handler parent, GDPParserHandler parser);
-
- /**
- * Creates a handler for a particular element in a document.
- *
- * @param element The schema component which represents the declaration
- * of the element.
- * @param parent The parent handler.
- * @param parser The content handler driving the parser.
- *
- * @return A new element handler, or null if one could not be created.
- */
- ElementHandler createElementHandler(XSDElementDeclaration element, Handler parent,
- GDPParserHandler parser);
-
- /**
- * Creates a handler for a particular element in a document.
- *
- * @param attribute The schema component which represents the declaration
- * of the attribute.
- * @param parent The parent handler.
- * @param parser The content handler driving the parser.
- *
- * @return A new attribute handler, or null if one could not be created.
- */
-
- //AttributeHandler createAttributeHandler(XSDAttributeDeclaration attribute, Handler parent, GDPParserHandler parser );
-}
View
39 gdp-process-wps/src/main/java/gov/usgs/cida/gdp/wps/util/xml/GDPHandlerFactoryImpl.java
@@ -1,39 +0,0 @@
-package gov.usgs.cida.gdp.wps.util.xml;
-
-import javax.xml.namespace.QName;
-
-import org.eclipse.xsd.XSDElementDeclaration;
-import org.geotools.xml.SchemaIndex;
-import org.geotools.xml.impl.DocumentHandler;
-import org.geotools.xml.impl.ElementHandler;
-import org.geotools.xml.impl.Handler;
-
-
-/**
- *
- *
- * @source $URL$
- */
-public class GDPHandlerFactoryImpl implements GDPHandlerFactory {
- public DocumentHandler createDocumentHandler(GDPParserHandler parser) {
- return new GDPDocumentHandlerImpl(this, parser);
- }
-
- public ElementHandler createElementHandler(QName qName, Handler parent, GDPParserHandler parser) {
- SchemaIndex index = parser.getSchemaIndex();
-
- //look up the element in the schema
- XSDElementDeclaration element = index.getElementDeclaration(qName);
-
- if (element != null) {
- return createElementHandler(element, parent, parser);
- }
-
- return null;
- }
-
- public ElementHandler createElementHandler(XSDElementDeclaration element, Handler parent,
- GDPParserHandler parser) {
- return new GDPElementHandlerImpl(element, parent, parser);
- }
-}
View
360 gdp-process-wps/src/main/java/gov/usgs/cida/gdp/wps/util/xml/GDPParseExecutor.java
@@ -1,360 +0,0 @@
-package gov.usgs.cida.gdp.wps.util.xml;
-
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Set;
-
-import javax.xml.namespace.QName;
-
-import org.eclipse.xsd.XSDComplexTypeDefinition;
-import org.eclipse.xsd.XSDElementDeclaration;
-import org.eclipse.xsd.XSDEnumerationFacet;
-import org.eclipse.xsd.XSDFacet;
-import org.eclipse.xsd.XSDFactory;
-import org.eclipse.xsd.XSDLengthFacet;
-import org.eclipse.xsd.XSDMaxLengthFacet;
-import org.eclipse.xsd.XSDMinLengthFacet;
-import org.eclipse.xsd.XSDNamedComponent;
-import org.eclipse.xsd.XSDSimpleTypeDefinition;
-import org.eclipse.xsd.XSDTypeDefinition;
-import org.eclipse.xsd.XSDVariety;
-import org.eclipse.xsd.XSDWhiteSpace;
-import org.eclipse.xsd.XSDWhiteSpaceFacet;
-import org.geotools.xml.Binding;
-import org.geotools.xml.ComplexBinding;
-import org.geotools.xml.ElementInstance;
-import org.geotools.xml.InstanceComponent;
-import org.geotools.xml.Node;
-import org.geotools.xml.Schemas;
-import org.geotools.xml.SimpleBinding;
-import org.geotools.xml.impl.BindingWalker.Visitor;
-import org.geotools.xml.impl.InstanceBinding;
-import org.geotools.xml.impl.InstanceComponentImpl;
-import org.geotools.xs.facets.Whitespace;
-import org.picocontainer.MutablePicoContainer;
-
-
-/**
- *
- *
- * @source $URL$
- */
-public class GDPParseExecutor implements Visitor {
- private InstanceComponent instance;
- private Node node;
- private MutablePicoContainer context;
- private GDPParserHandler parser;
-
- /**
- * initial binding value
- */
- private Object value;
-
- /**
- * final parsed result
- */
- private Object result;
-
- public GDPParseExecutor(InstanceComponent instance, Node node, MutablePicoContainer context,
- GDPParserHandler parser) {
- this.instance = instance;
- this.node = node;
- this.context = context;
- this.parser = parser;
- }
-
- public void visit(Binding binding) {
- //TODO: the check for InstanceBinding is a temporary measure to allow
- // for bindings that are not registered by class, but by instance.
- // in the long term we intend to ditch pico container b/c our inection
- // needs are quite trivial and can be handled by some simple reflection
- if ( !( binding instanceof InstanceBinding ) ) {
- //reload out of context, we do this so that the binding can pick up any new dependencies
- // providedb by this particular context
- Class bindingClass = binding.getClass();
- QName bindingTarget = binding.getTarget();
-
- binding = (Binding) context.getComponentInstanceOfType(binding.getClass());
- if (binding == null) {
-
- binding = parser.getBindingLoader().loadBinding(bindingTarget, context);
- if ( binding == null ) {
- binding = parser.getBindingLoader().loadBinding(bindingTarget,bindingClass,context);
- }
- if ( binding.getClass() != bindingClass ) {
- throw new IllegalStateException( "Reloaded binding resulted in different type");
- }
- }
- }
-
-
- //execute the binding
- try {
- if (result == null) {
- //no result has been produced yet, should we pass the facet
- // parsed text in? only for simple types or complex types with
- // mixed content
- XSDTypeDefinition type = null;
-
- if (Schemas.nameMatches(instance.getDeclaration(), binding.getTarget())) {
- //instance binding
- type = instance.getTypeDefinition();
- } else {
- //type binding
- type = Schemas.getBaseTypeDefinition(instance.getTypeDefinition(),
- binding.getTarget());
- }
-
- if (value == null) {
- //have not preprocessed raw string yet
- //value = parseFacets( instance );
- value = preParse(instance);
-
- //if the type is simple or complex and mixed, use the
- // text as is, other wise trim it, turning to null if the
- // result is empty
- if ((type != null)
- && (type instanceof XSDSimpleTypeDefinition
- || ((XSDComplexTypeDefinition) type).isMixed())) {
- result = value;
- } else if ((value != null) && value instanceof String) {
- value = ((String) value).trim();
-
- if ("".equals(value)) {
- result = null;
- } else {
- result = value;
- }
- }
- else {
- result = value;
- }
- }
- }
-
- if (binding instanceof SimpleBinding) {
- result = ((SimpleBinding) binding).parse(instance, result);
- } else {
- result = ((ComplexBinding) binding).parse((ElementInstance) instance, node, result);
- }
-
- //only pass the value along if it was non-null
- if (result != null) {
- value = result;
- }
- } catch (Throwable t) {
- String msg = "Parsing failed for " + instance.getName() + ": " + t.toString();
- throw new RuntimeException(msg, t);
- }
- }
-
- public Object getValue() {
- return value;
- }
-
- /**
- * Pre-parses the instance compontent checking the following:
- * <p>
- *
- * </p>
- * @param instance
- */
- protected Object preParse(InstanceComponent instance) {
- // we only preparse text, so simple types
- XSDSimpleTypeDefinition type = null;
-
- if (instance.getTypeDefinition() instanceof XSDSimpleTypeDefinition) {
- type = (XSDSimpleTypeDefinition) instance.getTypeDefinition();
- } else {
- XSDComplexTypeDefinition complexType = (XSDComplexTypeDefinition) instance
- .getTypeDefinition();
-
- if (complexType.getContentType() instanceof XSDSimpleTypeDefinition) {
- type = (XSDSimpleTypeDefinition) complexType.getContentType();
- }
- }
-
- String text = instance.getText();
-
- if (type != null) {
- //alright, lets preparse some text
- //first base on variety
- if (type.getVariety() == XSDVariety.LIST_LITERAL) {
- //list, whiteSpace is fixed to "COLLAPSE
- text = Whitespace.COLLAPSE.preparse(text);
-
- //lists are seperated by spaces
- String[] list = text.split(" +");
-
- //apply the facets
- // 1. length
- // 2. maxLength
- // 3. minLength
- // 4. enumeration
- if (type.getLengthFacet() != null) {
- XSDLengthFacet length = type.getLengthFacet();
-
- if (list.length != length.getValue()) {
- //validation exception
- }
- }
-
- if (type.getMaxLengthFacet() != null) {
- XSDMaxLengthFacet length = type.getMaxLengthFacet();
-
- if (list.length > length.getValue()) {
- //validation exception
- }
- }
-
- if (type.getMinLengthFacet() != null) {
- XSDMinLengthFacet length = type.getMinLengthFacet();
-
- if (list.length < length.getValue()) {
- //validation exception
- }
- }
-
- if (!type.getEnumerationFacets().isEmpty()) {
- //gather up all teh possible values
- Set values = new HashSet();
-
- for (Iterator e = type.getEnumerationFacets().iterator(); e.hasNext();) {
- XSDEnumerationFacet enumeration = (XSDEnumerationFacet) e.next();
-
- for (Iterator v = enumeration.getValue().iterator(); v.hasNext();) {
- values.add(v.next());
- }
- }
-
- for (int i = 0; i < list.length; i++) {
- if (!values.contains(list[i])) {
- //validation exception
- }
- }
- }
-
- //now we must parse the items up
- final XSDSimpleTypeDefinition itemType = type.getItemTypeDefinition();
- List parsed = new ArrayList();
-
- //create a pseudo declaration
- final XSDElementDeclaration element = XSDFactory.eINSTANCE
- .createXSDElementDeclaration();
- element.setTypeDefinition(itemType);
-
- if (instance.getName() != null) {
- element.setName(instance.getName());
- }
-
- if (instance.getNamespace() != null) {
- element.setTargetNamespace(instance.getNamespace());
- }
-
- //create a new instance of the specified type
- InstanceComponentImpl theInstance = new InstanceComponentImpl() {
- public XSDTypeDefinition getTypeDefinition() {
- return itemType;
- }
-
- public XSDNamedComponent getDeclaration() {
- return element;
- }
- ;
- };
-
- for (int i = 0; i < list.length; i++) {
- theInstance.setText(list[i]);
-
- //perform the parse
- GDPParseExecutor executor = new GDPParseExecutor(theInstance, null, context, parser);
- parser.getBindingWalker().walk(element, executor, context);
-
- parsed.add(executor.getValue());
- }
-
- return parsed;
- } else if (type.getVariety() == XSDVariety.UNION_LITERAL) {
- //union, "valueSpace" and "lexicalSpace" facets are the union of the contained
- // datatypes
- return text;
- } else {
- //atomic
-
- //walk through the facets and preparse as necessary
- for (Iterator f = type.getFacets().iterator(); f.hasNext();) {
- XSDFacet facet = (XSDFacet) f.next();
-
- //white space
- if (facet instanceof XSDWhiteSpaceFacet) {
- XSDWhiteSpaceFacet whitespace = (XSDWhiteSpaceFacet) facet;
-
- if (whitespace.getValue() == XSDWhiteSpace.REPLACE_LITERAL) {
- text = Whitespace.REPLACE.preparse(text);
- }
-
- if (whitespace.getValue() == XSDWhiteSpace.COLLAPSE_LITERAL) {
- text = Whitespace.COLLAPSE.preparse(text);
- }
-
- if (whitespace.getValue() == XSDWhiteSpace.PRESERVE_LITERAL) {
- //do nothing
- }
- }
- }
-
- return text;
- }
- } else {
- //type is not simple, or complex with simple content, do a check
- // for mixed
- if (instance.getTypeDefinition() instanceof XSDComplexTypeDefinition
- && ((XSDComplexTypeDefinition) instance.getTypeDefinition()).isMixed()) {
- //collape the text
- text = Whitespace.COLLAPSE.preparse(text);
- }
- }
-
- return text;
- }
-
- protected Object parseFacets(InstanceComponent instance) {
- XSDTypeDefinition type = instance.getTypeDefinition();
-
- String value = instance.getText();
-
- while (type != null) {
- if (type instanceof XSDSimpleTypeDefinition) {
- XSDSimpleTypeDefinition simpleType = (XSDSimpleTypeDefinition) type;
- List facets = simpleType.getFacets();
-
- for (Iterator itr = facets.iterator(); itr.hasNext();) {
- XSDFacet facet = (XSDFacet) itr.next();
-
- if ("whiteSpace".equals(facet.getFacetName())) {
- Whitespace whitespace = Whitespace.valueOf(facet.getLexicalValue());
-
- if (whitespace != null) {
- value = whitespace.preparse(value);
- }
-
- //else TODO: check for validation, throw exception?
- }
-
- //TODO: other facets
- }
- }
-
- if (type.equals(type.getBaseType())) {
- break;
- }
-
- type = type.getBaseType();
- }
-
- return value;
- }
-}
-
View
34 ...da/gdp/wps/util/xml/GDPFeatureParser.java → ...ain/java/org/geotools/xml/PullParser.java
@@ -1,4 +1,4 @@
-package gov.usgs.cida.gdp.wps.util.xml;
+package org.geotools.xml;
import java.io.IOException;
import java.io.InputStream;
@@ -11,36 +11,43 @@
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
-import org.geotools.xml.Configuration;
import org.geotools.xml.impl.ElementHandler;
import org.geotools.xml.impl.NodeImpl;
+import org.geotools.xml.impl.ParserHandler;
import org.xml.sax.SAXException;
/**
- * Fix to the parser from GeoTools as their parsers are memory leakers
- *
- * @author Philip Russo, USGS - CIDA
- */
-public class GDPFeatureParser {
+* XML pull parser capable of streaming.
+* <p>
+* Similar in nature to {@link StreamingParser} but based on XPP pull parsing rather than SAX.
+*
+* @author Justin Deoliveira, OpenGeo
+*
+* Fix to the parser from GeoTools as their parsers are memory leakers
+* Moved to override geotools version rather than fork completely
+*
+* @author Philip Russo, USGS - CIDA
+*/
+public class PullParser {
PullParserHandler handler;
XMLStreamReader pp;
Attributes atts = new Attributes();
- public GDPFeatureParser(Configuration config, InputStream input, QName element) {
+ public PullParser(Configuration config, InputStream input, QName element) {
this(config, input, new ElementPullParserHandler(element, config));
}
- public GDPFeatureParser(Configuration config, InputStream input, Class type) {
+ public PullParser(Configuration config, InputStream input, Class type) {
this(config, input, new TypePullParserHandler(type, config));
}
- public GDPFeatureParser(Configuration config, InputStream input, Object... handlerSpecs) {
+ public PullParser(Configuration config, InputStream input, Object... handlerSpecs) {
this(config, input, new OrPullParserHandler(config, handlerSpecs));
}
- public GDPFeatureParser(Configuration config, InputStream input, PullParserHandler handler) {
+ public PullParser(Configuration config, InputStream input, PullParserHandler handler) {
this.handler = handler;
pp = createPullParser(input);
}
@@ -213,9 +220,9 @@ public String getValue(String qName) {
}
}
- static abstract class PullParserHandler extends GDPParserHandler {
+ static abstract class PullParserHandler extends ParserHandler {
- GDPFeatureParser parser;
+ PullParser parser;
Object object;
public PullParserHandler(Configuration config) {
@@ -241,6 +248,7 @@ public Object getObject() {
}
protected abstract boolean stop(ElementHandler handler);
+
}
View
92 ...da/gdp/wps/util/xml/GDPParserHandler.java → .../org/geotools/xml/impl/ParserHandler.java
@@ -1,4 +1,20 @@
-package gov.usgs.cida.gdp.wps.util.xml;
+/*
+ * GeoTools - The Open Source Java GIS Toolkit
+ * http://geotools.org
+ *
+ * (C) 2002-2008, Open Source Geospatial Foundation (OSGeo)
+ *
+ * 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.xml.impl;
import java.io.IOException;
import java.util.ArrayList;
@@ -12,8 +28,8 @@
import java.util.logging.Logger;
import javax.xml.namespace.QName;
-
import org.eclipse.emf.common.util.EList;
+
import org.eclipse.emf.ecore.resource.URIHandler;
import org.eclipse.xsd.XSDElementDeclaration;
import org.eclipse.xsd.XSDFactory;
@@ -30,16 +46,6 @@
import org.geotools.xml.ParserDelegate2;
import org.geotools.xml.SchemaIndex;
import org.geotools.xml.Schemas;
-import org.geotools.xml.impl.BindingFactoryImpl;
-import org.geotools.xml.impl.BindingLoader;
-import org.geotools.xml.impl.BindingWalker;
-import org.geotools.xml.impl.BindingWalkerFactoryImpl;
-import org.geotools.xml.impl.DocumentHandler;
-import org.geotools.xml.impl.ElementHandler;
-import org.geotools.xml.impl.Handler;
-import org.geotools.xml.impl.NamespaceSupportWrapper;
-import org.geotools.xml.impl.SchemaIndexImpl;
-import org.geotools.xml.impl.ValidatorHandler;
import org.geotools.xs.XS;
import org.picocontainer.ComponentAdapter;
import org.picocontainer.MutablePicoContainer;
@@ -65,7 +71,7 @@
*
* @source $URL$
*/
-public class GDPParserHandler extends DefaultHandler {
+public class ParserHandler extends DefaultHandler {
/** execution stack **/
protected Stack handlers;
@@ -79,7 +85,7 @@
SchemaIndex index;
/** handler factory **/
- GDPHandlerFactory handlerFactory;
+ HandlerFactory handlerFactory;
/** binding loader */
BindingLoader bindingLoader;
@@ -125,7 +131,7 @@
/** uri handlers for handling uri references during parsing */
List<URIHandler> uriHandlers = new ArrayList<URIHandler>();
- public GDPParserHandler(Configuration config) {
+ public ParserHandler(Configuration config) {
this.config = config;
namespaces = new NamespaceSupport();
validating = false;
@@ -192,7 +198,7 @@ public ValidatorHandler getValidator() {
return validator;
}
- public GDPHandlerFactory getHandlerFactory() {
+ public HandlerFactory getHandlerFactory() {
return handlerFactory;
}
@@ -520,10 +526,10 @@ public void startElement(String uri, String localName, String qName, Attributes
if (handler == null) {
//perform a lookup in the context for an element factory that create a child handler
- List handlerFactories = context.getComponentInstancesOfType(GDPHandlerFactory.class);
+ List handlerFactories = context.getComponentInstancesOfType(HandlerFactory.class);
for (Iterator hf = handlerFactories.iterator(); (handler == null) && hf.hasNext();) {
- GDPHandlerFactory handlerFactory = (GDPHandlerFactory) hf.next();
+ HandlerFactory handlerFactory = (HandlerFactory) hf.next();
handler = handlerFactory.createElementHandler(qualifiedName, parent, this);
}
}
@@ -544,9 +550,9 @@ public void startElement(String uri, String localName, String qName, Attributes
if (canHandle) {
//found one
- handler = new GDPDelegatingHandler( delegate, qualifiedName, parent );
+ handler = new DelegatingHandler( delegate, qualifiedName, parent );
- GDPDelegatingHandler dh = (GDPDelegatingHandler) handler;
+ DelegatingHandler dh = (DelegatingHandler) handler;
dh.startDocument();
//inject the current namespace context
@@ -694,9 +700,9 @@ public void endElement(String uri, String localName, String qName)
endElementInternal(handler);
//if the upper most delegating handler, then end the document
- if ( handler instanceof GDPDelegatingHandler &&
- !handlers.isEmpty() && !(handlers.peek() instanceof GDPDelegatingHandler) ) {
- GDPDelegatingHandler dh = (GDPDelegatingHandler) handler;
+ if ( handler instanceof DelegatingHandler &&
+ !handlers.isEmpty() && !(handlers.peek() instanceof DelegatingHandler) ) {
+ DelegatingHandler dh = (DelegatingHandler) handler;
dh.endDocument();
//grabbed the parsed value
@@ -767,27 +773,27 @@ public Object getValue() {
}
/**
- * This cleanup method removes the memory leak caused by not clearing out
- * all of the XSDElementDeclaration objects created during this classes
- * lifetime.
- */
+ * This cleanup method removes the memory leak caused by not clearing out
+ * all of the XSDElementDeclaration objects created during this classes
+ * lifetime.
+ */
public void cleanup() {
- for (int i = 0; i < schemas.length; i++) {
+ for (int i = 0; i < schemas.length; i++) {
if (schemas[i] != null) {
- XSDSchema schema = schemas[i];
-
- EList<XSDElementDeclaration> declarations = schema.getElementDeclarations();
-
- for(int j = 0; j < declarations.size(); j++) {
- XSDElementDeclaration declaration = declarations.get(j);
-
- EList<XSDElementDeclaration> substitutionGroups = declaration.getSubstitutionGroup();
- substitutionGroups.clear();
- }
- declarations.clear();
-
- schema = null;
- schemas[i] = null;
+ XSDSchema schema = schemas[i];
+
+ EList<XSDElementDeclaration> declarations = schema.getElementDeclarations();
+
+ for (int j = 0; j < declarations.size(); j++) {
+ XSDElementDeclaration declaration = declarations.get(j);
+
+ EList<XSDElementDeclaration> substitutionGroups = declaration.getSubstitutionGroup();
+ substitutionGroups.clear();
+ }
+ declarations.clear();
+
+ schema = null;
+ schemas[i] = null;
}
}
}
@@ -796,7 +802,7 @@ protected void configure(Configuration config) {
//configure the bindings
Map bindings = config.setupBindings();
- handlerFactory = new GDPHandlerFactoryImpl();
+ handlerFactory = new HandlerFactoryImpl();
bindingLoader = new BindingLoader(bindings);
bindingWalker = new BindingWalker(bindingLoader);
}

No commit comments for this range

Something went wrong with that request. Please try again.