Repository: olingo-odata2
Updated Branches:
  refs/heads/OLINGO-231_PocForAndroid 20205caba -> 3f1de10c8


[OLINGO-231] Added support for Factory properties


Project: http://git-wip-us.apache.org/repos/asf/olingo-odata2/repo
Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata2/commit/3f1de10c
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata2/tree/3f1de10c
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata2/diff/3f1de10c

Branch: refs/heads/OLINGO-231_PocForAndroid
Commit: 3f1de10c88d4d7e9f0fd4ce783ae526c0251483c
Parents: 20205ca
Author: Michael Bolz <[email protected]>
Authored: Fri Apr 11 14:18:18 2014 +0200
Committer: Michael Bolz <[email protected]>
Committed: Fri Apr 11 14:18:18 2014 +0200

----------------------------------------------------------------------
 .../odata2/android/xml/AndroidXmlFactory.java   | 16 ++--
 .../odata2/android/xml/AndroidXmlReader.java    | 18 ++++
 .../odata2/android/xml/AndroidXmlWriter.java    | 16 +++-
 .../odata2/api/xml/XMLStreamReaderFactory.java  | 12 ++-
 .../odata2/api/xml/XMLStreamWriterFactory.java  | 12 ++-
 .../provider/EdmServiceMetadataImplProv.java    |  3 -
 .../odata2/core/ep/BasicEntityProvider.java     |  3 -
 .../core/xml/AbstractXmlStreamFactory.java      | 56 ++++++++++++
 .../odata2/core/xml/JavaxStaxReaderWrapper.java | 45 +---------
 .../odata2/core/xml/JavaxStaxStreamFactory.java | 94 ++++++++++++++++++++
 .../odata2/core/xml/JavaxStaxWriterWrapper.java | 30 +------
 .../odata2/core/xml/XmlStreamFactory.java       | 47 +++++-----
 .../AtomServiceDocumentConsumerTest.java        | 43 ++++-----
 13 files changed, 252 insertions(+), 143 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/3f1de10c/odata2-android/src/main/java/org/apache/olingo/odata2/android/xml/AndroidXmlFactory.java
----------------------------------------------------------------------
diff --git 
a/odata2-android/src/main/java/org/apache/olingo/odata2/android/xml/AndroidXmlFactory.java
 
b/odata2-android/src/main/java/org/apache/olingo/odata2/android/xml/AndroidXmlFactory.java
index 60a8f06..1660390 100644
--- 
a/odata2-android/src/main/java/org/apache/olingo/odata2/android/xml/AndroidXmlFactory.java
+++ 
b/odata2-android/src/main/java/org/apache/olingo/odata2/android/xml/AndroidXmlFactory.java
@@ -1,19 +1,17 @@
 package org.apache.olingo.odata2.android.xml;
 
 import org.apache.olingo.odata2.api.ep.EntityProviderException;
-import org.apache.olingo.odata2.api.xml.XMLStreamReader;
-import org.apache.olingo.odata2.api.xml.XMLStreamReaderFactory;
-import org.apache.olingo.odata2.api.xml.XMLStreamWriter;
-import org.apache.olingo.odata2.api.xml.XMLStreamWriterFactory;
+import org.apache.olingo.odata2.api.xml.*;
+import org.apache.olingo.odata2.core.xml.AbstractXmlStreamFactory;
 
-public class AndroidXmlFactory implements XMLStreamReaderFactory, 
XMLStreamWriterFactory {
+public class AndroidXmlFactory extends AbstractXmlStreamFactory {
   @Override
-  public XMLStreamReader createXMLStreamReader(Object content) {
-    return new AndroidXmlReader(content);
+  public XMLStreamReader createXMLStreamReader(Object content) throws 
XMLStreamException {
+    return new AndroidXmlReader(content).setProperties(readProperties);
   }
 
   @Override
-  public XMLStreamWriter createXMLStreamWriter(Object content) throws 
EntityProviderException {
-    return new AndroidXmlWriter(content);
+  public XMLStreamWriter createXMLStreamWriter(Object content) throws 
XMLStreamException {
+    return new AndroidXmlWriter(content).setProperties(writeProperties);
   }
 }

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/3f1de10c/odata2-android/src/main/java/org/apache/olingo/odata2/android/xml/AndroidXmlReader.java
----------------------------------------------------------------------
diff --git 
a/odata2-android/src/main/java/org/apache/olingo/odata2/android/xml/AndroidXmlReader.java
 
b/odata2-android/src/main/java/org/apache/olingo/odata2/android/xml/AndroidXmlReader.java
index 91af430..cf8addd 100644
--- 
a/odata2-android/src/main/java/org/apache/olingo/odata2/android/xml/AndroidXmlReader.java
+++ 
b/odata2-android/src/main/java/org/apache/olingo/odata2/android/xml/AndroidXmlReader.java
@@ -2,6 +2,7 @@ package org.apache.olingo.odata2.android.xml;
 
 import java.io.IOException;
 import java.io.InputStream;
+import java.util.Map;
 
 import org.apache.olingo.odata2.api.xml.NamespaceContext;
 import org.apache.olingo.odata2.api.xml.QName;
@@ -33,6 +34,23 @@ public class AndroidXmlReader implements XMLStreamReader {
     }
   }
 
+  public AndroidXmlReader setProperties(Map<String, Object> properties) throws 
XMLStreamException {
+    for (Map.Entry<String, Object> entry : properties.entrySet()) {
+      setProperty(entry.getKey(), entry.getValue());
+    }
+    return this;
+  }
+
+  public AndroidXmlReader setProperty(String name, Object value) throws 
XMLStreamException {
+    try {
+      parser.setProperty(name, value);
+    } catch (XmlPullParserException e) {
+      throw new XMLStreamException("During property setting an XmlPullParser 
Exception occurred: "
+              + e.getMessage(), e);
+    }
+    return this;
+  }
+
   @Override
   public void close() throws XMLStreamException {
   }

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/3f1de10c/odata2-android/src/main/java/org/apache/olingo/odata2/android/xml/AndroidXmlWriter.java
----------------------------------------------------------------------
diff --git 
a/odata2-android/src/main/java/org/apache/olingo/odata2/android/xml/AndroidXmlWriter.java
 
b/odata2-android/src/main/java/org/apache/olingo/odata2/android/xml/AndroidXmlWriter.java
index 67686e5..211738a 100644
--- 
a/odata2-android/src/main/java/org/apache/olingo/odata2/android/xml/AndroidXmlWriter.java
+++ 
b/odata2-android/src/main/java/org/apache/olingo/odata2/android/xml/AndroidXmlWriter.java
@@ -3,11 +3,13 @@ package org.apache.olingo.odata2.android.xml;
 import org.apache.olingo.odata2.api.ep.EntityProviderException;
 import org.apache.olingo.odata2.api.xml.XMLStreamException;
 import org.apache.olingo.odata2.api.xml.XMLStreamWriter;
+import org.xmlpull.v1.XmlPullParserException;
 
 import java.io.IOException;
 import java.io.OutputStream;
 import java.io.PrintWriter;
 import java.io.Writer;
+import java.util.Map;
 
 /**
  */
@@ -15,7 +17,7 @@ public class AndroidXmlWriter implements XMLStreamWriter {
 
   private Writer writer;
 
-  public AndroidXmlWriter(Object output) throws EntityProviderException {
+  public AndroidXmlWriter(Object output) {
     if (output instanceof OutputStream) {
       writer = new PrintWriter((OutputStream) output);
     } else if (output instanceof Writer) {
@@ -23,6 +25,18 @@ public class AndroidXmlWriter implements XMLStreamWriter {
     }
   }
 
+  public AndroidXmlWriter setProperties(Map<String, Object> properties) throws 
XMLStreamException {
+    for (Map.Entry<String, Object> entry : properties.entrySet()) {
+      setProperty(entry.getKey(), entry.getValue());
+    }
+    return this;
+  }
+
+  public AndroidXmlWriter setProperty(String name, Object value) throws 
XMLStreamException {
+    return this;
+  }
+
+
   @Override
   public void flush() throws XMLStreamException {
     write("flush");

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/3f1de10c/odata2-lib/odata-api/src/main/java/org/apache/olingo/odata2/api/xml/XMLStreamReaderFactory.java
----------------------------------------------------------------------
diff --git 
a/odata2-lib/odata-api/src/main/java/org/apache/olingo/odata2/api/xml/XMLStreamReaderFactory.java
 
b/odata2-lib/odata-api/src/main/java/org/apache/olingo/odata2/api/xml/XMLStreamReaderFactory.java
index 75c5926..4c793f6 100644
--- 
a/odata2-lib/odata-api/src/main/java/org/apache/olingo/odata2/api/xml/XMLStreamReaderFactory.java
+++ 
b/odata2-lib/odata-api/src/main/java/org/apache/olingo/odata2/api/xml/XMLStreamReaderFactory.java
@@ -33,5 +33,15 @@ public interface XMLStreamReaderFactory {
    * @return reader for given content.
    * @throws EntityProviderException if something goes wrong during 
initialization.
    */
-  XMLStreamReader createXMLStreamReader(Object content) throws 
EntityProviderException;
+  XMLStreamReader createXMLStreamReader(Object content) throws 
EntityProviderException, XMLStreamException;
+
+  /**
+   * Set property with given name and value.
+   * Be sure that property can be handled by underlying implementation.
+   *
+   * @param name name of property
+   * @param value value of property
+   * @return XMLStreamReaderFactory instance
+   */
+  XMLStreamReaderFactory setReadProperty(String name, Object value);
 }

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/3f1de10c/odata2-lib/odata-api/src/main/java/org/apache/olingo/odata2/api/xml/XMLStreamWriterFactory.java
----------------------------------------------------------------------
diff --git 
a/odata2-lib/odata-api/src/main/java/org/apache/olingo/odata2/api/xml/XMLStreamWriterFactory.java
 
b/odata2-lib/odata-api/src/main/java/org/apache/olingo/odata2/api/xml/XMLStreamWriterFactory.java
index 0e314a8..9713934 100644
--- 
a/odata2-lib/odata-api/src/main/java/org/apache/olingo/odata2/api/xml/XMLStreamWriterFactory.java
+++ 
b/odata2-lib/odata-api/src/main/java/org/apache/olingo/odata2/api/xml/XMLStreamWriterFactory.java
@@ -33,5 +33,15 @@ public interface XMLStreamWriterFactory{
    * @return writer for given content.
    * @throws EntityProviderException if something goes wrong during 
initialization.
    */
-  XMLStreamWriter createXMLStreamWriter(Object content) throws 
EntityProviderException;
+  XMLStreamWriter createXMLStreamWriter(Object content) throws 
EntityProviderException, XMLStreamException;
+
+  /**
+   * Set property with given name and value.
+   * Be sure that property can be handled by underlying implementation.
+   *
+   * @param name name of property
+   * @param value value of property
+   * @return XMLStreamWriterFactory instance
+   */
+  XMLStreamWriterFactory setWriteProperty(String name, Object value);
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/3f1de10c/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/edm/provider/EdmServiceMetadataImplProv.java
----------------------------------------------------------------------
diff --git 
a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/edm/provider/EdmServiceMetadataImplProv.java
 
b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/edm/provider/EdmServiceMetadataImplProv.java
index 02d77f7..0221dcb 100644
--- 
a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/edm/provider/EdmServiceMetadataImplProv.java
+++ 
b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/edm/provider/EdmServiceMetadataImplProv.java
@@ -73,9 +73,6 @@ public class EdmServiceMetadataImplProv implements 
EdmServiceMetadata {
       XMLStreamWriter xmlStreamWriter = 
XmlStreamFactory.createStreamWriter(writer);
       XmlMetadataProducer.writeMetadata(metadata, xmlStreamWriter, null);
       return csb.getInputStream();
-    } catch (XMLStreamException e) {
-      cachedException = new 
EntityProviderException(EntityProviderException.COMMON, e);
-      throw cachedException;
     } catch (UnsupportedEncodingException e) {
       cachedException = new 
EntityProviderException(EntityProviderException.COMMON, e);
       throw cachedException;

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/3f1de10c/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/BasicEntityProvider.java
----------------------------------------------------------------------
diff --git 
a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/BasicEntityProvider.java
 
b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/BasicEntityProvider.java
index cc4f3fa..8d830f0 100644
--- 
a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/BasicEntityProvider.java
+++ 
b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/BasicEntityProvider.java
@@ -252,9 +252,6 @@ public class BasicEntityProvider {
     } catch (UnsupportedEncodingException e) {
       throw new 
EntityProviderException(EntityProviderException.EXCEPTION_OCCURRED.addContent(e.getClass()
           .getSimpleName()), e);
-    } catch (XMLStreamException e) {
-      throw new 
EntityProviderException(EntityProviderException.EXCEPTION_OCCURRED.addContent(e.getClass()
-          .getSimpleName()), e);
     } catch (FactoryConfigurationError e) {
       throw new 
EntityProviderException(EntityProviderException.EXCEPTION_OCCURRED.addContent(e.getClass()
           .getSimpleName()), e);

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/3f1de10c/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/xml/AbstractXmlStreamFactory.java
----------------------------------------------------------------------
diff --git 
a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/xml/AbstractXmlStreamFactory.java
 
b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/xml/AbstractXmlStreamFactory.java
new file mode 100644
index 0000000..d385e97
--- /dev/null
+++ 
b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/xml/AbstractXmlStreamFactory.java
@@ -0,0 +1,56 @@
+/*******************************************************************************
+ * 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.olingo.odata2.core.xml;
+
+import org.apache.olingo.odata2.api.xml.XMLStreamReaderFactory;
+import org.apache.olingo.odata2.api.xml.XMLStreamWriterFactory;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ */
+public abstract class AbstractXmlStreamFactory implements 
XMLStreamWriterFactory, XMLStreamReaderFactory {
+  protected final Map<String, Object> readProperties = new HashMap<String, 
Object>();
+  protected final Map<String, Object> writeProperties = new HashMap<String, 
Object>();
+
+  @Override
+  public XMLStreamReaderFactory setReadProperty(String name, Object value) {
+    readProperties.put(name, value);
+    return this;
+  }
+
+  @Override
+  public XMLStreamWriterFactory setWriteProperty(String name, Object value) {
+    writeProperties.put(name, value);
+    return this;
+  }
+
+  protected void applyProperties(XMLStreamReaderFactory factory, Map<String, 
Object> readProperties) {
+    for (Map.Entry<String, Object> name2Value : readProperties.entrySet()) {
+      factory.setReadProperty(name2Value.getKey(), name2Value.getValue());
+    }
+  }
+
+  protected void applyProperties(XMLStreamWriterFactory factory, Map<String, 
Object> readProperties) {
+    for (Map.Entry<String, Object> name2Value : readProperties.entrySet()) {
+      factory.setWriteProperty(name2Value.getKey(), name2Value.getValue());
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/3f1de10c/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/xml/JavaxStaxReaderWrapper.java
----------------------------------------------------------------------
diff --git 
a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/xml/JavaxStaxReaderWrapper.java
 
b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/xml/JavaxStaxReaderWrapper.java
index 55d495c..9afedc3 100644
--- 
a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/xml/JavaxStaxReaderWrapper.java
+++ 
b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/xml/JavaxStaxReaderWrapper.java
@@ -26,55 +26,14 @@ import java.io.InputStream;
 
 /**
  */
-public class JavaxStaxReaderWrapper implements XMLStreamReader, 
XMLStreamReaderFactory {
-
-  /** Default used charset for reader */
-  private static final String DEFAULT_CHARSET = "UTF-8";
+public class JavaxStaxReaderWrapper implements XMLStreamReader {
 
   private final javax.xml.stream.XMLStreamReader reader;
 
-  private JavaxStaxReaderWrapper(javax.xml.stream.XMLStreamReader reader) {
+  public JavaxStaxReaderWrapper(javax.xml.stream.XMLStreamReader reader) {
     this.reader = reader;
   }
 
-  public static XMLStreamReaderFactory createFactory() {
-    return new JavaxStaxReaderWrapper(null);
-  }
-
-  @Override
-  public XMLStreamReader createXMLStreamReader(Object content) throws 
EntityProviderException {
-    if (content == null) {
-      throw new 
EntityProviderException(EntityProviderException.ILLEGAL_ARGUMENT
-              .addContent("Got not allowed NULL parameter for creation of 
XMLStreamReader."));
-    }
-    javax.xml.stream.XMLStreamReader streamReader;
-    try {
-      XMLInputFactory factory = XMLInputFactory.newInstance();
-      factory.setProperty(XMLInputFactory.IS_VALIDATING, false);
-      factory.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, true);
-      factory.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, 
false);
-      factory.setProperty(XMLInputFactory.SUPPORT_DTD, false);
-
-      if (content instanceof InputStream) {
-        streamReader = factory.createXMLStreamReader((InputStream) content, 
DEFAULT_CHARSET);
-        // verify charset encoding set in content is supported (if not set 
UTF-8 is used as defined in
-        // 'http://www.w3.org/TR/2008/REC-xml-20081126/')
-        String characterEncodingInContent = 
streamReader.getCharacterEncodingScheme();
-        if (characterEncodingInContent != null && 
!DEFAULT_CHARSET.equalsIgnoreCase(characterEncodingInContent)) {
-          throw new EntityProviderException(EntityProviderException
-                  
.UNSUPPORTED_CHARACTER_ENCODING.addContent(characterEncodingInContent));
-        }
-      } else {
-        throw new 
EntityProviderException(EntityProviderException.ILLEGAL_ARGUMENT
-                .addContent("Found not supported content of class '" + 
content.getClass() + "' to de-serialize."));
-      }
-      return new JavaxStaxReaderWrapper(streamReader);
-    } catch (javax.xml.stream.XMLStreamException e) {
-      throw new 
EntityProviderException(EntityProviderException.EXCEPTION_OCCURRED.addContent(e.getClass()
-              .getSimpleName()), e);
-    }
-  }
-
   public String getLocalName() {
     return reader.getLocalName();
   }

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/3f1de10c/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/xml/JavaxStaxStreamFactory.java
----------------------------------------------------------------------
diff --git 
a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/xml/JavaxStaxStreamFactory.java
 
b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/xml/JavaxStaxStreamFactory.java
new file mode 100644
index 0000000..ab007ca
--- /dev/null
+++ 
b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/xml/JavaxStaxStreamFactory.java
@@ -0,0 +1,94 @@
+/*******************************************************************************
+ * 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.olingo.odata2.core.xml;
+
+import org.apache.olingo.odata2.api.ep.EntityProviderException;
+import org.apache.olingo.odata2.api.xml.*;
+
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLOutputFactory;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.Writer;
+
+/**
+ *
+ */
+public class JavaxStaxStreamFactory extends AbstractXmlStreamFactory {
+  /** Default used charset for reader */
+  private static final String DEFAULT_CHARSET = "UTF-8";
+
+  @Override
+  public XMLStreamReader createXMLStreamReader(Object content) throws 
EntityProviderException {
+    if (content == null) {
+      throw new 
EntityProviderException(EntityProviderException.ILLEGAL_ARGUMENT
+              .addContent("Got not allowed NULL parameter for creation of 
XMLStreamReader."));
+    }
+    javax.xml.stream.XMLStreamReader streamReader;
+    try {
+      XMLInputFactory factory = XMLInputFactory.newInstance();
+      factory.setProperty(XMLInputFactory.IS_VALIDATING, false);
+      factory.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, true);
+      factory.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, 
false);
+      factory.setProperty(XMLInputFactory.SUPPORT_DTD, false);
+
+      if (content instanceof InputStream) {
+        streamReader = factory.createXMLStreamReader((InputStream) content, 
DEFAULT_CHARSET);
+        // verify charset encoding set in content is supported (if not set 
UTF-8 is used as defined in
+        // 'http://www.w3.org/TR/2008/REC-xml-20081126/')
+        String characterEncodingInContent = 
streamReader.getCharacterEncodingScheme();
+        if (characterEncodingInContent != null && 
!DEFAULT_CHARSET.equalsIgnoreCase(characterEncodingInContent)) {
+          throw new EntityProviderException(EntityProviderException
+                  
.UNSUPPORTED_CHARACTER_ENCODING.addContent(characterEncodingInContent));
+        }
+      } else {
+        throw new 
EntityProviderException(EntityProviderException.ILLEGAL_ARGUMENT
+                .addContent("Found not supported content of class '" + 
content.getClass() + "' to de-serialize."));
+      }
+      return new JavaxStaxReaderWrapper(streamReader);
+    } catch (javax.xml.stream.XMLStreamException e) {
+      throw new 
EntityProviderException(EntityProviderException.EXCEPTION_OCCURRED.addContent(e.getClass()
+              .getSimpleName()), e);
+    }
+  }
+
+  @Override
+  public XMLStreamWriter createXMLStreamWriter(Object content) throws 
EntityProviderException {
+    if(content == null) {
+      throw new IllegalArgumentException("Unsupported NULL input content.");
+    }
+
+    try {
+      XMLOutputFactory xouf = XMLOutputFactory.newFactory();
+      if (content instanceof OutputStream) {
+        javax.xml.stream.XMLStreamWriter javaxWriter = 
xouf.createXMLStreamWriter((OutputStream) content);
+        return new JavaxStaxWriterWrapper(javaxWriter);
+      } else if (content instanceof Writer) {
+        javax.xml.stream.XMLStreamWriter javaxWriter = 
xouf.createXMLStreamWriter((Writer) content);
+        return new JavaxStaxWriterWrapper(javaxWriter);
+      } else {
+        throw new IllegalArgumentException("Unsupported input content with 
class type '" +
+                content.getClass() + "'.");
+      }
+    } catch (javax.xml.stream.XMLStreamException e) {
+      throw new 
EntityProviderException(EntityProviderException.EXCEPTION_OCCURRED.addContent(e.getClass()
+              .getSimpleName()), e);
+    }
+  }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/3f1de10c/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/xml/JavaxStaxWriterWrapper.java
----------------------------------------------------------------------
diff --git 
a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/xml/JavaxStaxWriterWrapper.java
 
b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/xml/JavaxStaxWriterWrapper.java
index e76d367..e25f5b4 100644
--- 
a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/xml/JavaxStaxWriterWrapper.java
+++ 
b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/xml/JavaxStaxWriterWrapper.java
@@ -29,41 +29,13 @@ import java.io.Writer;
 
 /**
  */
-public class JavaxStaxWriterWrapper implements XMLStreamWriter, 
XMLStreamWriterFactory {
+public class JavaxStaxWriterWrapper implements XMLStreamWriter {
   private final javax.xml.stream.XMLStreamWriter xmlStreamWriter;
 
   public JavaxStaxWriterWrapper(javax.xml.stream.XMLStreamWriter 
xmlStreamWriter) {
     this.xmlStreamWriter = xmlStreamWriter;
   }
 
-  public static XMLStreamWriterFactory createFactory() {
-    return new JavaxStaxWriterWrapper(null);
-  }
-
-  @Override
-  public XMLStreamWriter createXMLStreamWriter(Object content) throws 
EntityProviderException {
-    if(content == null) {
-      throw new IllegalArgumentException("Unsupported NULL input content.");
-    }
-
-    try {
-      XMLOutputFactory xouf = XMLOutputFactory.newFactory();
-      if (content instanceof OutputStream) {
-        javax.xml.stream.XMLStreamWriter javaxWriter = 
xouf.createXMLStreamWriter((OutputStream) content);
-        return new JavaxStaxWriterWrapper(javaxWriter);
-      } else if (content instanceof Writer) {
-        javax.xml.stream.XMLStreamWriter javaxWriter = 
xouf.createXMLStreamWriter((Writer) content);
-        return new JavaxStaxWriterWrapper(javaxWriter);
-      } else {
-        throw new IllegalArgumentException("Unsupported input content with 
class type '" +
-                content.getClass() + "'.");
-      }
-    } catch (javax.xml.stream.XMLStreamException e) {
-      throw new 
EntityProviderException(EntityProviderException.EXCEPTION_OCCURRED.addContent(e.getClass()
-              .getSimpleName()), e);
-    }
-  }
-
   public void writeStartDocument() throws XMLStreamException {
     try {
       xmlStreamWriter.writeStartDocument();

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/3f1de10c/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/xml/XmlStreamFactory.java
----------------------------------------------------------------------
diff --git 
a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/xml/XmlStreamFactory.java
 
b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/xml/XmlStreamFactory.java
index 15af926..c93d48b 100644
--- 
a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/xml/XmlStreamFactory.java
+++ 
b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/xml/XmlStreamFactory.java
@@ -22,30 +22,14 @@ import 
org.apache.olingo.odata2.api.ep.EntityProviderException;
 import org.apache.olingo.odata2.api.xml.*;
 
 import java.io.OutputStream;
-import java.util.Collections;
-import java.util.Map;
 
 /**
  *
  */
-public class XmlStreamFactory implements XMLStreamWriterFactory, 
XMLStreamReaderFactory {
-
-  private final Map<String, Object> properties;
-
-  private XmlStreamFactory() {
-    this(Collections.EMPTY_MAP);
-  }
-
-  private XmlStreamFactory(Map<String, Object> properties) {
-    this.properties = properties;
-  }
+public class XmlStreamFactory extends AbstractXmlStreamFactory {
 
   public static XmlStreamFactory create() {
-    return create(Collections.EMPTY_MAP);
-  }
-
-  public static XmlStreamFactory create(Map<String, Object> properties) {
-    return new XmlStreamFactory(properties);
+    return new XmlStreamFactory();
   }
 
   public static XMLStreamReader createStreamReader(final Object content)
@@ -55,15 +39,15 @@ public class XmlStreamFactory implements 
XMLStreamWriterFactory, XMLStreamReader
   }
 
   public static XMLStreamWriter createStreamWriter(final Object content)
-          throws EntityProviderException, XMLStreamException {
+          throws EntityProviderException {
     XmlStreamFactory factory = new XmlStreamFactory();
     return factory.createXMLStreamWriter(content);
   }
 
   public static XMLStreamWriter createStreamWriter(OutputStream content, 
String charset)
-          throws EntityProviderException {
-    XmlStreamFactory factory = new XmlStreamFactory();
-    return factory.createXMLStreamWriter(content);
+          throws EntityProviderException, XMLStreamException {
+    XmlStreamFactory xsf = new XmlStreamFactory();
+    return xsf.createXMLStreamWriter(content);
   }
 
   public XMLStreamReaderFactory createReaderFactory() throws 
EntityProviderException {
@@ -77,7 +61,7 @@ public class XmlStreamFactory implements 
XMLStreamWriterFactory, XMLStreamReader
                 
EntityProviderException.EXCEPTION_OCCURRED.addContent(e.getMessage()));
       }
     }
-    return JavaxStaxReaderWrapper.createFactory();
+    return new JavaxStaxStreamFactory();
   }
 
   public XMLStreamWriterFactory createWriterFactory() throws 
EntityProviderException {
@@ -91,18 +75,29 @@ public class XmlStreamFactory implements 
XMLStreamWriterFactory, XMLStreamReader
                 
EntityProviderException.EXCEPTION_OCCURRED.addContent(e.getMessage()));
       }
     }
-    return JavaxStaxWriterWrapper.createFactory();
+    return new JavaxStaxStreamFactory();
   }
 
   @Override
   public XMLStreamReader createXMLStreamReader(Object content) throws 
EntityProviderException {
     XMLStreamReaderFactory factory = createReaderFactory();
-    return factory.createXMLStreamReader(content);
+    applyProperties(factory, readProperties);
+    try {
+      return factory.createXMLStreamReader(content);
+    } catch (XMLStreamException e) {
+      throw new EntityProviderException(EntityProviderException.COMMON, e);
+    }
   }
 
   @Override
   public XMLStreamWriter createXMLStreamWriter(Object content) throws 
EntityProviderException {
     XMLStreamWriterFactory factory = createWriterFactory();
-    return factory.createXMLStreamWriter(content);
+    applyProperties(factory, writeProperties);
+    try {
+      return factory.createXMLStreamWriter(content);
+    } catch (XMLStreamException e) {
+      throw new EntityProviderException(EntityProviderException.COMMON, e);
+    }
   }
+
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/3f1de10c/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/consumer/AtomServiceDocumentConsumerTest.java
----------------------------------------------------------------------
diff --git 
a/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/consumer/AtomServiceDocumentConsumerTest.java
 
b/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/consumer/AtomServiceDocumentConsumerTest.java
index 254e941..b99f382 100644
--- 
a/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/consumer/AtomServiceDocumentConsumerTest.java
+++ 
b/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/consumer/AtomServiceDocumentConsumerTest.java
@@ -26,8 +26,6 @@ import static org.junit.Assert.fail;
 
 import java.io.IOException;
 import java.io.InputStream;
-import java.util.HashMap;
-import java.util.Map;
 
 import org.apache.olingo.odata2.api.edm.Edm;
 import org.apache.olingo.odata2.api.ep.EntityProviderException;
@@ -39,11 +37,13 @@ import 
org.apache.olingo.odata2.api.servicedocument.ExtensionElement;
 import org.apache.olingo.odata2.api.servicedocument.Fixed;
 import org.apache.olingo.odata2.api.servicedocument.ServiceDocument;
 import org.apache.olingo.odata2.api.servicedocument.Workspace;
-import org.apache.olingo.odata2.api.xml.XMLStreamException;
 import org.apache.olingo.odata2.api.xml.XMLStreamReader;
+import org.apache.olingo.odata2.api.xml.XMLStreamReaderFactory;
 import org.apache.olingo.odata2.core.xml.XmlStreamFactory;
 import org.junit.Test;
 
+import javax.xml.stream.XMLInputFactory;
+
 public class AtomServiceDocumentConsumerTest extends AbstractXmlConsumerTest {
 
   public AtomServiceDocumentConsumerTest(final StreamWriterImplType type) {
@@ -54,7 +54,7 @@ public class AtomServiceDocumentConsumerTest extends 
AbstractXmlConsumerTest {
   private static final String PREFIX = "foo";
 
   @Test
-  public void testServiceDocument() throws IOException, 
EntityProviderException {
+  public void testServiceDocument() throws Exception {
     AtomServiceDocumentConsumer svcDocumentParser = new 
AtomServiceDocumentConsumer();
     ServiceDocument svcDocument = 
svcDocumentParser.readServiceDokument(createStreamReader("/svcExample.xml"));
     assertNotNull(svcDocument);
@@ -85,7 +85,7 @@ public class AtomServiceDocumentConsumerTest extends 
AbstractXmlConsumerTest {
   }
 
   @Test
-  public void testExtensionsWithAttributes() throws IOException, 
EntityProviderException {
+  public void testExtensionsWithAttributes() throws Exception {
     AtomServiceDocumentConsumer svcDocumentParser = new 
AtomServiceDocumentConsumer();
     ServiceDocument svcDocument = 
svcDocumentParser.readServiceDokument(createStreamReader("/svcExample.xml"));
     assertNotNull(svcDocument);
@@ -105,7 +105,7 @@ public class AtomServiceDocumentConsumerTest extends 
AbstractXmlConsumerTest {
   }
 
   @Test
-  public void testServiceDocument2() throws IOException, 
EntityProviderException {
+  public void testServiceDocument2() throws Exception {
     AtomServiceDocumentConsumer svcDocumentParser = new 
AtomServiceDocumentConsumer();
     ServiceDocument svcDocument = 
svcDocumentParser.readServiceDokument(createStreamReader("/svcAtomExample.xml"));
     assertNotNull(svcDocument);
@@ -130,7 +130,7 @@ public class AtomServiceDocumentConsumerTest extends 
AbstractXmlConsumerTest {
   }
 
   @Test
-  public void testCategories() throws IOException, EntityProviderException {
+  public void testCategories() throws Exception {
     AtomServiceDocumentConsumer svcDocumentParser = new 
AtomServiceDocumentConsumer();
     ServiceDocument svcDocument = 
svcDocumentParser.readServiceDokument(createStreamReader("/svcAtomExample.xml"));
     assertNotNull(svcDocument);
@@ -160,7 +160,7 @@ public class AtomServiceDocumentConsumerTest extends 
AbstractXmlConsumerTest {
   }
 
   @Test
-  public void testNestedExtensions() throws IOException, 
EntityProviderException {
+  public void testNestedExtensions() throws Exception {
     AtomServiceDocumentConsumer svcDocumentParser = new 
AtomServiceDocumentConsumer();
     ServiceDocument svcDocument = 
svcDocumentParser.readServiceDokument(createStreamReader("/svcAtomExample.xml"));
     assertNotNull(svcDocument);
@@ -189,19 +189,19 @@ public class AtomServiceDocumentConsumerTest extends 
AbstractXmlConsumerTest {
   }
 
   @Test(expected = EntityProviderException.class)
-  public void testWithoutTitle() throws IOException, EntityProviderException {
+  public void testWithoutTitle() throws Exception {
     AtomServiceDocumentConsumer svcDocumentParser = new 
AtomServiceDocumentConsumer();
     
svcDocumentParser.readServiceDokument(createStreamReader("/svcDocWithoutTitle.xml"));
   }
 
   @Test(expected = EntityProviderException.class)
-  public void testSvcWithoutWorkspaces() throws IOException, 
EntityProviderException {
+  public void testSvcWithoutWorkspaces() throws Exception {
     AtomServiceDocumentConsumer svcDocumentParser = new 
AtomServiceDocumentConsumer();
     
svcDocumentParser.readServiceDokument(createStreamReader("/invalidSvcExample.xml"));
   }
 
   @Test
-  public void testServiceDocument3() throws IOException, 
EntityProviderException {
+  public void testServiceDocument3() throws Exception {
     AtomServiceDocumentConsumer svcDocumentParser = new 
AtomServiceDocumentConsumer();
     ServiceDocument svcDocument = 
svcDocumentParser.readServiceDokument(createStreamReader("/serviceDocExample.xml"));
     assertNotNull(svcDocument);
@@ -249,29 +249,18 @@ public class AtomServiceDocumentConsumerTest extends 
AbstractXmlConsumerTest {
     }
   }
 
-  private org.apache.olingo.odata2.api.xml.XMLStreamReader 
createStreamReader(final String fileName)
-          throws IOException, EntityProviderException {
-    InputStream in = ClassLoader.class.getResourceAsStream(fileName);
-    if (in == null) {
-      throw new IOException("Requested file '" + fileName + "' was not 
found.");
-    }
-    return 
org.apache.olingo.odata2.core.xml.XmlStreamFactory.createStreamReader(in);
-  }
-
-  private XMLStreamReader createStreamReader2(final String fileName) throws 
IOException, EntityProviderException {
+  private XMLStreamReader createStreamReader(final String fileName) throws 
Exception {
 //    XMLInputFactory factory = XMLInputFactory.newInstance();
 //    factory.setProperty(XMLInputFactory.IS_VALIDATING, false);
 //    factory.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, true);
 
-    Map<String, Object> properties = new HashMap<String, Object>();
-    XmlStreamFactory factory = XmlStreamFactory.create(properties);
+    XMLStreamReaderFactory factory = 
XmlStreamFactory.create().createReaderFactory();
+    factory.setReadProperty(XMLInputFactory.IS_VALIDATING, false);
+    factory.setReadProperty(XMLInputFactory.IS_NAMESPACE_AWARE, true);
     InputStream in = ClassLoader.class.getResourceAsStream(fileName);
     if (in == null) {
       throw new IOException("Requested file '" + fileName + "' was not 
found.");
     }
-    XMLStreamReader streamReader;
-    streamReader = factory.createXMLStreamReader(in);
-
-    return streamReader;
+    return factory.createXMLStreamReader(in);
   }
 }

Reply via email to