You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2011/11/22 15:30:24 UTC

svn commit: r1205018 [1/2] - in /camel/trunk: apache-camel/ apache-camel/src/main/descriptors/ camel-core/src/main/java/org/apache/camel/component/file/ camel-core/src/main/java/org/apache/camel/converter/jaxp/ camel-core/src/test/java/org/apache/camel...

Author: davsclaus
Date: Tue Nov 22 14:30:16 2011
New Revision: 1205018

URL: http://svn.apache.org/viewvc?rev=1205018&view=rev
Log:
CAMEL-3999: camel-stax component. Thanks to Romain for the patch.

Added:
    camel/trunk/components/camel-stax/   (with props)
    camel/trunk/components/camel-stax/pom.xml   (with props)
    camel/trunk/components/camel-stax/src/
    camel/trunk/components/camel-stax/src/main/
    camel/trunk/components/camel-stax/src/main/java/
    camel/trunk/components/camel-stax/src/main/java/org/
    camel/trunk/components/camel-stax/src/main/java/org/apache/
    camel/trunk/components/camel-stax/src/main/java/org/apache/camel/
    camel/trunk/components/camel-stax/src/main/java/org/apache/camel/component/
    camel/trunk/components/camel-stax/src/main/java/org/apache/camel/component/stax/
    camel/trunk/components/camel-stax/src/main/java/org/apache/camel/component/stax/StAXBuilder.java   (with props)
    camel/trunk/components/camel-stax/src/main/java/org/apache/camel/component/stax/StAXComponent.java   (with props)
    camel/trunk/components/camel-stax/src/main/java/org/apache/camel/component/stax/StAXJAXBIteratorExpression.java   (with props)
    camel/trunk/components/camel-stax/src/main/java/org/apache/camel/component/stax/StAXProcessor.java   (with props)
    camel/trunk/components/camel-stax/src/main/java/org/apache/camel/component/stax/StAXUtil.java   (with props)
    camel/trunk/components/camel-stax/src/main/java/org/apache/camel/component/stax/StaxStreamXMLReader.java   (with props)
    camel/trunk/components/camel-stax/src/main/resources/
    camel/trunk/components/camel-stax/src/main/resources/META-INF/
    camel/trunk/components/camel-stax/src/main/resources/META-INF/services/
    camel/trunk/components/camel-stax/src/main/resources/META-INF/services/org/
    camel/trunk/components/camel-stax/src/main/resources/META-INF/services/org/apache/
    camel/trunk/components/camel-stax/src/main/resources/META-INF/services/org/apache/camel/
    camel/trunk/components/camel-stax/src/main/resources/META-INF/services/org/apache/camel/component/
    camel/trunk/components/camel-stax/src/main/resources/META-INF/services/org/apache/camel/component/stax
    camel/trunk/components/camel-stax/src/test/
    camel/trunk/components/camel-stax/src/test/java/
    camel/trunk/components/camel-stax/src/test/java/org/
    camel/trunk/components/camel-stax/src/test/java/org/apache/
    camel/trunk/components/camel-stax/src/test/java/org/apache/camel/
    camel/trunk/components/camel-stax/src/test/java/org/apache/camel/component/
    camel/trunk/components/camel-stax/src/test/java/org/apache/camel/component/stax/
    camel/trunk/components/camel-stax/src/test/java/org/apache/camel/component/stax/CountingHandler.java   (with props)
    camel/trunk/components/camel-stax/src/test/java/org/apache/camel/component/stax/StAXComponentTest.java   (with props)
    camel/trunk/components/camel-stax/src/test/java/org/apache/camel/component/stax/StAXJAXBIteratorExpressionTest.java   (with props)
    camel/trunk/components/camel-stax/src/test/java/org/apache/camel/component/stax/StAXXPathSplitChoicePerformanceTest.java   (with props)
    camel/trunk/components/camel-stax/src/test/java/org/apache/camel/component/stax/model/
    camel/trunk/components/camel-stax/src/test/java/org/apache/camel/component/stax/model/Order.java   (with props)
    camel/trunk/components/camel-stax/src/test/java/org/apache/camel/component/stax/model/Orders.java   (with props)
    camel/trunk/components/camel-stax/src/test/java/org/apache/camel/component/stax/model/Record.java   (with props)
    camel/trunk/components/camel-stax/src/test/java/org/apache/camel/component/stax/model/Records.java   (with props)
    camel/trunk/components/camel-stax/src/test/java/org/apache/camel/component/stax/model/RecordsUtil.java   (with props)
    camel/trunk/components/camel-stax/src/test/resources/
    camel/trunk/components/camel-stax/src/test/resources/log4j.properties   (with props)
    camel/trunk/components/camel-stax/src/test/resources/org/
    camel/trunk/components/camel-stax/src/test/resources/org/apache/
    camel/trunk/components/camel-stax/src/test/resources/org/apache/camel/
    camel/trunk/components/camel-stax/src/test/resources/org/apache/camel/component/
    camel/trunk/components/camel-stax/src/test/resources/org/apache/camel/component/stax/
    camel/trunk/components/camel-stax/src/test/resources/org/apache/camel/component/stax/model/
    camel/trunk/components/camel-stax/src/test/resources/org/apache/camel/component/stax/model/jaxb.index
    camel/trunk/components/camel-stax/src/test/resources/xsd/
    camel/trunk/components/camel-stax/src/test/resources/xsd/records.xsd   (with props)
    camel/trunk/tests/camel-itest-karaf/src/test/java/org/apache/camel/itest/karaf/CamelStAXTest.java
      - copied, changed from r1204884, camel/trunk/tests/camel-itest-karaf/src/test/java/org/apache/camel/itest/karaf/CamelStreamTest.java
Modified:
    camel/trunk/apache-camel/pom.xml
    camel/trunk/apache-camel/src/main/descriptors/common-bin.xml
    camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileConverter.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/converter/jaxp/StaxConverter.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/converter/jaxp/XmlConverter.java
    camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/GenericFileConverterTest.java
    camel/trunk/camel-core/src/test/java/org/apache/camel/converter/jaxp/XmlConverterTest.java
    camel/trunk/components/pom.xml
    camel/trunk/parent/pom.xml
    camel/trunk/platforms/karaf/features/src/main/resources/features.xml

Modified: camel/trunk/apache-camel/pom.xml
URL: http://svn.apache.org/viewvc/camel/trunk/apache-camel/pom.xml?rev=1205018&r1=1205017&r2=1205018&view=diff
==============================================================================
--- camel/trunk/apache-camel/pom.xml (original)
+++ camel/trunk/apache-camel/pom.xml Tue Nov 22 14:30:16 2011
@@ -427,6 +427,10 @@
     </dependency>
     <dependency>
       <groupId>org.apache.camel</groupId>
+      <artifactId>camel-stax</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.camel</groupId>
       <artifactId>camel-stream</artifactId>
     </dependency>
     <dependency>

Modified: camel/trunk/apache-camel/src/main/descriptors/common-bin.xml
URL: http://svn.apache.org/viewvc/camel/trunk/apache-camel/src/main/descriptors/common-bin.xml?rev=1205018&r1=1205017&r2=1205018&view=diff
==============================================================================
--- camel/trunk/apache-camel/src/main/descriptors/common-bin.xml (original)
+++ camel/trunk/apache-camel/src/main/descriptors/common-bin.xml Tue Nov 22 14:30:16 2011
@@ -125,6 +125,7 @@
         <include>org.apache.camel:camel-spring-security</include>
         <include>org.apache.camel:camel-spring-ws</include>
         <include>org.apache.camel:camel-sql</include>
+        <include>org.apache.camel:camel-stax</include>
         <include>org.apache.camel:camel-stream</include>
         <include>org.apache.camel:camel-stringtemplate</include>
         <include>org.apache.camel:camel-syslog</include>

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileConverter.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileConverter.java?rev=1205018&r1=1205017&r2=1205018&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileConverter.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileConverter.java Tue Nov 22 14:30:16 2011
@@ -16,6 +16,7 @@
  */
 package org.apache.camel.component.file;
 
+import java.io.BufferedInputStream;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.IOException;
@@ -67,7 +68,7 @@ public final class GenericFileConverter 
         if (exchange != null) {
             // use a file input stream if its a java.io.File
             if (file.getFile() instanceof java.io.File) {
-                return new FileInputStream((File) file.getFile());
+                return new BufferedInputStream(new FileInputStream((File) file.getFile()));
             }
             // otherwise ensure the body is loaded as we want the input stream of the body
             file.getBinding().loadContent(exchange, file);

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/converter/jaxp/StaxConverter.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/jaxp/StaxConverter.java?rev=1205018&r1=1205017&r2=1205018&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/converter/jaxp/StaxConverter.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/converter/jaxp/StaxConverter.java Tue Nov 22 14:30:16 2011
@@ -16,6 +16,10 @@
  */
 package org.apache.camel.converter.jaxp;
 
+import java.io.BufferedInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
 import java.io.InputStream;
 import java.io.OutputStream;
 import java.io.Reader;
@@ -89,6 +93,12 @@ public class StaxConverter {
     }
 
     @Converter
+    public XMLStreamReader createXMLStreamReader(File file, Exchange exchange) throws XMLStreamException, FileNotFoundException {
+        InputStream is = new BufferedInputStream(new FileInputStream(file));
+        return getInputFactory().createXMLStreamReader(is, IOHelper.getCharsetName(exchange));
+    }
+
+    @Converter
     public XMLStreamReader createXMLStreamReader(Reader in) throws XMLStreamException {
         return getInputFactory().createXMLStreamReader(in);
     }
@@ -112,6 +122,12 @@ public class StaxConverter {
     }
 
     @Converter
+    public XMLEventReader createXMLEventReader(File file, Exchange exchange) throws XMLStreamException, FileNotFoundException {
+        InputStream is = new BufferedInputStream(new FileInputStream(file));
+        return getInputFactory().createXMLEventReader(is, IOHelper.getCharsetName(exchange));
+    }
+
+    @Converter
     public XMLEventReader createXMLEventReader(Reader in) throws XMLStreamException {
         return getInputFactory().createXMLEventReader(in);
     }

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/converter/jaxp/XmlConverter.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/jaxp/XmlConverter.java?rev=1205018&r1=1205017&r2=1205018&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/converter/jaxp/XmlConverter.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/converter/jaxp/XmlConverter.java Tue Nov 22 14:30:16 2011
@@ -16,6 +16,7 @@
  */
 package org.apache.camel.converter.jaxp;
 
+import java.io.BufferedInputStream;
 import java.io.ByteArrayInputStream;
 import java.io.File;
 import java.io.FileInputStream;
@@ -27,6 +28,7 @@ import java.io.Reader;
 import java.io.StringReader;
 import java.io.StringWriter;
 import java.lang.reflect.Constructor;
+import java.nio.Buffer;
 import java.nio.ByteBuffer;
 import java.util.Properties;
 
@@ -860,7 +862,13 @@ public class XmlConverter {
     }
 
     @Converter
-    public InputSource toInputSource(InputStream is) {
+    public InputSource toInputSource(InputStream is, Exchange exchange) {
+        return new InputSource(is);
+    }
+
+    @Converter
+    public InputSource toInputSource(File file, Exchange exchange) throws FileNotFoundException {
+        InputStream is = new BufferedInputStream(new FileInputStream(file));
         return new InputSource(is);
     }
 

Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/GenericFileConverterTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/GenericFileConverterTest.java?rev=1205018&r1=1205017&r2=1205018&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/GenericFileConverterTest.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/GenericFileConverterTest.java Tue Nov 22 14:30:16 2011
@@ -16,6 +16,7 @@
  */
 package org.apache.camel.component.file;
 
+import java.io.BufferedInputStream;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.InputStream;
@@ -157,7 +158,7 @@ public class GenericFileConverterTest ex
                         @Override
                         public void process(Exchange exchange) throws Exception {
                             Object body = exchange.getIn().getBody();
-                            assertIsInstanceOf(FileInputStream.class, body);
+                            assertIsInstanceOf(BufferedInputStream.class, body);
                         }
                     })
                     .to("mock:result");
@@ -165,9 +166,11 @@ public class GenericFileConverterTest ex
         });
         context.start();
 
+        // a file input stream is wrapped in a buffered so its faster
+
         MockEndpoint mock = getMockEndpoint("mock:result");
         mock.expectedMessageCount(1);
-        mock.message(0).body().isInstanceOf(FileInputStream.class);
+        mock.message(0).body().isInstanceOf(BufferedInputStream.class);
         mock.message(0).body(String.class).isEqualTo("Hello World");
 
         template.sendBodyAndHeader("file://target/gf", "Hello World", Exchange.FILE_NAME, "hello.txt");

Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/converter/jaxp/XmlConverterTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/converter/jaxp/XmlConverterTest.java?rev=1205018&r1=1205017&r2=1205018&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/converter/jaxp/XmlConverterTest.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/converter/jaxp/XmlConverterTest.java Tue Nov 22 14:30:16 2011
@@ -474,11 +474,20 @@ public class XmlConverterTest extends Co
         XmlConverter conv = new XmlConverter();
 
         InputStream is = context.getTypeConverter().convertTo(InputStream.class, "<foo>bar</foo>");
-        InputSource out = conv.toInputSource(is);
+        InputSource out = conv.toInputSource(is, null);
         assertNotNull(out);
         assertNotNull(out.getByteStream());
     }
     
+    public void testToInputSourceFromFile() throws Exception {
+        XmlConverter conv = new XmlConverter();
+        File file = new File("./src/test/resources/org/apache/camel/converter/stream/test.xml").getAbsoluteFile();
+
+        InputSource out = conv.toInputSource(file, null);
+        assertNotNull(out);
+        assertNotNull(out.getByteStream());
+    }
+
     public void testOutOptionsFromCamelContext() throws Exception {
         CamelContext context = new DefaultCamelContext();        
         Exchange exchange =  new DefaultExchange(context);

Propchange: camel/trunk/components/camel-stax/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Tue Nov 22 14:30:16 2011
@@ -0,0 +1,8 @@
+eclipse-classes
+.pmd
+.checkstyle
+target
+.classpath
+.project
+.settings
+*.i??

Added: camel/trunk/components/camel-stax/pom.xml
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-stax/pom.xml?rev=1205018&view=auto
==============================================================================
--- camel/trunk/components/camel-stax/pom.xml (added)
+++ camel/trunk/components/camel-stax/pom.xml Tue Nov 22 14:30:16 2011
@@ -0,0 +1,65 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You under the Apache License, Version 2.0
+  (the "License"); you may not use this file except in compliance with
+  the License.  You may obtain a copy of the License at
+
+  http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+<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/xsd/maven-4.0.0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+
+  <parent>
+    <groupId>org.apache.camel</groupId>
+    <artifactId>components</artifactId>
+    <version>2.9-SNAPSHOT</version>
+  </parent>
+
+  <artifactId>camel-stax</artifactId>
+  <packaging>bundle</packaging>
+  <name>Camel :: StAX</name>
+  <description>Camel StAX support</description>
+
+  <properties>
+      <camel.osgi.export.pkg>org.apache.camel.component.stax.*</camel.osgi.export.pkg>
+  </properties>
+
+  <dependencies>
+
+    <dependency>
+      <groupId>org.apache.camel</groupId>
+      <artifactId>camel-core</artifactId>
+    </dependency>
+
+    <dependency>
+      <groupId>org.apache.camel</groupId>
+      <artifactId>camel-test</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <!-- camel-jaxb is used for XPath testing -->
+    <dependency>
+      <groupId>org.apache.camel</groupId>
+      <artifactId>camel-jaxb</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>slf4j-log4j12</artifactId>
+      <scope>test</scope>
+    </dependency>
+
+  </dependencies>
+
+</project>
+

Propchange: camel/trunk/components/camel-stax/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-stax/pom.xml
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: camel/trunk/components/camel-stax/pom.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml

Added: camel/trunk/components/camel-stax/src/main/java/org/apache/camel/component/stax/StAXBuilder.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-stax/src/main/java/org/apache/camel/component/stax/StAXBuilder.java?rev=1205018&view=auto
==============================================================================
--- camel/trunk/components/camel-stax/src/main/java/org/apache/camel/component/stax/StAXBuilder.java (added)
+++ camel/trunk/components/camel-stax/src/main/java/org/apache/camel/component/stax/StAXBuilder.java Tue Nov 22 14:30:16 2011
@@ -0,0 +1,30 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.stax;
+
+import org.apache.camel.Expression;
+
+public final class StAXBuilder {
+
+    private StAXBuilder() {
+        // no-op
+    }
+
+    public static <T> Expression stax(Class<T> clazz) {
+        return new StAXJAXBIteratorExpression<T>(clazz);
+    }
+}

Propchange: camel/trunk/components/camel-stax/src/main/java/org/apache/camel/component/stax/StAXBuilder.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-stax/src/main/java/org/apache/camel/component/stax/StAXBuilder.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: camel/trunk/components/camel-stax/src/main/java/org/apache/camel/component/stax/StAXComponent.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-stax/src/main/java/org/apache/camel/component/stax/StAXComponent.java?rev=1205018&view=auto
==============================================================================
--- camel/trunk/components/camel-stax/src/main/java/org/apache/camel/component/stax/StAXComponent.java (added)
+++ camel/trunk/components/camel-stax/src/main/java/org/apache/camel/component/stax/StAXComponent.java Tue Nov 22 14:30:16 2011
@@ -0,0 +1,37 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.stax;
+
+import java.util.Map;
+
+import org.xml.sax.ContentHandler;
+
+import org.apache.camel.Endpoint;
+import org.apache.camel.impl.DefaultComponent;
+import org.apache.camel.impl.ProcessorEndpoint;
+
+public class StAXComponent extends DefaultComponent {
+
+    @Override
+    protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
+        Class<ContentHandler> clazz = getCamelContext().getClassResolver().resolveMandatoryClass(remaining, ContentHandler.class);
+
+        StAXProcessor processor = new StAXProcessor(clazz);
+        setProperties(processor, parameters);
+        return new ProcessorEndpoint(uri, this, processor);
+    }
+}

Propchange: camel/trunk/components/camel-stax/src/main/java/org/apache/camel/component/stax/StAXComponent.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-stax/src/main/java/org/apache/camel/component/stax/StAXComponent.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: camel/trunk/components/camel-stax/src/main/java/org/apache/camel/component/stax/StAXJAXBIteratorExpression.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-stax/src/main/java/org/apache/camel/component/stax/StAXJAXBIteratorExpression.java?rev=1205018&view=auto
==============================================================================
--- camel/trunk/components/camel-stax/src/main/java/org/apache/camel/component/stax/StAXJAXBIteratorExpression.java (added)
+++ camel/trunk/components/camel-stax/src/main/java/org/apache/camel/component/stax/StAXJAXBIteratorExpression.java Tue Nov 22 14:30:16 2011
@@ -0,0 +1,184 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.stax;
+
+import java.io.Closeable;
+import java.io.IOException;
+import java.util.Iterator;
+import java.util.Map;
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBElement;
+import javax.xml.bind.JAXBException;
+import javax.xml.bind.Unmarshaller;
+import javax.xml.stream.XMLEventReader;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.events.XMLEvent;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.InvalidPayloadException;
+import org.apache.camel.RuntimeCamelException;
+import org.apache.camel.support.ExpressionAdapter;
+import org.apache.camel.util.LRUSoftCache;
+import org.apache.camel.util.ObjectHelper;
+
+import static org.apache.camel.component.stax.StAXUtil.getTagName;
+
+/**
+ * {@link org.apache.camel.Expression} to walk a {@link org.apache.camel.Message} body
+ * using an {@link Iterator}, which uses StAX to walk in streaming mode.
+ * The elements returned is a POJO which is bound using JAXB annotations.
+ * <p/>
+ * The message body must be able to convert to {@link XMLEventReader} type which is used as stream
+ * to access the message body. And there must be a JAXB annotated class to use as binding.
+ */
+public class StAXJAXBIteratorExpression<T> extends ExpressionAdapter {
+    private static final Map<Class<?>, JAXBContext> JAX_CONTEXTS = new LRUSoftCache<Class<?>, JAXBContext>(1000);
+
+    private final Class<T> handled;
+
+    /**
+     * Creates this expression.
+     *
+     * @param handled the class which has JAXB annotations to bind POJO.
+     */
+    public StAXJAXBIteratorExpression(Class<T> handled) {
+        ObjectHelper.notNull(handled, "handled");
+        this.handled = handled;
+    }
+
+    private static JAXBContext jaxbContext(Class<?> handled) throws JAXBException {
+        if (JAX_CONTEXTS.containsKey(handled)) {
+            return JAX_CONTEXTS.get(handled);
+        }
+
+        JAXBContext context;
+        synchronized (JAX_CONTEXTS) {
+            context = JAXBContext.newInstance(handled);
+            JAX_CONTEXTS.put(handled, context);
+        }
+        return context;
+    }
+
+    @Override
+    public Object evaluate(Exchange exchange) {
+        try {
+            XMLEventReader reader = exchange.getIn().getMandatoryBody(XMLEventReader.class);
+            return createIterator(reader, handled);
+        } catch (InvalidPayloadException e) {
+            exchange.setException(e);
+            return null;
+        } catch (JAXBException e) {
+            exchange.setException(e);
+            return null;
+        }
+    }
+
+    private Iterator<T> createIterator(XMLEventReader reader, Class<T> clazz) throws JAXBException {
+        return new StAXJAXBIterator<T>(clazz, reader);
+    }
+
+    /**
+     * Iterator to walk the XML reader
+     */
+    static class StAXJAXBIterator<T> implements Iterator<T>, Closeable {
+
+        private final XMLEventReader reader;
+        private final Class<T> clazz;
+        private final String name;
+        private final Unmarshaller unmarshaller;
+        private T element;
+
+        StAXJAXBIterator(Class<T> clazz, XMLEventReader reader) throws JAXBException {
+            this.clazz = clazz;
+            this.reader = reader;
+
+            name = getTagName(clazz);
+            JAXBContext jaxb = jaxbContext(clazz);
+            // unmarshaller is not thread safe so we need to create a new instance per iterator
+            unmarshaller = jaxb.createUnmarshaller();
+        }
+
+        @Override
+        public boolean hasNext() {
+            if (element == null) {
+                element = getNextElement();
+            }
+            return element != null;
+        }
+
+        @Override
+        public T next() {
+            if (element == null) {
+                element = getNextElement();
+            }
+
+            T answer = element;
+            element = null;
+            return answer;
+        }
+
+        @Override
+        public void remove() {
+            throw new UnsupportedOperationException();
+        }
+
+        @SuppressWarnings("unchecked")
+        T getNextElement() {
+            XMLEvent xmlEvent;
+            boolean found = false;
+            while (!found && reader.hasNext()) {
+                try {
+                    xmlEvent = reader.peek();
+                    if (xmlEvent != null && xmlEvent.isStartElement() && name.equals(xmlEvent.asStartElement().getName().getLocalPart())) {
+                        found = true;
+                    } else {
+                        reader.nextEvent();
+                    }
+                } catch (XMLStreamException e) {
+                    throw new RuntimeCamelException(e);
+                }
+            }
+
+            if (!found) {
+                return null;
+            }
+
+            Object answer;
+            try {
+                answer = unmarshaller.unmarshal(reader, clazz);
+                if (answer != null && answer.getClass() == JAXBElement.class) {
+                    JAXBElement jbe = (JAXBElement) answer;
+                    answer = jbe.getValue();
+                }
+            } catch (JAXBException e) {
+                throw new RuntimeCamelException(e);
+            }
+
+            return (T) answer;
+        }
+
+        @Override
+        public void close() throws IOException {
+            try {
+                reader.close();
+            } catch (XMLStreamException e) {
+                throw new IOException(e);
+            }
+        }
+    }
+
+}

Propchange: camel/trunk/components/camel-stax/src/main/java/org/apache/camel/component/stax/StAXJAXBIteratorExpression.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-stax/src/main/java/org/apache/camel/component/stax/StAXJAXBIteratorExpression.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: camel/trunk/components/camel-stax/src/main/java/org/apache/camel/component/stax/StAXProcessor.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-stax/src/main/java/org/apache/camel/component/stax/StAXProcessor.java?rev=1205018&view=auto
==============================================================================
--- camel/trunk/components/camel-stax/src/main/java/org/apache/camel/component/stax/StAXProcessor.java (added)
+++ camel/trunk/components/camel-stax/src/main/java/org/apache/camel/component/stax/StAXProcessor.java Tue Nov 22 14:30:16 2011
@@ -0,0 +1,62 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.stax;
+
+import javax.xml.stream.XMLStreamReader;
+
+import org.xml.sax.ContentHandler;
+import org.xml.sax.InputSource;
+import org.xml.sax.XMLReader;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.util.ExchangeHelper;
+
+/**
+ * It uses SAX content handler to handle events.
+ * <p/>
+ * The {@link Exchange} is expected to contain a message body, that is
+ * convertable to both a {@link InputSource} and a {@link XMLStreamReader}
+ * to support StAX streaming.
+ */
+public class StAXProcessor implements Processor {
+    private final Class<ContentHandler> contentHandlerClass;
+
+    public StAXProcessor(Class<ContentHandler> contentHandlerClass) {
+        this.contentHandlerClass = contentHandlerClass;
+    }
+
+    @Override
+    public void process(Exchange exchange) throws Exception {
+        InputSource is = exchange.getIn().getMandatoryBody(InputSource.class);
+        XMLStreamReader stream = exchange.getIn().getMandatoryBody(XMLStreamReader.class);
+        XMLReader reader = new StaxStreamXMLReader(stream);
+
+        ContentHandler handler = contentHandlerClass.newInstance();
+        reader.setContentHandler(handler);
+        reader.parse(is);
+
+        if (ExchangeHelper.isOutCapable(exchange)) {
+            // preserve headers
+            exchange.getOut().setHeaders(exchange.getIn().getHeaders());
+            exchange.getOut().setBody(handler);
+        } else {
+            exchange.getIn().setBody(handler);
+        }
+    }
+
+}

Propchange: camel/trunk/components/camel-stax/src/main/java/org/apache/camel/component/stax/StAXProcessor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-stax/src/main/java/org/apache/camel/component/stax/StAXProcessor.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: camel/trunk/components/camel-stax/src/main/java/org/apache/camel/component/stax/StAXUtil.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-stax/src/main/java/org/apache/camel/component/stax/StAXUtil.java?rev=1205018&view=auto
==============================================================================
--- camel/trunk/components/camel-stax/src/main/java/org/apache/camel/component/stax/StAXUtil.java (added)
+++ camel/trunk/components/camel-stax/src/main/java/org/apache/camel/component/stax/StAXUtil.java Tue Nov 22 14:30:16 2011
@@ -0,0 +1,50 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.stax;
+
+import java.util.Map;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlType;
+
+import org.apache.camel.util.LRUSoftCache;
+
+public final class StAXUtil {
+    private static final Map<Class<?>, String> TAG_NAMES = new LRUSoftCache<Class<?>, String>(1000);
+
+    private StAXUtil() {
+        // no-op
+    }
+
+    public static String getTagName(Class<?> handled) {
+        if (TAG_NAMES.containsKey(handled)) {
+            return TAG_NAMES.get(handled);
+        }
+
+        XmlType xmlType = handled.getAnnotation(XmlType.class);
+        if (xmlType != null && xmlType.name() != null && xmlType.name().trim().length() > 0) {
+            TAG_NAMES.put(handled, xmlType.name());
+            return xmlType.name();
+        } else {
+            XmlRootElement xmlRoot = handled.getAnnotation(XmlRootElement.class);
+            if (xmlRoot != null && xmlRoot.name() != null && xmlRoot.name().trim().length() > 0) {
+                TAG_NAMES.put(handled, xmlRoot.name());
+                return xmlRoot.name();
+            }
+        }
+        throw new IllegalArgumentException("XML name not found for " + handled.getName());
+    }
+}

Propchange: camel/trunk/components/camel-stax/src/main/java/org/apache/camel/component/stax/StAXUtil.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-stax/src/main/java/org/apache/camel/component/stax/StAXUtil.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: camel/trunk/components/camel-stax/src/main/java/org/apache/camel/component/stax/StaxStreamXMLReader.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-stax/src/main/java/org/apache/camel/component/stax/StaxStreamXMLReader.java?rev=1205018&view=auto
==============================================================================
--- camel/trunk/components/camel-stax/src/main/java/org/apache/camel/component/stax/StaxStreamXMLReader.java (added)
+++ camel/trunk/components/camel-stax/src/main/java/org/apache/camel/component/stax/StaxStreamXMLReader.java Tue Nov 22 14:30:16 2011
@@ -0,0 +1,571 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.stax;
+
+import java.util.LinkedHashMap;
+import java.util.Map;
+import javax.xml.namespace.QName;
+import javax.xml.stream.Location;
+import javax.xml.stream.XMLStreamConstants;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import org.xml.sax.Attributes;
+import org.xml.sax.ContentHandler;
+import org.xml.sax.DTDHandler;
+import org.xml.sax.EntityResolver;
+import org.xml.sax.ErrorHandler;
+import org.xml.sax.InputSource;
+import org.xml.sax.Locator;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXNotRecognizedException;
+import org.xml.sax.SAXNotSupportedException;
+import org.xml.sax.SAXParseException;
+import org.xml.sax.XMLReader;
+import org.xml.sax.ext.LexicalHandler;
+import org.xml.sax.ext.Locator2;
+import org.xml.sax.helpers.AttributesImpl;
+
+import org.apache.camel.util.ObjectHelper;
+
+/**
+ * class extracted from spring 3.0.6.RELEASE.
+ */
+// CHECKSTYLE:OFF
+public class StaxStreamXMLReader implements XMLReader {
+
+	private static final String DEFAULT_XML_VERSION = "1.0";
+
+    private static final String NAMESPACES_FEATURE_NAME = "http://xml.org/sax/features/namespaces";
+
+	private static final String NAMESPACE_PREFIXES_FEATURE_NAME = "http://xml.org/sax/features/namespace-prefixes";
+
+	private static final String IS_STANDALONE_FEATURE_NAME = "http://xml.org/sax/features/is-standalone";
+
+    private DTDHandler dtdHandler;
+
+	private ContentHandler contentHandler;
+
+	private EntityResolver entityResolver;
+
+	private ErrorHandler errorHandler;
+
+	private LexicalHandler lexicalHandler;
+
+	private boolean namespacesFeature = true;
+
+	private boolean namespacePrefixesFeature = false;
+
+	private Boolean isStandalone;
+
+	private final Map<String, String> namespaces = new LinkedHashMap<String, String>();
+
+	private final XMLStreamReader reader;
+
+	private String xmlVersion = DEFAULT_XML_VERSION;
+
+	private String encoding;
+
+	/**
+	 * Constructs a new instance of the <code>StaxStreamXmlReader</code> that reads from the given
+	 * <code>XMLStreamReader</code>.  The supplied stream reader must be in <code>XMLStreamConstants.START_DOCUMENT</code>
+	 * or <code>XMLStreamConstants.START_ELEMENT</code> state.
+	 *
+	 * @param reader the <code>XMLEventReader</code> to read from
+	 * @throws IllegalStateException if the reader is not at the start of a document or element
+	 */
+	StaxStreamXMLReader(XMLStreamReader reader) {
+		if (reader == null) {
+            throw new IllegalArgumentException("'reader' must not be null");
+        }
+		int event = reader.getEventType();
+		if (!(event == XMLStreamConstants.START_DOCUMENT || event == XMLStreamConstants.START_ELEMENT)) {
+			throw new IllegalStateException("XMLEventReader not at start of document or element");
+		}
+		this.reader = reader;
+	}
+
+	protected void parseInternal() throws SAXException, XMLStreamException {
+		boolean documentStarted = false;
+		boolean documentEnded = false;
+		int elementDepth = 0;
+		int eventType = reader.getEventType();
+		while (true) {
+			if (eventType != XMLStreamConstants.START_DOCUMENT && eventType != XMLStreamConstants.END_DOCUMENT &&
+					!documentStarted) {
+				handleStartDocument();
+				documentStarted = true;
+			}
+			switch (eventType) {
+				case XMLStreamConstants.START_ELEMENT:
+					elementDepth++;
+					handleStartElement();
+					break;
+				case XMLStreamConstants.END_ELEMENT:
+					elementDepth--;
+					if (elementDepth >= 0) {
+						handleEndElement();
+					}
+					break;
+				case XMLStreamConstants.PROCESSING_INSTRUCTION:
+					handleProcessingInstruction();
+					break;
+				case XMLStreamConstants.CHARACTERS:
+				case XMLStreamConstants.SPACE:
+				case XMLStreamConstants.CDATA:
+					handleCharacters();
+					break;
+				case XMLStreamConstants.START_DOCUMENT:
+					handleStartDocument();
+					documentStarted = true;
+					break;
+				case XMLStreamConstants.END_DOCUMENT:
+					handleEndDocument();
+					documentEnded = true;
+					break;
+				case XMLStreamConstants.COMMENT:
+					handleComment();
+					break;
+				case XMLStreamConstants.DTD:
+					handleDtd();
+					break;
+				case XMLStreamConstants.ENTITY_REFERENCE:
+					handleEntityReference();
+					break;
+			}
+			if (reader.hasNext() && elementDepth >= 0) {
+				eventType = reader.next();
+			}
+			else {
+				break;
+			}
+		}
+		if (!documentEnded) {
+			handleEndDocument();
+		}
+	}
+
+	private void handleStartDocument() throws SAXException {
+		if (XMLStreamConstants.START_DOCUMENT == reader.getEventType()) {
+			String xmlVersion = reader.getVersion();
+			if (ObjectHelper.isNotEmpty(xmlVersion)) {
+				this.xmlVersion = xmlVersion;
+			}
+			this.encoding = reader.getCharacterEncodingScheme();
+		}
+
+		if (getContentHandler() != null) {
+			final Location location = reader.getLocation();
+
+			getContentHandler().setDocumentLocator(new Locator2() {
+
+				public int getColumnNumber() {
+					return location != null ? location.getColumnNumber() : -1;
+				}
+
+				public int getLineNumber() {
+					return location != null ? location.getLineNumber() : -1;
+				}
+
+				public String getPublicId() {
+					return location != null ? location.getPublicId() : null;
+				}
+
+				public String getSystemId() {
+					return location != null ? location.getSystemId() : null;
+				}
+
+				public String getXMLVersion() {
+					return xmlVersion;
+				}
+
+				public String getEncoding() {
+					return encoding;
+				}
+			});
+			getContentHandler().startDocument();
+			if (reader.standaloneSet()) {
+				setStandalone(reader.isStandalone());
+			}
+		}
+	}
+
+	private void handleStartElement() throws SAXException {
+		if (getContentHandler() != null) {
+			QName qName = reader.getName();
+			if (hasNamespacesFeature()) {
+				for (int i = 0; i < reader.getNamespaceCount(); i++) {
+					startPrefixMapping(reader.getNamespacePrefix(i), reader.getNamespaceURI(i));
+				}
+				for (int i = 0; i < reader.getAttributeCount(); i++) {
+					String prefix = reader.getAttributePrefix(i);
+					String namespace = reader.getAttributeNamespace(i);
+					if (ObjectHelper.isNotEmpty(namespace)) {
+						startPrefixMapping(prefix, namespace);
+					}
+				}
+				getContentHandler().startElement(qName.getNamespaceURI(), qName.getLocalPart(), toQualifiedName(qName),
+						getAttributes());
+			}
+			else {
+				getContentHandler().startElement("", "", toQualifiedName(qName), getAttributes());
+			}
+		}
+	}
+
+	private void handleEndElement() throws SAXException {
+		if (getContentHandler() != null) {
+			QName qName = reader.getName();
+			if (hasNamespacesFeature()) {
+				getContentHandler().endElement(qName.getNamespaceURI(), qName.getLocalPart(), toQualifiedName(qName));
+				for (int i = 0; i < reader.getNamespaceCount(); i++) {
+					String prefix = reader.getNamespacePrefix(i);
+					if (prefix == null) {
+						prefix = "";
+					}
+					endPrefixMapping(prefix);
+				}
+			}
+			else {
+				getContentHandler().endElement("", "", toQualifiedName(qName));
+			}
+		}
+	}
+
+	private void handleCharacters() throws SAXException {
+		if (getContentHandler() != null && reader.isWhiteSpace()) {
+			getContentHandler()
+					.ignorableWhitespace(reader.getTextCharacters(), reader.getTextStart(), reader.getTextLength());
+			return;
+		}
+		if (XMLStreamConstants.CDATA == reader.getEventType() && getLexicalHandler() != null) {
+			getLexicalHandler().startCDATA();
+		}
+		if (getContentHandler() != null) {
+			getContentHandler().characters(reader.getTextCharacters(), reader.getTextStart(), reader.getTextLength());
+		}
+		if (XMLStreamConstants.CDATA == reader.getEventType() && getLexicalHandler() != null) {
+			getLexicalHandler().endCDATA();
+		}
+	}
+
+	private void handleComment() throws SAXException {
+		if (getLexicalHandler() != null) {
+			getLexicalHandler().comment(reader.getTextCharacters(), reader.getTextStart(), reader.getTextLength());
+		}
+	}
+
+	private void handleDtd() throws SAXException {
+		if (getLexicalHandler() != null) {
+			javax.xml.stream.Location location = reader.getLocation();
+			getLexicalHandler().startDTD(null, location.getPublicId(), location.getSystemId());
+		}
+		if (getLexicalHandler() != null) {
+			getLexicalHandler().endDTD();
+		}
+	}
+
+	private void handleEntityReference() throws SAXException {
+		if (getLexicalHandler() != null) {
+			getLexicalHandler().startEntity(reader.getLocalName());
+		}
+		if (getLexicalHandler() != null) {
+			getLexicalHandler().endEntity(reader.getLocalName());
+		}
+	}
+
+	private void handleEndDocument() throws SAXException {
+		if (getContentHandler() != null) {
+			getContentHandler().endDocument();
+		}
+	}
+
+	private void handleProcessingInstruction() throws SAXException {
+		if (getContentHandler() != null) {
+			getContentHandler().processingInstruction(reader.getPITarget(), reader.getPIData());
+		}
+	}
+
+	private Attributes getAttributes() {
+		AttributesImpl attributes = new AttributesImpl();
+
+		for (int i = 0; i < reader.getAttributeCount(); i++) {
+			String namespace = reader.getAttributeNamespace(i);
+			if (namespace == null || !hasNamespacesFeature()) {
+				namespace = "";
+			}
+			String type = reader.getAttributeType(i);
+			if (type == null) {
+				type = "CDATA";
+			}
+			attributes.addAttribute(namespace, reader.getAttributeLocalName(i),
+					toQualifiedName(reader.getAttributeName(i)), type, reader.getAttributeValue(i));
+		}
+		if (hasNamespacePrefixesFeature()) {
+			for (int i = 0; i < reader.getNamespaceCount(); i++) {
+				String prefix = reader.getNamespacePrefix(i);
+				String namespaceUri = reader.getNamespaceURI(i);
+				String qName;
+				if (ObjectHelper.isNotEmpty(prefix)) {
+					qName = "xmlns:" + prefix;
+				}
+				else {
+					qName = "xmlns";
+				}
+				attributes.addAttribute("", "", qName, "CDATA", namespaceUri);
+			}
+		}
+
+		return attributes;
+	}
+
+    // AbstractStaxXmlReader
+    @Override
+	public boolean getFeature(String name) throws SAXNotRecognizedException, SAXNotSupportedException {
+		if (NAMESPACES_FEATURE_NAME.equals(name)) {
+			return this.namespacesFeature;
+		}
+		else if (NAMESPACE_PREFIXES_FEATURE_NAME.equals(name)) {
+			return this.namespacePrefixesFeature;
+		}
+		else if (IS_STANDALONE_FEATURE_NAME.equals(name)) {
+			if (this.isStandalone != null) {
+				return this.isStandalone;
+			}
+			else {
+				throw new SAXNotSupportedException("startDocument() callback not completed yet");
+			}
+		}
+		else {
+			throw new SAXNotRecognizedException(name);
+		}
+	}
+
+	@Override
+	public void setFeature(String name, boolean value) throws SAXNotRecognizedException, SAXNotSupportedException {
+		if (NAMESPACES_FEATURE_NAME.equals(name)) {
+			this.namespacesFeature = value;
+		}
+		else if (NAMESPACE_PREFIXES_FEATURE_NAME.equals(name)) {
+			this.namespacePrefixesFeature = value;
+		}
+		else {
+			throw new SAXNotRecognizedException(name);
+		}
+	}
+
+	protected void setStandalone(boolean standalone) {
+		this.isStandalone = standalone;
+	}
+
+	/**
+	 * Indicates whether the SAX feature <code>http://xml.org/sax/features/namespaces</code> is turned on.
+	 */
+	protected boolean hasNamespacesFeature() {
+		return this.namespacesFeature;
+	}
+
+	/**
+	 * Indicates whether the SAX feature <code>http://xml.org/sax/features/namespaces-prefixes</code> is turned on.
+	 */
+	protected boolean hasNamespacePrefixesFeature() {
+		return this.namespacePrefixesFeature;
+	}
+
+	/**
+	 * Convert a <code>QName</code> to a qualified name, as used by DOM and SAX.
+	 * The returned string has a format of <code>prefix:localName</code> if the
+	 * prefix is set, or just <code>localName</code> if not.
+	 * @param qName the <code>QName</code>
+	 * @return the qualified name
+	 */
+	protected String toQualifiedName(QName qName) {
+		String prefix = qName.getPrefix();
+		if (!ObjectHelper.isNotEmpty(prefix)) {
+			return qName.getLocalPart();
+		}
+		else {
+			return prefix + ":" + qName.getLocalPart();
+		}
+	}
+
+
+	/**
+	 * Parse the StAX XML reader passed at construction-time.
+	 * <p><b>NOTE:</b>: The given <code>InputSource</code> is not read, but ignored.
+	 * @param ignored is ignored
+	 * @throws SAXException a SAX exception, possibly wrapping a <code>XMLStreamException</code>
+	 */
+	public final void parse(InputSource ignored) throws SAXException {
+		parse();
+	}
+
+	/**
+	 * Parse the StAX XML reader passed at construction-time.
+	 * <p><b>NOTE:</b>: The given system identifier is not read, but ignored.
+	 * @param ignored is ignored
+	 * @throws SAXException A SAX exception, possibly wrapping a <code>XMLStreamException</code>
+	 */
+	public final void parse(String ignored) throws SAXException {
+		parse();
+	}
+
+	private void parse() throws SAXException {
+		try {
+			parseInternal();
+		} catch (XMLStreamException ex) {
+			Locator locator = null;
+			if (ex.getLocation() != null) {
+				locator = new StaxLocator(ex.getLocation());
+			}
+			SAXParseException saxException = new SAXParseException(ex.getMessage(), locator, ex);
+			if (getErrorHandler() != null) {
+				getErrorHandler().fatalError(saxException);
+			}
+			else {
+				throw saxException;
+			}
+		}
+	}
+
+	/**
+	 * Starts the prefix mapping for the given prefix.
+	 * @see org.xml.sax.ContentHandler#startPrefixMapping(String, String)
+	 */
+	protected void startPrefixMapping(String prefix, String namespace) throws SAXException {
+		if (getContentHandler() != null) {
+			if (prefix == null) {
+				prefix = "";
+			}
+			if (!ObjectHelper.isNotEmpty(namespace)) {
+				return;
+			}
+			if (!namespace.equals(namespaces.get(prefix))) {
+				getContentHandler().startPrefixMapping(prefix, namespace);
+				namespaces.put(prefix, namespace);
+			}
+		}
+	}
+
+	/**
+	 * Ends the prefix mapping for the given prefix.
+	 * @see org.xml.sax.ContentHandler#endPrefixMapping(String)
+	 */
+	protected void endPrefixMapping(String prefix) throws SAXException {
+		if (getContentHandler() != null) {
+			if (namespaces.containsKey(prefix)) {
+				getContentHandler().endPrefixMapping(prefix);
+				namespaces.remove(prefix);
+			}
+		}
+	}
+
+	/**
+	 * Implementation of the <code>Locator</code> interface that is based on a StAX <code>Location</code>.
+	 * @see Locator
+	 * @see Location
+	 */
+	private static class StaxLocator implements Locator {
+
+		private Location location;
+
+		protected StaxLocator(Location location) {
+			this.location = location;
+		}
+
+		public String getPublicId() {
+			return location.getPublicId();
+		}
+
+		public String getSystemId() {
+			return location.getSystemId();
+		}
+
+		public int getLineNumber() {
+			return location.getLineNumber();
+		}
+
+		public int getColumnNumber() {
+			return location.getColumnNumber();
+		}
+	}
+
+    // AbstractXMLReader
+
+    public ContentHandler getContentHandler() {
+		return contentHandler;
+	}
+
+	public void setContentHandler(ContentHandler contentHandler) {
+		this.contentHandler = contentHandler;
+	}
+
+	public void setDTDHandler(DTDHandler dtdHandler) {
+		this.dtdHandler = dtdHandler;
+	}
+
+	public DTDHandler getDTDHandler() {
+		return dtdHandler;
+	}
+
+	public EntityResolver getEntityResolver() {
+		return entityResolver;
+	}
+
+	public void setEntityResolver(EntityResolver entityResolver) {
+		this.entityResolver = entityResolver;
+	}
+
+	public ErrorHandler getErrorHandler() {
+		return errorHandler;
+	}
+
+	public void setErrorHandler(ErrorHandler errorHandler) {
+		this.errorHandler = errorHandler;
+	}
+
+	protected LexicalHandler getLexicalHandler() {
+		return lexicalHandler;
+	}
+
+	/**
+	 * Throws a <code>SAXNotRecognizedException</code> exception when the given property does not signify a lexical
+	 * handler. The property name for a lexical handler is <code>http://xml.org/sax/properties/lexical-handler</code>.
+	 */
+	public Object getProperty(String name) throws SAXNotRecognizedException, SAXNotSupportedException {
+		if ("http://xml.org/sax/properties/lexical-handler".equals(name)) {
+			return lexicalHandler;
+		}
+		else {
+			throw new SAXNotRecognizedException(name);
+		}
+	}
+
+	/**
+	 * Throws a <code>SAXNotRecognizedException</code> exception when the given property does not signify a lexical
+	 * handler. The property name for a lexical handler is <code>http://xml.org/sax/properties/lexical-handler</code>.
+	 */
+	public void setProperty(String name, Object value) throws SAXNotRecognizedException, SAXNotSupportedException {
+		if ("http://xml.org/sax/properties/lexical-handler".equals(name)) {
+			lexicalHandler = (LexicalHandler) value;
+		}
+		else {
+			throw new SAXNotRecognizedException(name);
+		}
+	}
+}
+// CHECKSTYLE:ON

Propchange: camel/trunk/components/camel-stax/src/main/java/org/apache/camel/component/stax/StaxStreamXMLReader.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-stax/src/main/java/org/apache/camel/component/stax/StaxStreamXMLReader.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: camel/trunk/components/camel-stax/src/main/resources/META-INF/services/org/apache/camel/component/stax
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-stax/src/main/resources/META-INF/services/org/apache/camel/component/stax?rev=1205018&view=auto
==============================================================================
--- camel/trunk/components/camel-stax/src/main/resources/META-INF/services/org/apache/camel/component/stax (added)
+++ camel/trunk/components/camel-stax/src/main/resources/META-INF/services/org/apache/camel/component/stax Tue Nov 22 14:30:16 2011
@@ -0,0 +1,17 @@
+## ------------------------------------------------------------------------
+## Licensed to the Apache Software Foundation (ASF) under one or more
+## contributor license agreements.  See the NOTICE file distributed with
+## this work for additional information regarding copyright ownership.
+## The ASF licenses this file to You under the Apache License, Version 2.0
+## (the "License"); you may not use this file except in compliance with
+## the License.  You may obtain a copy of the License at
+##
+## http://www.apache.org/licenses/LICENSE-2.0
+##
+## Unless required by applicable law or agreed to in writing, software
+## distributed under the License is distributed on an "AS IS" BASIS,
+## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+## See the License for the specific language governing permissions and
+## limitations under the License.
+## ------------------------------------------------------------------------
+class=org.apache.camel.component.stax.StAXComponent

Added: camel/trunk/components/camel-stax/src/test/java/org/apache/camel/component/stax/CountingHandler.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-stax/src/test/java/org/apache/camel/component/stax/CountingHandler.java?rev=1205018&view=auto
==============================================================================
--- camel/trunk/components/camel-stax/src/test/java/org/apache/camel/component/stax/CountingHandler.java (added)
+++ camel/trunk/components/camel-stax/src/test/java/org/apache/camel/component/stax/CountingHandler.java Tue Nov 22 14:30:16 2011
@@ -0,0 +1,34 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.stax;
+
+import org.xml.sax.Attributes;
+import org.xml.sax.SAXException;
+import org.xml.sax.helpers.DefaultHandler;
+
+public class CountingHandler extends DefaultHandler {
+    private int number;
+
+    @Override
+    public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
+        number++;
+    }
+
+    public int getNumber() {
+        return number;
+    }
+}

Propchange: camel/trunk/components/camel-stax/src/test/java/org/apache/camel/component/stax/CountingHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-stax/src/test/java/org/apache/camel/component/stax/CountingHandler.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: camel/trunk/components/camel-stax/src/test/java/org/apache/camel/component/stax/StAXComponentTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-stax/src/test/java/org/apache/camel/component/stax/StAXComponentTest.java?rev=1205018&view=auto
==============================================================================
--- camel/trunk/components/camel-stax/src/test/java/org/apache/camel/component/stax/StAXComponentTest.java (added)
+++ camel/trunk/components/camel-stax/src/test/java/org/apache/camel/component/stax/StAXComponentTest.java Tue Nov 22 14:30:16 2011
@@ -0,0 +1,65 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.stax;
+
+import org.apache.camel.EndpointInject;
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.component.stax.model.RecordsUtil;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class StAXComponentTest extends CamelTestSupport {
+
+    @EndpointInject(uri = "mock:records")
+    private MockEndpoint recordsEndpoint;
+
+    @BeforeClass
+    public static void initRouteExample() {
+        RecordsUtil.createXMLFile();
+    }
+
+    @Override
+    public RouteBuilder createRouteBuilder() {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("file:target/in")
+                    .routeId("stax-parser")
+                    .to("stax:" + CountingHandler.class.getName())
+                    .process(new Processor() {
+                        @Override
+                        public void process(Exchange exchange) throws Exception {
+                            assertEquals(11, exchange.getIn().getBody(CountingHandler.class).getNumber());
+                        }
+                    })
+                    .to("mock:records");
+            }
+        };
+    }
+
+    @Test
+    public void testStax() throws Exception {
+        recordsEndpoint.expectedMessageCount(1);
+        recordsEndpoint.message(0).body().isInstanceOf(CountingHandler.class);
+
+        recordsEndpoint.assertIsSatisfied();
+    }
+}

Propchange: camel/trunk/components/camel-stax/src/test/java/org/apache/camel/component/stax/StAXComponentTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-stax/src/test/java/org/apache/camel/component/stax/StAXComponentTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: camel/trunk/components/camel-stax/src/test/java/org/apache/camel/component/stax/StAXJAXBIteratorExpressionTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-stax/src/test/java/org/apache/camel/component/stax/StAXJAXBIteratorExpressionTest.java?rev=1205018&view=auto
==============================================================================
--- camel/trunk/components/camel-stax/src/test/java/org/apache/camel/component/stax/StAXJAXBIteratorExpressionTest.java (added)
+++ camel/trunk/components/camel-stax/src/test/java/org/apache/camel/component/stax/StAXJAXBIteratorExpressionTest.java Tue Nov 22 14:30:16 2011
@@ -0,0 +1,63 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.stax;
+
+import org.apache.camel.EndpointInject;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.component.stax.model.Record;
+import org.apache.camel.component.stax.model.RecordsUtil;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import static org.apache.camel.component.stax.StAXBuilder.stax;
+
+public class StAXJAXBIteratorExpressionTest extends CamelTestSupport {
+    @EndpointInject(uri = "mock:records")
+    private MockEndpoint recordsEndpoint;
+
+    @BeforeClass
+    public static void initRouteExample() {
+        RecordsUtil.createXMLFile();
+    }
+
+    @Override
+    public RouteBuilder createRouteBuilder() {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("file:target/in")
+                    .routeId("stax-test")
+                    .split(stax(Record.class))
+                        .to("mock:records");
+            }
+        };
+    }
+
+    @Test
+    public void testStaxExpression() throws InterruptedException {
+        recordsEndpoint.expectedMessageCount(10);
+        recordsEndpoint.allMessages().body().isInstanceOf(Record.class);
+
+        recordsEndpoint.assertIsSatisfied();
+
+        Record five = recordsEndpoint.getReceivedExchanges().get(4).getIn().getBody(Record.class);
+        assertEquals("4", five.getKey());
+        assertEquals("#4", five.getValue());
+    }
+}

Propchange: camel/trunk/components/camel-stax/src/test/java/org/apache/camel/component/stax/StAXJAXBIteratorExpressionTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-stax/src/test/java/org/apache/camel/component/stax/StAXJAXBIteratorExpressionTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: camel/trunk/components/camel-stax/src/test/java/org/apache/camel/component/stax/StAXXPathSplitChoicePerformanceTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-stax/src/test/java/org/apache/camel/component/stax/StAXXPathSplitChoicePerformanceTest.java?rev=1205018&view=auto
==============================================================================
--- camel/trunk/components/camel-stax/src/test/java/org/apache/camel/component/stax/StAXXPathSplitChoicePerformanceTest.java (added)
+++ camel/trunk/components/camel-stax/src/test/java/org/apache/camel/component/stax/StAXXPathSplitChoicePerformanceTest.java Tue Nov 22 14:30:16 2011
@@ -0,0 +1,186 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.stax;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.NotifyBuilder;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.stax.model.Order;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.apache.camel.util.StopWatch;
+import org.apache.camel.util.TimeUtils;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.slf4j.Logger;
+
+import static org.apache.camel.component.stax.StAXBuilder.stax;
+
+/**
+ *
+ */
+@Ignore("this is a manual test")
+public class StAXXPathSplitChoicePerformanceTest extends CamelTestSupport {
+
+    private int size = 20 * 1000;
+    private final AtomicInteger tiny = new AtomicInteger();
+    private final AtomicInteger small = new AtomicInteger();
+    private final AtomicInteger med = new AtomicInteger();
+    private final AtomicInteger large = new AtomicInteger();
+    private final StopWatch watch = new StopWatch();
+
+    @Override
+    public void setUp() throws Exception {
+        createDataFile(log, size);
+        super.setUp();
+    }
+
+    @Test
+    public void testXPathSTaXPerformanceRoute() throws Exception {
+        NotifyBuilder notify = new NotifyBuilder(context).whenDone(size).create();
+
+        boolean matches = notify.matches(60, TimeUnit.SECONDS);
+        log.info("Processed file with " + size + " elements in: " + TimeUtils.printDuration(watch.stop()));
+
+        log.info("Processed " + tiny.get() + " tiny messages");
+        log.info("Processed " + small.get() + " small messages");
+        log.info("Processed " + med.get() + " medium messages");
+        log.info("Processed " + large.get() + " large messages");
+
+        assertEquals((size / 10) * 4, tiny.get());
+        assertEquals((size / 10) * 2, small.get());
+        assertEquals((size / 10) * 3, med.get());
+        assertEquals((size / 10) * 1, large.get());
+
+        assertTrue("Should complete route", matches);
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("file:target/data?noop=true")
+                    .process(new Processor() {
+                        public void process(Exchange exchange) throws Exception {
+                            log.info("Starting to process file");
+                            watch.restart();
+                        }
+                    })
+                    .split(stax(Order.class)).streaming()
+                        .choice()
+                            .when().xpath("/order/amount < 10")
+                                .process(new Processor() {
+                                    public void process(Exchange exchange) throws Exception {
+                                        String xml = exchange.getIn().getBody(String.class);
+                                        assertTrue(xml, xml.contains("<amount>3</amount>"));
+
+                                        int num = tiny.incrementAndGet();
+                                        if (num % 100 == 0) {
+                                            log.info("Processed " + num + " tiny messages");
+                                            log.debug(xml);
+                                        }
+                                    }
+                                })
+                            .when().xpath("/order/amount < 50")
+                                .process(new Processor() {
+                                    public void process(Exchange exchange) throws Exception {
+                                        String xml = exchange.getIn().getBody(String.class);
+                                        assertTrue(xml, xml.contains("<amount>44</amount>"));
+
+                                        int num = small.incrementAndGet();
+                                        if (num % 100 == 0) {
+                                            log.info("Processed " + num + " small messages");
+                                            log.debug(xml);
+                                        }
+                                    }
+                                })
+                            .when().xpath("/order/amount < 100")
+                                .process(new Processor() {
+                                    public void process(Exchange exchange) throws Exception {
+                                        String xml = exchange.getIn().getBody(String.class);
+                                        assertTrue(xml, xml.contains("<amount>88</amount>"));
+
+                                        int num = med.incrementAndGet();
+                                        if (num % 100 == 0) {
+                                            log.info("Processed " + num + " medium messages");
+                                            log.debug(xml);
+                                        }
+                                    }
+                                })
+                            .otherwise()
+                                .process(new Processor() {
+                                    public void process(Exchange exchange) throws Exception {
+                                        String xml = exchange.getIn().getBody(String.class);
+                                        assertTrue(xml, xml.contains("<amount>123</amount>"));
+
+                                        int num = large.incrementAndGet();
+                                        if (num % 100 == 0) {
+                                            log.info("Processed " + num + " large messages");
+                                            log.debug(xml);
+                                        }
+                                    }
+                                })
+                        .end() // choice
+                    .end(); // split
+            }
+        };
+    }
+
+    public static void createDataFile(Logger log, int size) throws Exception {
+        deleteDirectory("target/data");
+        createDirectory("target/data");
+
+        log.info("Creating data file ...");
+
+        File file = new File("target/data/data.xml");
+        FileOutputStream fos = new FileOutputStream(file, true);
+        fos.write("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><orders>\n".getBytes());
+
+        for (int i = 0; i < size; i++) {
+            fos.write("<order>\n".getBytes());
+            fos.write(("  <id>" + i + "</id>\n").getBytes());
+            int num = i % 10;
+            if (num >= 0 && num <= 3) {
+                fos.write("  <amount>3</amount>\n".getBytes());
+                fos.write("  <customerId>333</customerId>\n".getBytes());
+            } else if (num >= 4 && num <= 5) {
+                fos.write("  <amount>44</amount>\n".getBytes());
+                fos.write("  <customerId>444</customerId>\n".getBytes());
+            } else if (num >= 6 && num <= 8) {
+                fos.write("  <amount>88</amount>\n".getBytes());
+                fos.write("  <customerId>888</customerId>\n".getBytes());
+            } else {
+                fos.write("  <amount>123</amount>\n".getBytes());
+                fos.write("  <customerId>123123</customerId>\n".getBytes());
+            }
+            fos.write("  <description>bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla</description>\n".getBytes());
+            fos.write("</order>\n".getBytes());
+        }
+
+        fos.write("</orders>".getBytes());
+        fos.close();
+
+        log.info("Creating data file done.");
+    }
+
+}

Propchange: camel/trunk/components/camel-stax/src/test/java/org/apache/camel/component/stax/StAXXPathSplitChoicePerformanceTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-stax/src/test/java/org/apache/camel/component/stax/StAXXPathSplitChoicePerformanceTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: camel/trunk/components/camel-stax/src/test/java/org/apache/camel/component/stax/model/Order.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-stax/src/test/java/org/apache/camel/component/stax/model/Order.java?rev=1205018&view=auto
==============================================================================
--- camel/trunk/components/camel-stax/src/test/java/org/apache/camel/component/stax/model/Order.java (added)
+++ camel/trunk/components/camel-stax/src/test/java/org/apache/camel/component/stax/model/Order.java Tue Nov 22 14:30:16 2011
@@ -0,0 +1,76 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.stax.model;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+
+/**
+ *
+ */
+@XmlAccessorType(XmlAccessType.FIELD)
+@XmlRootElement(name = "order")
+public class Order {
+
+    @XmlElement(required = true)
+    protected String id;
+    @XmlElement(required = true)
+    protected int amount;
+    @XmlElement(required = true)
+    protected int customerId;
+    @XmlElement(required = true)
+    protected String description;
+
+    public int getAmount() {
+        return amount;
+    }
+
+    public void setAmount(int amount) {
+        this.amount = amount;
+    }
+
+    public int getCustomerId() {
+        return customerId;
+    }
+
+    public void setCustomerId(int customerId) {
+        this.customerId = customerId;
+    }
+
+    public String getDescription() {
+        return description;
+    }
+
+    public void setDescription(String description) {
+        this.description = description;
+    }
+
+    public String getId() {
+        return id;
+    }
+
+    public void setId(String id) {
+        this.id = id;
+    }
+
+    @Override
+    public String toString() {
+        return "Order[" + id + "]";
+    }
+}

Propchange: camel/trunk/components/camel-stax/src/test/java/org/apache/camel/component/stax/model/Order.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-stax/src/test/java/org/apache/camel/component/stax/model/Order.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: camel/trunk/components/camel-stax/src/test/java/org/apache/camel/component/stax/model/Orders.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-stax/src/test/java/org/apache/camel/component/stax/model/Orders.java?rev=1205018&view=auto
==============================================================================
--- camel/trunk/components/camel-stax/src/test/java/org/apache/camel/component/stax/model/Orders.java (added)
+++ camel/trunk/components/camel-stax/src/test/java/org/apache/camel/component/stax/model/Orders.java Tue Nov 22 14:30:16 2011
@@ -0,0 +1,41 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.stax.model;
+
+import java.util.ArrayList;
+import java.util.List;
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+
+/**
+ *
+ */
+@XmlAccessorType(XmlAccessType.FIELD)
+@XmlRootElement(name = "orders")
+public class Orders {
+    @XmlElement(required = true)
+    protected List<Order> orders;
+
+    public List<Order> getOrders() {
+        if (orders == null) {
+            orders = new ArrayList<Order>();
+        }
+        return orders;
+    }
+}

Propchange: camel/trunk/components/camel-stax/src/test/java/org/apache/camel/component/stax/model/Orders.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-stax/src/test/java/org/apache/camel/component/stax/model/Orders.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: camel/trunk/components/camel-stax/src/test/java/org/apache/camel/component/stax/model/Record.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-stax/src/test/java/org/apache/camel/component/stax/model/Record.java?rev=1205018&view=auto
==============================================================================
--- camel/trunk/components/camel-stax/src/test/java/org/apache/camel/component/stax/model/Record.java (added)
+++ camel/trunk/components/camel-stax/src/test/java/org/apache/camel/component/stax/model/Record.java Tue Nov 22 14:30:16 2011
@@ -0,0 +1,53 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.stax.model;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlType;
+
+@XmlAccessorType(XmlAccessType.FIELD)
+@XmlType(name = "record", propOrder = { "key", "value" })
+public class Record {
+    @XmlAttribute(required = true)
+    protected String key;
+
+    @XmlAttribute(required = true)
+    protected String value;
+
+    public String getKey() {
+        return key;
+    }
+
+    public void setKey(String key) {
+        this.key = key;
+    }
+
+    public String getValue() {
+        return value;
+    }
+
+    public void setValue(String value) {
+        this.value = value;
+    }
+
+    @Override
+    public String toString() {
+        return "Record[" + key + "]";
+    }
+}

Propchange: camel/trunk/components/camel-stax/src/test/java/org/apache/camel/component/stax/model/Record.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-stax/src/test/java/org/apache/camel/component/stax/model/Record.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: camel/trunk/components/camel-stax/src/test/java/org/apache/camel/component/stax/model/Records.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-stax/src/test/java/org/apache/camel/component/stax/model/Records.java?rev=1205018&view=auto
==============================================================================
--- camel/trunk/components/camel-stax/src/test/java/org/apache/camel/component/stax/model/Records.java (added)
+++ camel/trunk/components/camel-stax/src/test/java/org/apache/camel/component/stax/model/Records.java Tue Nov 22 14:30:16 2011
@@ -0,0 +1,38 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.stax.model;
+
+import java.util.ArrayList;
+import java.util.List;
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+
+@XmlAccessorType(XmlAccessType.FIELD)
+@XmlRootElement(name = "records")
+public class Records {
+    @XmlElement(required = true)
+    protected List<Record> record;
+
+    public List<Record> getRecord() {
+        if (record == null) {
+            record = new ArrayList<Record>();
+        }
+        return record;
+    }
+}

Propchange: camel/trunk/components/camel-stax/src/test/java/org/apache/camel/component/stax/model/Records.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-stax/src/test/java/org/apache/camel/component/stax/model/Records.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date