[jboss-svn-commits] JBoss Common SVN: r4501 - in jbossxb/branches/split: wstoxparser and 11 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Fri Jun 11 11:33:13 EDT 2010
Author: alex.loubyansky at jboss.com
Date: 2010-06-11 11:33:12 -0400 (Fri, 11 Jun 2010)
New Revision: 4501
Added:
jbossxb/branches/split/wstoxparser/
jbossxb/branches/split/wstoxparser/trunk/
jbossxb/branches/split/wstoxparser/trunk/.classpath
jbossxb/branches/split/wstoxparser/trunk/.project
jbossxb/branches/split/wstoxparser/trunk/pom.xml
jbossxb/branches/split/wstoxparser/trunk/src/
jbossxb/branches/split/wstoxparser/trunk/src/main/
jbossxb/branches/split/wstoxparser/trunk/src/main/java/
jbossxb/branches/split/wstoxparser/trunk/src/main/java/org/
jbossxb/branches/split/wstoxparser/trunk/src/main/java/org/jboss/
jbossxb/branches/split/wstoxparser/trunk/src/main/java/org/jboss/xb/
jbossxb/branches/split/wstoxparser/trunk/src/main/java/org/jboss/xb/binding/
jbossxb/branches/split/wstoxparser/trunk/src/main/java/org/jboss/xb/binding/parser/
jbossxb/branches/split/wstoxparser/trunk/src/main/java/org/jboss/xb/binding/parser/JBossXBParserFactoryImpl.java
jbossxb/branches/split/wstoxparser/trunk/src/main/java/org/jboss/xb/binding/parser/wstox/
jbossxb/branches/split/wstoxparser/trunk/src/main/java/org/jboss/xb/binding/parser/wstox/WoodstoxJBossXBParser.java
jbossxb/branches/split/wstoxparser/trunk/src/main/resources/
jbossxb/branches/split/wstoxparser/trunk/src/test/
jbossxb/branches/split/wstoxparser/trunk/src/test/java/
jbossxb/branches/split/wstoxparser/trunk/src/test/resources/
Log:
woodstox-based parser for xb
Added: jbossxb/branches/split/wstoxparser/trunk/.classpath
===================================================================
--- jbossxb/branches/split/wstoxparser/trunk/.classpath (rev 0)
+++ jbossxb/branches/split/wstoxparser/trunk/.classpath 2010-06-11 15:33:12 UTC (rev 4501)
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" output="target/classes" path="src/main/java"/>
+ <classpathentry excluding="**/*.java" kind="src" output="target/classes" path="src/main/resources"/>
+ <classpathentry kind="src" output="target/test-classes" path="src/test/java"/>
+ <classpathentry excluding="**/*.java" kind="src" output="target/test-classes" path="src/test/resources"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+ <classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
+ <classpathentry kind="output" path="target/classes"/>
+</classpath>
Added: jbossxb/branches/split/wstoxparser/trunk/.project
===================================================================
--- jbossxb/branches/split/wstoxparser/trunk/.project (rev 0)
+++ jbossxb/branches/split/wstoxparser/trunk/.project 2010-06-11 15:33:12 UTC (rev 4501)
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>jbossxb-wstoxparser</name>
+ <comment>JBoss XML Binding Woodstox parser</comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.maven.ide.eclipse.maven2Builder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.maven.ide.eclipse.maven2Nature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
Added: jbossxb/branches/split/wstoxparser/trunk/pom.xml
===================================================================
--- jbossxb/branches/split/wstoxparser/trunk/pom.xml (rev 0)
+++ jbossxb/branches/split/wstoxparser/trunk/pom.xml 2010-06-11 15:33:12 UTC (rev 4501)
@@ -0,0 +1,147 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <parent>
+ <groupId>org.jboss</groupId>
+ <artifactId>jboss-parent</artifactId>
+ <version>5</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>jbossxb-wstoxparser</artifactId>
+ <packaging>jar</packaging>
+ <version>3.0.0-SNAPSHOT</version>
+ <name>JBoss XML Binding</name>
+ <url>http://www.jboss.org</url>
+ <description>JBoss XML Binding</description>
+ <scm>
+ <connection>scm:svn:https://svn.jboss.org/repos/common/jbossxb/branches/split/jbossxb-wstoxparser/trunk</connection>
+ </scm>
+ <build>
+ <finalName>jbossxb-wstoxparser</finalName>
+ <plugins>
+ <plugin>
+ <artifactId>maven-release-plugin</artifactId>
+ <configuration>
+ <!-- The tagBase property is needed during the release process so that the maven release plugin
+ will create the release tag in the appropriate location. -->
+ <tagBase>https://svn.jboss.org/repos/common/jbossxb/tags</tagBase>
+ </configuration>
+ </plugin>
+ <plugin>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <!-- the tessuite will be run twice.
+ the first/default execution will run with the default xb configuration
+ if there are failures, the next execution won't be run -->
+ <testFailureIgnore>false</testFailureIgnore>
+ <redirectTestOutputToFile>true</redirectTestOutputToFile>
+ <includes>
+ <include>**/*TestCase.java</include>
+ </includes>
+ <excludes>
+ <exclude>org/jboss/test/xml/RepeatedElementsUnitTestCase.java</exclude> <!-- JBXB-88 -->
+ <exclude>org/jboss/test/xb/builder/object/type/jbossxmlmodelgroup/test/RepeatablePropertyAllUnmarshallingTestCase.java</exclude> <!-- JBXB-193 -->
+ </excludes>
+ </configuration>
+ <executions>
+ <execution>
+ <!-- this execution will run with xb.builder.useUnorderedSequence=true
+ the reports from the previous testsuite run will be overriden
+ which is ok, since if the previous execution fails, this execution shouldn't start -->
+ <id>unordered-sequence-true-test</id>
+ <goals>
+ <goal>test</goal>
+ </goals>
+ <configuration>
+ <testFailureIgnore>false</testFailureIgnore>
+ <redirectTestOutputToFile>true</redirectTestOutputToFile>
+ <excludes>
+ <exclude>org/jboss/test/xml/RepeatedElementsUnitTestCase.java</exclude> <!-- JBXB-88 -->
+ <exclude>org/jboss/test/xb/builder/object/type/jbossxmlmodelgroup/test/RepeatablePropertyAllUnmarshallingTestCase.java</exclude> <!-- JBXB-193 -->
+ <exclude>org/jboss/test/xb/builder/object/type/jbossxmlmodelgroup/test/RepeatablePropertySequenceUnmarshallingTestCase.java</exclude> <!-- unordered sequence makes it JBXB-193 -->
+ <exclude>org/jboss/test/xb/builder/repeatableterms/test/RepeatableTermsUnitTestCase.java</exclude>
+
+ <!-- below are the tests that don't depend on the setting -->
+ <exclude>org/jboss/test/xb/validator/test/BasicBindingValidatorUnitTestCase.java</exclude>
+ </excludes>
+ <systemProperties>
+ <property>
+ <name>xb.builder.useUnorderedSequence</name>
+ <value>true</value>
+ </property>
+ </systemProperties>
+ </configuration>
+ </execution>
+ <execution>
+ <!-- this execution will run with xb.builder.repeatableParticleHandlers=false -->
+ <id>repeatable-handlers-false-test</id>
+ <goals>
+ <goal>test</goal>
+ </goals>
+ <configuration>
+ <testFailureIgnore>false</testFailureIgnore>
+ <redirectTestOutputToFile>true</redirectTestOutputToFile>
+ <excludes>
+ <exclude>org/jboss/test/xml/RepeatedElementsUnitTestCase.java</exclude> <!-- JBXB-88 -->
+ <exclude>org/jboss/test/xb/builder/object/type/jbossxmlmodelgroup/test/RepeatablePropertyAllUnmarshallingTestCase.java</exclude> <!-- JBXB-193 -->
+ <!-- below are the tests that don't depend on the setting -->
+ <exclude>org/jboss/test/xb/validator/test/BasicBindingValidatorUnitTestCase.java</exclude>
+ </excludes>
+ <systemProperties>
+ <property>
+ <name>xb.builder.repeatableParticleHandlers</name>
+ <value>false</value>
+ </property>
+ </systemProperties>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+ <repositories>
+ <repository>
+ <id>repository.jboss.org</id>
+ <name>JBoss Repository</name>
+ <layout>default</layout>
+ <url>http://repository.jboss.org/maven2/</url>
+ <snapshots>
+ <enabled>false</enabled>
+ </snapshots>
+ </repository>
+ <repository>
+ <id>snapshots.jboss.org</id>
+ <name>JBoss Snapshot Repository</name>
+ <layout>default</layout>
+ <url>http://snapshots.jboss.org/maven2/</url>
+ <releases>
+ <enabled>false</enabled>
+ </releases>
+ <snapshots>
+ <enabled>true</enabled>
+ </snapshots>
+ </repository>
+ </repositories>
+
+ <dependencies>
+
+ <dependency>
+ <groupId>org.jboss</groupId>
+ <artifactId>jbossxb-core</artifactId>
+ <version>3.0.0-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.jboss.test</groupId>
+ <artifactId>jboss-test</artifactId>
+ <version>1.1.4.GA</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.4</version>
+ <scope>test</scope>
+ </dependency>
+
+ </dependencies>
+</project>
\ No newline at end of file
Added: jbossxb/branches/split/wstoxparser/trunk/src/main/java/org/jboss/xb/binding/parser/JBossXBParserFactoryImpl.java
===================================================================
--- jbossxb/branches/split/wstoxparser/trunk/src/main/java/org/jboss/xb/binding/parser/JBossXBParserFactoryImpl.java (rev 0)
+++ jbossxb/branches/split/wstoxparser/trunk/src/main/java/org/jboss/xb/binding/parser/JBossXBParserFactoryImpl.java 2010-06-11 15:33:12 UTC (rev 4501)
@@ -0,0 +1,39 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This 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; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.xb.binding.parser;
+
+import org.jboss.xb.binding.parser.wstox.WoodstoxJBossXBParser;
+
+/**
+ * A JBossXBParserFactoryImpl.
+ *
+ * @author <a href="alex at jboss.com">Alexey Loubyansky</a>
+ * @version $Revision: 1.1 $
+ */
+public class JBossXBParserFactoryImpl implements JBossXBParserFactory
+{
+ @Override
+ public JBossXBParser createParser()
+ {
+ return new WoodstoxJBossXBParser();
+ }
+}
Added: jbossxb/branches/split/wstoxparser/trunk/src/main/java/org/jboss/xb/binding/parser/wstox/WoodstoxJBossXBParser.java
===================================================================
--- jbossxb/branches/split/wstoxparser/trunk/src/main/java/org/jboss/xb/binding/parser/wstox/WoodstoxJBossXBParser.java (rev 0)
+++ jbossxb/branches/split/wstoxparser/trunk/src/main/java/org/jboss/xb/binding/parser/wstox/WoodstoxJBossXBParser.java 2010-06-11 15:33:12 UTC (rev 4501)
@@ -0,0 +1,707 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This 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; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software 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.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.xb.binding.parser.wstox;
+
+import java.io.File;
+import java.io.InputStream;
+import java.io.Reader;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.FactoryConfigurationError;
+import javax.xml.stream.XMLEventReader;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLResolver;
+import javax.xml.stream.XMLStreamConstants;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.events.Attribute;
+import javax.xml.stream.events.Characters;
+import javax.xml.stream.events.DTD;
+import javax.xml.stream.events.EndElement;
+import javax.xml.stream.events.Namespace;
+import javax.xml.stream.events.StartElement;
+import javax.xml.stream.events.XMLEvent;
+
+//import org.codehaus.stax2.XMLEventReader2;
+//import org.codehaus.stax2.XMLInputFactory2;
+//import org.codehaus.stax2.XMLStreamReader2;
+//import org.codehaus.stax2.evt.DTD2;
+//import org.codehaus.stax2.io.Stax2Source;
+//import org.codehaus.stax2.io.Stax2FileSource;
+//import org.codehaus.stax2.io.Stax2URLSource;
+import org.jboss.xb.binding.JBossXBException;
+import org.jboss.xb.binding.JBossXBRuntimeException;
+import org.jboss.xb.binding.parser.JBossXBParser;
+import org.jboss.xb.binding.parser.JBossXBParser.ContentHandler;
+import org.xml.sax.Attributes;
+import org.xml.sax.EntityResolver;
+import org.xml.sax.InputSource;
+
+//import com.ctc.wstx.api.ReaderConfig;
+//import com.ctc.wstx.stax.WstxInputFactory;
+
+/**
+ * A WoodstoxJBossXBParser.
+ *
+ * @author <a href="alex at jboss.com">Alexey Loubyansky</a>
+ * @version $Revision: 1.1 $
+ */
+public class WoodstoxJBossXBParser implements JBossXBParser
+{
+
+ private static final Attributes EMPTY_ATTRS = new Attributes()
+ {
+ @Override
+ public int getIndex(String name)
+ {
+ return -1;
+ }
+
+ @Override
+ public int getIndex(String uri, String localName)
+ {
+ return -1;
+ }
+
+ @Override
+ public int getLength()
+ {
+ return 0;
+ }
+
+ @Override
+ public String getLocalName(int index)
+ {
+ return null;
+ }
+
+ @Override
+ public String getQName(int index)
+ {
+ return null;
+ }
+
+ @Override
+ public String getType(int index)
+ {
+ return null;
+ }
+
+ @Override
+ public String getType(String name)
+ {
+ return null;
+ }
+
+ @Override
+ public String getType(String uri, String localName)
+ {
+ return null;
+ }
+
+ @Override
+ public String getURI(int index)
+ {
+ return null;
+ }
+
+ @Override
+ public String getValue(int index)
+ {
+ return null;
+ }
+
+ @Override
+ public String getValue(String name)
+ {
+ return null;
+ }
+
+ @Override
+ public String getValue(String uri, String localName)
+ {
+ return null;
+ }
+ };
+
+// private static WstxInputFactory inputFactory = new WstxInputFactory();//(XMLInputFactory2) XMLInputFactory2.newInstance();
+
+/* public WoodstoxJBossXBParser()
+ {
+ System.out.println(inputFactory.getProperty(XMLInputFactory.IS_VALIDATING));
+ System.out.println(inputFactory.getProperty(XMLInputFactory.IS_NAMESPACE_AWARE));
+ System.out.println(inputFactory.getProperty(XMLInputFactory.IS_COALESCING));
+ System.out.println(inputFactory.getProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES));
+ System.out.println(inputFactory.getProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES));
+ System.out.println(inputFactory.getProperty(XMLInputFactory.SUPPORT_DTD));
+ }
+*/
+ @Override
+ public void parse(final String source, ContentHandler handler) throws JBossXBException
+ {
+/* Stax2Source src;
+ try
+ {
+ src = new Stax2URLSource(new URL(source));
+ }
+ catch(MalformedURLException e)
+ {
+ src = new Stax2FileSource(new File(source));
+ }
+
+ try
+ {
+ //XMLEventReader2 stream = (XMLEventReader2) inputFactory.createXMLEventReader(src);
+ XMLStreamReader2 stream = (XMLStreamReader2) inputFactory.createXMLStreamReader(src);
+ parse(handler, stream);
+ }
+ catch (FactoryConfigurationError e)
+ {
+ throw new JBossXBException("Failed to create an instance of XMLStreamReader", e);
+ }
+ catch (XMLStreamException e)
+ {
+ throw new JBossXBException("Failed to parse XML stream", e);
+ }
+ catch(Throwable e)
+ {
+ throw new JBossXBException("Failed to parse source: ", e);
+ }
+*/ }
+
+ @Override
+ public void parse(InputStream is, ContentHandler handler) throws JBossXBException
+ {
+/* try
+ {
+ //XMLEventReader2 stream = (XMLEventReader2) inputFactory.createXMLEventReader(is);
+ XMLStreamReader2 stream = (XMLStreamReader2) inputFactory.createXMLStreamReader(is);
+ parse(handler, stream);
+ }
+ catch (FactoryConfigurationError e)
+ {
+ throw new JBossXBException("Failed to create an instance of XMLStreamReader", e);
+ }
+ catch (XMLStreamException e)
+ {
+ throw new JBossXBException("Failed to parse XML stream", e);
+ }
+ catch(Throwable e)
+ {
+ throw new JBossXBException("Failed to parse source: ", e);
+ }
+*/ }
+
+ @Override
+ public void parse(Reader reader, ContentHandler handler) throws JBossXBException
+ {
+/* try
+ {
+ //XMLEventReader2 stream = (XMLEventReader2) inputFactory.createXMLEventReader(reader);
+ XMLStreamReader2 stream = (XMLStreamReader2) inputFactory.createXMLStreamReader(reader);
+ parse(handler, stream);
+ }
+ catch (FactoryConfigurationError e)
+ {
+ throw new JBossXBException("Failed to create an instance of XMLStreamReader", e);
+ }
+ catch (XMLStreamException e)
+ {
+ throw new JBossXBException("Failed to parse XML stream", e);
+ }
+ catch(Throwable e)
+ {
+ throw new JBossXBException("Failed to parse source: ", e);
+ }
+*/ }
+
+ @Override
+ public void parse(InputSource source, ContentHandler handler) throws JBossXBException
+ {
+ InputStream bs = source.getByteStream();
+ if(bs != null)
+ {
+ parse(bs, handler);
+ return;
+ }
+
+ Reader cs = source.getCharacterStream();
+ if(cs != null)
+ {
+ parse(cs, handler);
+ return;
+ }
+
+ String systemId = source.getSystemId();
+ if(systemId == null)
+ throw new JBossXBRuntimeException("None of ByteStream, CharacterStream, systemId are available through the instance of InputSource.");
+ parse(systemId, handler);
+ }
+
+ @Override
+ public void setEntityResolver(final EntityResolver entityResolver) throws JBossXBException
+ {
+ XMLResolver resolver = new XMLResolver()
+ {
+ @Override
+ public Object resolveEntity(String publicID, String systemID, String baseURI, String namespace)
+ throws XMLStreamException
+ {
+ InputSource source;
+ try
+ {
+ source = entityResolver.resolveEntity(publicID, systemID);
+ }
+ catch (Exception e)
+ {
+ throw new JBossXBRuntimeException("Failed to resolve publicId=" + publicID +
+ ", systemId=" + systemID +
+ ", baseURI=" + baseURI +
+ ", namespace=" + namespace, e);
+ }
+
+ InputStream stream = source.getByteStream();
+ if(stream != null)
+ return stream;
+
+ throw new IllegalStateException("Only streams are supported atm");
+ }
+ };
+
+/* ReaderConfig config = inputFactory.getConfig();
+ config.setDtdResolver(resolver);
+ config.setEntityResolver(resolver);
+*/ }
+
+ @Override
+ public void setFeature(String name, boolean value)
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void setProperty(String name, Object value)
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+/* private void parse(ContentHandler handler, final XMLStreamReader2 stream) throws XMLStreamException
+ {
+ while (stream.hasNext())
+ {
+ int event = stream.next();
+
+ switch(event)
+ {
+ case XMLStreamConstants.ATTRIBUTE:
+ System.out.println("attribute");
+ break;
+ case XMLStreamConstants.CDATA:
+ System.out.println("cdata");
+ break;
+ case XMLStreamConstants.CHARACTERS:
+ System.out.println("characters");
+ break;
+ case XMLStreamConstants.COMMENT:
+ System.out.println("comment");
+ break;
+ case XMLStreamConstants.DTD:
+ System.out.println("dtd");
+ break;
+ case XMLStreamConstants.END_DOCUMENT:
+ System.out.println("end doc");
+ break;
+ case XMLStreamConstants.END_ELEMENT:
+ System.out.println("end element " + stream.getLocalName());
+ break;
+ case XMLStreamConstants.ENTITY_DECLARATION:
+ System.out.println("entity dec");
+ break;
+ case XMLStreamConstants.ENTITY_REFERENCE:
+ System.out.println("entity ref");
+ break;
+ case XMLStreamConstants.NAMESPACE:
+ System.out.println("namespace");
+ break;
+ case XMLStreamConstants.NOTATION_DECLARATION:
+ System.out.println("notation");
+ break;
+ case XMLStreamConstants.PROCESSING_INSTRUCTION:
+ System.out.println("pi");
+ break;
+ case XMLStreamConstants.SPACE:
+ System.out.println("space");
+ break;
+ case XMLStreamConstants.START_DOCUMENT:
+ System.out.println("start doc");
+ break;
+ case XMLStreamConstants.START_ELEMENT:
+ System.out.println("start element " + stream.getLocalName());
+ break;
+ default:
+ throw new IllegalStateException("Unknown event " + event);
+ }
+
+ if (event == XMLStreamConstants.START_ELEMENT)
+ {
+ //System.out.println("start " + stream.getLocalName());
+
+ int nsTotal = stream.getNamespaceCount();
+ if(nsTotal > 0)
+ {
+ for(int i = 0; i < nsTotal; ++i)
+ {
+ String ns = stream.getNamespaceURI(i);
+ if(ns == null)
+ ns = "";
+ String prefix = stream.getNamespacePrefix(i);
+ if(prefix == null)
+ prefix = "";
+ handler.startPrefixMapping(prefix, ns);
+ }
+ }
+
+ Attributes attrs = EMPTY_ATTRS;
+ int attrsTotal = stream.getAttributeCount();
+ if(attrsTotal > 0)
+ {
+ attrs = new Attributes()
+ {
+ @Override
+ public int getIndex(String name)
+ {
+ return getIndex(null, name);
+ }
+
+ @Override
+ public int getIndex(String uri, String localName)
+ {
+ return -1;
+ }
+
+ @Override
+ public int getLength()
+ {
+ return stream.getAttributeCount();
+ }
+
+ @Override
+ public String getLocalName(int index)
+ {
+ return stream.getAttributeLocalName(index);
+ }
+
+ @Override
+ public String getQName(int index)
+ {
+ return null;
+ }
+
+ @Override
+ public String getType(int index)
+ {
+ return stream.getAttributeType(index);
+ }
+
+ @Override
+ public String getType(String name)
+ {
+ return getType(null, name);
+ }
+
+ @Override
+ public String getType(String uri, String localName)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public String getURI(int index)
+ {
+ String ns = stream.getAttributeNamespace(index);
+ if(ns == null)
+ return "";
+ return ns;
+ }
+
+ @Override
+ public String getValue(int index)
+ {
+ return stream.getAttributeValue(index);
+ }
+
+ @Override
+ public String getValue(String name)
+ {
+ return getValue(null, name);
+ }
+
+ @Override
+ public String getValue(String uri, String localName)
+ {
+ return stream.getAttributeValue(uri, localName);
+ }
+ };
+ }
+
+ String ns = stream.getNamespaceURI();
+ if(ns == null)
+ ns = "";
+ handler.startElement(ns, stream.getLocalName(), null, attrs);
+ }
+// else if (event == XMLStreamConstants.ATTRIBUTE)
+// {
+// }
+ else if (event == XMLStreamConstants.CHARACTERS)
+ {
+ handler.characters(stream.getTextCharacters(), stream.getTextStart(), stream.getTextLength());
+ }
+// else if (event == XMLStreamConstants.COMMENT)
+// {
+// //System.out.println("Comment Text:" + stream.getText());
+// }
+// else if (event == XMLStreamConstants.END_DOCUMENT)
+// {
+// }
+ else if (event == XMLStreamConstants.END_ELEMENT)
+ {
+ String ns = stream.getNamespaceURI();
+ if(ns == null)
+ ns = "";
+ handler.endElement(ns, stream.getLocalName(), null);
+ int nsTotal = stream.getNamespaceCount();
+ if(nsTotal > 0)
+ {
+ for(int i = 0; i < nsTotal; ++i)
+ {
+ String prefix = stream.getNamespacePrefix(i);
+ if(prefix == null)
+ prefix = "";
+ handler.endPrefixMapping(prefix);
+ }
+ }
+ }
+// else if(event == XMLStreamConstants.DTD)
+// {
+// System.out.println("dtd " + stream.getText());
+// }
+// else if (event == XMLStreamConstants.NAMESPACE)
+// {
+// //System.out.println("ns: " + stream.getText());
+// }
+// if (event == XMLStreamConstants.PROCESSING_INSTRUCTION)
+// {
+// System.out.println("PI Target:" + stream.getPITarget());
+// System.out.println("PI Data:" + stream.getPIData());
+// }
+// if (event == XMLStreamConstants.SPACE)
+// {
+// System.out.println("Event Type: SPACE");
+// System.out.println("Text:" + stream.getText());
+//
+// }
+ }
+ }
+
+ private void parse(ContentHandler handler, final XMLEventReader2 stream) throws XMLStreamException
+ {
+ while (stream.hasNext())
+ {
+ XMLEvent event = stream.nextEvent();
+ if (event.isStartElement())
+ {
+ //System.out.println("start " + stream.getLocalName());
+
+ final StartElement start = (StartElement)event;
+ Iterator<Namespace> i = start.getNamespaces();
+ while(i.hasNext())
+ {
+ Namespace declaredNs = i.next();
+ String ns = declaredNs.getNamespaceURI();
+ if(ns == null)
+ ns = "";
+ String prefix = declaredNs.getPrefix();
+ if(prefix == null)
+ prefix = "";
+ handler.startPrefixMapping(prefix, ns);
+ }
+
+ Attributes attrs = EMPTY_ATTRS;
+ Iterator<Attribute> eAttrs = start.getAttributes();
+ if(eAttrs.hasNext())
+ {
+ final List<Attribute> attrList = new ArrayList<Attribute>();
+ while(eAttrs.hasNext())
+ attrList.add(eAttrs.next());
+
+ attrs = new Attributes()
+ {
+ @Override
+ public int getIndex(String name)
+ {
+ return getIndex(null, name);
+ }
+
+ @Override
+ public int getIndex(String uri, String localName)
+ {
+ return -1;
+ }
+
+ @Override
+ public int getLength()
+ {
+ return attrList.size();
+ }
+
+ @Override
+ public String getLocalName(int index)
+ {
+ return attrList.get(index).getName().getLocalPart();
+ }
+
+ @Override
+ public String getQName(int index)
+ {
+ return null;
+ }
+
+ @Override
+ public String getType(int index)
+ {
+ return attrList.get(index).getDTDType();
+ }
+
+ @Override
+ public String getType(String name)
+ {
+ return getType(null, name);
+ }
+
+ @Override
+ public String getType(String uri, String localName)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public String getURI(int index)
+ {
+ return attrList.get(index).getName().getNamespaceURI();
+ }
+
+ @Override
+ public String getValue(int index)
+ {
+ return attrList.get(index).getValue();
+ }
+
+ @Override
+ public String getValue(String name)
+ {
+ return getValue(null, name);
+ }
+
+ @Override
+ public String getValue(String uri, String localName)
+ {
+ Attribute attr = start.getAttributeByName(new QName(uri, localName));
+ if(attr == null)
+ return null;
+ return attr.getValue();
+ }
+ };
+ }
+
+ String ns = start.getName().getNamespaceURI();
+ if(ns == null)
+ ns = "";
+ try
+ {
+ handler.startElement(ns, start.getName().getLocalPart(), null, attrs);
+ }
+ catch(JBossXBRuntimeException e)
+ {
+ System.out.println(start.getLocation());
+ throw e;
+ }
+ }
+// else if (event == XMLStreamConstants.ATTRIBUTE)
+// {
+// }
+ else if (event.isCharacters())
+ {
+ Characters chars = (Characters) event;
+ handler.characters(chars.getData().toCharArray(), 0, chars.getData().length());
+ }
+// else if (event == XMLStreamConstants.COMMENT)
+// {
+// //System.out.println("Comment Text:" + stream.getText());
+// }
+// else if (event == XMLStreamConstants.END_DOCUMENT)
+// {
+// }
+ else if (event.isEndElement())
+ {
+ EndElement end = (EndElement) event;
+ String ns = end.getName().getNamespaceURI();
+ if(ns == null)
+ ns = "";
+ handler.endElement(ns, end.getName().getLocalPart(), null);
+ Iterator<Namespace> i = end.getNamespaces();
+ while(i.hasNext())
+ {
+ Namespace declaredNs = i.next();
+ String prefix = declaredNs.getPrefix();
+ if(prefix == null)
+ prefix = "";
+ handler.endPrefixMapping(prefix);
+ }
+ }
+ else if(event instanceof DTD2 && handler instanceof JBossXBParser.DtdAwareContentHandler)
+ {
+ DTD2 dtd = (DTD2) event;
+ JBossXBParser.DtdAwareContentHandler dtdHandler = (JBossXBParser.DtdAwareContentHandler)handler;
+ dtdHandler.startDTD(dtd.getRootName(), dtd.getPublicId(), dtd.getSystemId());
+ dtdHandler.endDTD();
+ }
+// if (event == XMLStreamConstants.PROCESSING_INSTRUCTION)
+// {
+// System.out.println("PI Target:" + stream.getPITarget());
+// System.out.println("PI Data:" + stream.getPIData());
+// }
+// if (event == XMLStreamConstants.SPACE)
+// {
+// System.out.println("Event Type: SPACE");
+// System.out.println("Text:" + stream.getText());
+//
+// }
+ }
+ }
+ */
+}
More information about the jboss-svn-commits
mailing list