Repository: olingo-odata2 Updated Branches: refs/heads/OLINGO-231_PocForAndroid fe9e2edc8 -> 15785c688
[OLINGO-237] Refactored architecture Project: http://git-wip-us.apache.org/repos/asf/olingo-odata2/repo Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata2/commit/15785c68 Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata2/tree/15785c68 Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata2/diff/15785c68 Branch: refs/heads/OLINGO-231_PocForAndroid Commit: 15785c6888412c5683ab60a78e8395a3020af365 Parents: fe9e2ed Author: Michael Bolz <[email protected]> Authored: Mon Apr 7 10:43:05 2014 +0200 Committer: Michael Bolz <[email protected]> Committed: Mon Apr 7 10:43:05 2014 +0200 ---------------------------------------------------------------------- .../olingo/odata2/core/commons/XmlHelper.java | 68 ----------------- .../provider/EdmServiceMetadataImplProv.java | 5 +- .../odata2/core/edm/provider/EdmxProvider.java | 5 +- .../odata2/core/ep/BasicEntityProvider.java | 5 +- .../consumer/AtomServiceDocumentConsumer.java | 4 +- .../core/ep/consumer/XmlEntityConsumer.java | 12 +-- .../ep/consumer/XmlErrorDocumentConsumer.java | 4 +- .../odata2/core/xml/JavaxStaxReaderWrapper.java | 41 ++++++---- .../odata2/core/xml/JavaxStaxWriterWrapper.java | 25 +++++-- .../odata2/core/xml/NamespaceContext.java | 8 +- .../apache/olingo/odata2/core/xml/QName.java | 15 +--- .../odata2/core/xml/XMLStreamConstants.java | 1 + .../olingo/odata2/core/xml/XMLStreamReader.java | 28 +------ .../odata2/core/xml/XMLStreamReaderFactory.java | 30 ++++++++ .../olingo/odata2/core/xml/XMLStreamWriter.java | 22 +----- .../odata2/core/xml/XMLStreamWriterFactory.java | 24 ++---- .../odata2/core/xml/XmlStreamFactory.java | 79 ++++++++++++++++++++ .../core/ep/consumer/AbstractConsumerTest.java | 5 +- .../AtomServiceDocumentConsumerTest.java | 2 +- .../ep/producer/XmlMetadataProducerTest.java | 3 +- 20 files changed, 193 insertions(+), 193 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/15785c68/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/commons/XmlHelper.java ---------------------------------------------------------------------- diff --git a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/commons/XmlHelper.java b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/commons/XmlHelper.java deleted file mode 100644 index c068f2f..0000000 --- a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/commons/XmlHelper.java +++ /dev/null @@ -1,68 +0,0 @@ -/******************************************************************************* - * 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.commons; - -import org.apache.olingo.odata2.api.ep.EntityProviderException; - -public class XmlHelper { - - /** Default used charset for reader */ - private static final String DEFAULT_CHARSET = "UTF-8"; - - public static org.apache.olingo.odata2.core.xml.XMLStreamReader createStreamReader(final Object content) - throws EntityProviderException { - return org.apache.olingo.odata2.core.xml.XMLStreamReader.createXMLStreamReader(content); - } - - - /* - public static XMLStreamReader createStreamReaderJavax(final Object content) throws EntityProviderException { - if (content == null) { - throw new EntityProviderException(EntityProviderException.ILLEGAL_ARGUMENT - .addContent("Got not allowed NULL parameter for creation of XMLStreamReader.")); - } - 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.createXMLStreamWriter((InputStream) content, DEFAULT_CHARSET); - // verify charset encoding set in content is supported (if not set UTF-8 is used as defined in - // v'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 streamReader; - } catch (XMLStreamException e) { - throw new EntityProviderException(EntityProviderException.EXCEPTION_OCCURRED.addContent(e.getClass() - .getSimpleName()), e); - } - } -*/ -} http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/15785c68/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 c1de8fe..b7a0c1f 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 @@ -41,7 +41,7 @@ import org.apache.olingo.odata2.core.ep.producer.XmlMetadataProducer; import org.apache.olingo.odata2.core.ep.util.CircleStreamBuffer; import org.apache.olingo.odata2.core.xml.XMLStreamException; import org.apache.olingo.odata2.core.xml.XMLStreamWriter; -import org.apache.olingo.odata2.core.xml.XMLStreamWriterFactory; +import org.apache.olingo.odata2.core.xml.XmlStreamFactory; /** * @@ -70,8 +70,7 @@ public class EdmServiceMetadataImplProv implements EdmServiceMetadata { try { writer = new OutputStreamWriter(csb.getOutputStream(), "UTF-8"); - XMLStreamWriterFactory xmlStreamWriterFactory = XMLStreamWriterFactory.create(); - XMLStreamWriter xmlStreamWriter = xmlStreamWriterFactory.createXMLStreamWriter(writer); + XMLStreamWriter xmlStreamWriter = XmlStreamFactory.createStreamWriter(writer); XmlMetadataProducer.writeMetadata(metadata, xmlStreamWriter, null); return csb.getInputStream(); } catch (XMLStreamException e) { http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/15785c68/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/edm/provider/EdmxProvider.java ---------------------------------------------------------------------- diff --git a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/edm/provider/EdmxProvider.java b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/edm/provider/EdmxProvider.java index 06c7e06..75119ec 100644 --- a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/edm/provider/EdmxProvider.java +++ b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/edm/provider/EdmxProvider.java @@ -22,8 +22,9 @@ import org.apache.olingo.odata2.api.edm.FullQualifiedName; import org.apache.olingo.odata2.api.edm.provider.*; import org.apache.olingo.odata2.api.ep.EntityProviderException; import org.apache.olingo.odata2.api.exception.ODataException; -import org.apache.olingo.odata2.core.commons.XmlHelper; +import org.apache.olingo.odata2.core.xml.XmlStreamFactory; import org.apache.olingo.odata2.core.ep.consumer.XmlMetadataConsumer; +import org.apache.olingo.odata2.core.xml.XmlStreamFactory; import java.io.InputStream; import java.util.ArrayList; @@ -34,7 +35,7 @@ public class EdmxProvider extends EdmProvider { public EdmxProvider parse(final InputStream in, final boolean validate) throws EntityProviderException { XmlMetadataConsumer parser = new XmlMetadataConsumer(); - org.apache.olingo.odata2.core.xml.XMLStreamReader streamReader = XmlHelper.createStreamReader(in); + org.apache.olingo.odata2.core.xml.XMLStreamReader streamReader = XmlStreamFactory.createStreamReader(in); dataServices = parser.readMetadata(streamReader, validate); return this; } http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/15785c68/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 467201d..5182014 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 @@ -52,7 +52,7 @@ import org.apache.olingo.odata2.core.ep.producer.XmlMetadataProducer; import org.apache.olingo.odata2.core.ep.util.CircleStreamBuffer; import org.apache.olingo.odata2.core.xml.XMLStreamException; import org.apache.olingo.odata2.core.xml.XMLStreamWriter; -import org.apache.olingo.odata2.core.xml.XMLStreamWriterFactory; +import org.apache.olingo.odata2.core.xml.XmlStreamFactory; /** * Provider for all basic (content type independent) entity provider methods. @@ -247,8 +247,7 @@ public class BasicEntityProvider { CircleStreamBuffer csb = new CircleStreamBuffer(); try { writer = new OutputStreamWriter(csb.getOutputStream(), DEFAULT_CHARSET); - XMLStreamWriterFactory xmlStreamWriterFactory = XMLStreamWriterFactory.create(); - XMLStreamWriter xmlStreamWriter = xmlStreamWriterFactory.createXMLStreamWriter(writer); + XMLStreamWriter xmlStreamWriter = XmlStreamFactory.createStreamWriter(writer); XmlMetadataProducer.writeMetadata(metadata, xmlStreamWriter, predefinedNamespaces); } catch (UnsupportedEncodingException e) { throw new EntityProviderException(EntityProviderException.EXCEPTION_OCCURRED.addContent(e.getClass() http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/15785c68/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/consumer/AtomServiceDocumentConsumer.java ---------------------------------------------------------------------- diff --git a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/consumer/AtomServiceDocumentConsumer.java b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/consumer/AtomServiceDocumentConsumer.java index 5dcbc19..774d07a 100644 --- a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/consumer/AtomServiceDocumentConsumer.java +++ b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/consumer/AtomServiceDocumentConsumer.java @@ -21,7 +21,7 @@ package org.apache.olingo.odata2.core.ep.consumer; import org.apache.olingo.odata2.api.edm.Edm; import org.apache.olingo.odata2.api.ep.EntityProviderException; import org.apache.olingo.odata2.api.servicedocument.*; -import org.apache.olingo.odata2.core.commons.XmlHelper; +import org.apache.olingo.odata2.core.xml.XmlStreamFactory; import org.apache.olingo.odata2.core.ep.util.FormatXml; import org.apache.olingo.odata2.core.servicedocument.*; import org.apache.olingo.odata2.core.xml.XMLStreamConstants; @@ -293,6 +293,6 @@ public class AtomServiceDocumentConsumer { } public ServiceDocumentImpl parseXml(final InputStream in) throws EntityProviderException { - return readServiceDokument(XmlHelper.createStreamReader(in)); + return readServiceDokument(XmlStreamFactory.createStreamReader(in)); } } http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/15785c68/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/consumer/XmlEntityConsumer.java ---------------------------------------------------------------------- diff --git a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/consumer/XmlEntityConsumer.java b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/consumer/XmlEntityConsumer.java index 3034574..f318efb 100644 --- a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/consumer/XmlEntityConsumer.java +++ b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/consumer/XmlEntityConsumer.java @@ -31,7 +31,7 @@ import org.apache.olingo.odata2.api.ep.EntityProviderReadProperties; import org.apache.olingo.odata2.api.ep.EntityProviderReadProperties.EntityProviderReadPropertiesBuilder; import org.apache.olingo.odata2.api.ep.entry.ODataEntry; import org.apache.olingo.odata2.api.ep.feed.ODataDeltaFeed; -import org.apache.olingo.odata2.core.commons.XmlHelper; +import org.apache.olingo.odata2.core.xml.XmlStreamFactory; import org.apache.olingo.odata2.core.ep.aggregator.EntityInfoAggregator; import org.apache.olingo.odata2.core.xml.XMLStreamException; import org.apache.olingo.odata2.core.xml.XMLStreamReader; @@ -53,7 +53,7 @@ public class XmlEntityConsumer { EntityProviderException cachedException = null; try { - reader = XmlHelper.createStreamReader(content); + reader = XmlStreamFactory.createStreamReader(content); EntityInfoAggregator eia = EntityInfoAggregator.create(entitySet); XmlFeedConsumer xfc = new XmlFeedConsumer(); @@ -83,7 +83,7 @@ public class XmlEntityConsumer { EntityProviderException cachedException = null; try { - reader = XmlHelper.createStreamReader(content); + reader = XmlStreamFactory.createStreamReader(content); EntityInfoAggregator eia = EntityInfoAggregator.create(entitySet); return new XmlEntryConsumer().readEntry(reader, eia, properties); @@ -113,7 +113,7 @@ public class XmlEntityConsumer { XmlPropertyConsumer xec = new XmlPropertyConsumer(); try { - reader = XmlHelper.createStreamReader(content); + reader = XmlStreamFactory.createStreamReader(content); Map<String, Object> result = xec.readProperty(reader, edmProperty, properties.getMergeSemantic(), properties.getTypeMappings()); return result; @@ -166,7 +166,7 @@ public class XmlEntityConsumer { XmlLinkConsumer xlc = new XmlLinkConsumer(); try { - reader = XmlHelper.createStreamReader(content); + reader = XmlStreamFactory.createStreamReader(content); return xlc.readLink(reader, entitySet); } catch (EntityProviderException e) { cachedException = e; @@ -193,7 +193,7 @@ public class XmlEntityConsumer { XmlLinkConsumer xlc = new XmlLinkConsumer(); try { - reader = XmlHelper.createStreamReader(content); + reader = XmlStreamFactory.createStreamReader(content); return xlc.readLinks(reader, entitySet); } catch (EntityProviderException e) { cachedException = e; http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/15785c68/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/consumer/XmlErrorDocumentConsumer.java ---------------------------------------------------------------------- diff --git a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/consumer/XmlErrorDocumentConsumer.java b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/consumer/XmlErrorDocumentConsumer.java index e87494a..0569469 100644 --- a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/consumer/XmlErrorDocumentConsumer.java +++ b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/consumer/XmlErrorDocumentConsumer.java @@ -22,7 +22,7 @@ import org.apache.olingo.odata2.api.edm.Edm; import org.apache.olingo.odata2.api.ep.EntityProviderException; import org.apache.olingo.odata2.api.processor.ODataErrorContext; import org.apache.olingo.odata2.core.commons.ContentType; -import org.apache.olingo.odata2.core.commons.XmlHelper; +import org.apache.olingo.odata2.core.xml.XmlStreamFactory; import org.apache.olingo.odata2.core.ep.util.FormatXml; import org.apache.olingo.odata2.core.xml.XMLStreamConstants; import org.apache.olingo.odata2.core.xml.XMLStreamException; @@ -61,7 +61,7 @@ public class XmlErrorDocumentConsumer { EntityProviderException cachedException = null; try { - reader = XmlHelper.createStreamReader(errorDocument); + reader = XmlStreamFactory.createStreamReader(errorDocument); return parserError(reader); } catch (XMLStreamException e) { cachedException = new EntityProviderException(EntityProviderException.INVALID_STATE.addContent( http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/15785c68/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 f2a40c2..bf5ffe5 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 @@ -25,12 +25,23 @@ import java.io.InputStream; /** */ -public class JavaxStaxReaderWrapper extends XMLStreamReader { +public class JavaxStaxReaderWrapper implements XMLStreamReader, XMLStreamReaderFactory { /** Default used charset for reader */ private static final String DEFAULT_CHARSET = "UTF-8"; - public static XMLStreamReader createStreamReader(final Object content) throws EntityProviderException { + private final javax.xml.stream.XMLStreamReader reader; + + private 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.")); @@ -63,12 +74,6 @@ public class JavaxStaxReaderWrapper extends XMLStreamReader { } } - private final javax.xml.stream.XMLStreamReader reader; - - public JavaxStaxReaderWrapper(javax.xml.stream.XMLStreamReader reader) { - this.reader = reader; - } - public String getLocalName() { return reader.getLocalName(); } @@ -209,8 +214,11 @@ public class JavaxStaxReaderWrapper extends XMLStreamReader { } - public static class JavaxNamespaceContext extends NamespaceContext { - javax.xml.namespace.NamespaceContext namespaceContext; + /** + * + */ + public class JavaxNamespaceContext implements NamespaceContext { + private final javax.xml.namespace.NamespaceContext namespaceContext; public JavaxNamespaceContext(javax.xml.namespace.NamespaceContext namespaceContext) { this.namespaceContext = namespaceContext; @@ -222,13 +230,18 @@ public class JavaxStaxReaderWrapper extends XMLStreamReader { } } - public static class JavaxQName extends QName { + /** + * + */ + public class JavaxQName implements QName { + private final javax.xml.namespace.QName qname; public JavaxQName(javax.xml.namespace.QName qname) { - this(qname.getNamespaceURI()); + this.qname = qname; } - protected JavaxQName(String namespaceURI) { - super(namespaceURI); + @Override + public String getNamespaceURI() { + return qname.getNamespaceURI(); } } } http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/15785c68/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 c686195..6292224 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 @@ -24,8 +24,16 @@ import java.io.Writer; /** */ -public class JavaxStaxWriterWrapper extends XMLStreamWriter { - private javax.xml.stream.XMLStreamWriter xmlStreamWriter; +public class JavaxStaxWriterWrapper implements XMLStreamWriter, XMLStreamWriterFactory { + 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 XMLStreamException { @@ -36,9 +44,11 @@ public class JavaxStaxWriterWrapper extends XMLStreamWriter { try { XMLOutputFactory xouf = XMLOutputFactory.newFactory(); if (content instanceof OutputStream) { - xmlStreamWriter = xouf.createXMLStreamWriter((OutputStream) content); + javax.xml.stream.XMLStreamWriter javaxWriter = xouf.createXMLStreamWriter((OutputStream) content); + return new JavaxStaxWriterWrapper(javaxWriter); } else if (content instanceof Writer) { - xmlStreamWriter = xouf.createXMLStreamWriter((Writer) content); + 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() + "'."); @@ -46,12 +56,11 @@ public class JavaxStaxWriterWrapper extends XMLStreamWriter { } catch (javax.xml.stream.XMLStreamException e) { throw new XMLStreamException(e); } - return this; } - public static XMLStreamWriter create(Object content) throws XMLStreamException { - return new JavaxStaxWriterWrapper().createXMLStreamWriter(content); - } +// public static XMLStreamWriter create(Object content) throws XMLStreamException { +// return new JavaxStaxWriterWrapper(null).createXMLStreamWriter(content); +// } public void writeStartDocument() throws XMLStreamException { try { http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/15785c68/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/xml/NamespaceContext.java ---------------------------------------------------------------------- diff --git a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/xml/NamespaceContext.java b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/xml/NamespaceContext.java index d4f4329..c8ee79e 100644 --- a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/xml/NamespaceContext.java +++ b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/xml/NamespaceContext.java @@ -19,10 +19,8 @@ package org.apache.olingo.odata2.core.xml; /** + * Based on NamespaceContext from JDK. */ -public abstract class NamespaceContext { - protected String prefix; - public String getPrefix(String customNamespaceURI) { - return prefix; - } +public interface NamespaceContext { + String getPrefix(String customNamespaceURI); } http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/15785c68/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/xml/QName.java ---------------------------------------------------------------------- diff --git a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/xml/QName.java b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/xml/QName.java index a18384e..286cdf9 100644 --- a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/xml/QName.java +++ b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/xml/QName.java @@ -19,15 +19,8 @@ package org.apache.olingo.odata2.core.xml; /** + * Based on QName from JDK. */ -public abstract class QName { - private String namespaceURI; - - protected QName(String namespaceURI) { - this.namespaceURI = namespaceURI; - } - - public String getNamespaceURI() { - return namespaceURI; - } -} +public interface QName { + String getNamespaceURI(); +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/15785c68/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/xml/XMLStreamConstants.java ---------------------------------------------------------------------- diff --git a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/xml/XMLStreamConstants.java b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/xml/XMLStreamConstants.java index 5ff403e..00f3818 100644 --- a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/xml/XMLStreamConstants.java +++ b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/xml/XMLStreamConstants.java @@ -19,6 +19,7 @@ package org.apache.olingo.odata2.core.xml; /** + * Based on XMLStreamConstants from JDK. */ public interface XMLStreamConstants { int START_ELEMENT = 1; http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/15785c68/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/xml/XMLStreamReader.java ---------------------------------------------------------------------- diff --git a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/xml/XMLStreamReader.java b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/xml/XMLStreamReader.java index 083b2d5..ff05941 100644 --- a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/xml/XMLStreamReader.java +++ b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/xml/XMLStreamReader.java @@ -18,34 +18,10 @@ ******************************************************************************/ package org.apache.olingo.odata2.core.xml; - -import org.apache.olingo.odata2.api.ep.EntityProviderException; - /** + * Based on XMLStreamReader from JDK. */ -public abstract class XMLStreamReader { - - public static final String XML_STREAM_READER_FACTORY_CLASS = "XMLStreamReaderFactoryClass"; - - public static XMLStreamReader createXMLStreamReader(Object content) throws EntityProviderException { - String factory = System.getProperty(XML_STREAM_READER_FACTORY_CLASS); - if(factory != null) { - try { -// System.out.println("Load stream reader factory class: " + factory); - Class factoryClass = Class.forName(factory); - XMLStreamReaderFactory factoryInstance = (XMLStreamReaderFactory) factoryClass.newInstance(); - return factoryInstance.createXMLStreamReader(content); - } catch (Exception e) { - throw new EntityProviderException( - EntityProviderException.EXCEPTION_OCCURRED.addContent(e.getMessage())); - } - } - return JavaxStaxReaderWrapper.createStreamReader(content); - } - - public interface XMLStreamReaderFactory { - XMLStreamReader createXMLStreamReader(Object content); - } +public interface XMLStreamReader { public abstract String getLocalName(); http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/15785c68/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/xml/XMLStreamReaderFactory.java ---------------------------------------------------------------------- diff --git a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/xml/XMLStreamReaderFactory.java b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/xml/XMLStreamReaderFactory.java new file mode 100644 index 0000000..3b201b0 --- /dev/null +++ b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/xml/XMLStreamReaderFactory.java @@ -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.olingo.odata2.core.xml; + +import org.apache.olingo.odata2.api.ep.EntityProviderException; + +/** + * + */ +public interface XMLStreamReaderFactory { + static final String XML_STREAM_READER_FACTORY_CLASS = "XMLStreamReaderFactoryClass"; + + XMLStreamReader createXMLStreamReader(Object content) throws EntityProviderException; +} http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/15785c68/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/xml/XMLStreamWriter.java ---------------------------------------------------------------------- diff --git a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/xml/XMLStreamWriter.java b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/xml/XMLStreamWriter.java index 0726350..fa24e9b 100644 --- a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/xml/XMLStreamWriter.java +++ b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/xml/XMLStreamWriter.java @@ -19,27 +19,9 @@ package org.apache.olingo.odata2.core.xml; /** + * Based on XMLStreamWriter from JDK. */ -public abstract class XMLStreamWriter extends XMLStreamWriterFactory { - -// public static XMLStreamWriter createXMLStreamWriter(Object content) -// throws EntityProviderException, XMLStreamException { -// -// String factory = System.getProperty(XML_STREAM_WRITER_FACTORY_CLASS); -// if (factory != null) { -// try { -// Class factoryClass = Class.forName(factory); -// XMLStreamWriterFactory factoryInstance = (XMLStreamWriterFactory) factoryClass.newInstance(); -// return factoryInstance.createXMLStreamWriter(content); -// } catch (Exception e) { -// throw new EntityProviderException( -// EntityProviderException.EXCEPTION_OCCURRED.addContent(e.getMessage())); -// } -// } -// return new JavaxStaxWriterWrapper.createXmlStreamReader(content); -// } - - +public interface XMLStreamWriter { public abstract void writeStartDocument() throws XMLStreamException; http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/15785c68/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/xml/XMLStreamWriterFactory.java ---------------------------------------------------------------------- diff --git a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/xml/XMLStreamWriterFactory.java b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/xml/XMLStreamWriterFactory.java index 4875d44..2cd65cb 100644 --- a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/xml/XMLStreamWriterFactory.java +++ b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/xml/XMLStreamWriterFactory.java @@ -21,24 +21,10 @@ package org.apache.olingo.odata2.core.xml; import org.apache.olingo.odata2.api.ep.EntityProviderException; /** - * Created by d046871 on 02.04.14. + * */ -public abstract class XMLStreamWriterFactory { - public static final String XML_STREAM_WRITER_FACTORY_CLASS = "XML_STREAM_WRITER_FACTORY_CLASS"; - - public abstract XMLStreamWriter createXMLStreamWriter(Object content) throws XMLStreamException; +public interface XMLStreamWriterFactory{ + static final String XML_STREAM_WRITER_FACTORY_CLASS = "XML_STREAM_WRITER_FACTORY_CLASS"; - public static XMLStreamWriterFactory create() throws EntityProviderException { - String factory = System.getProperty(XML_STREAM_WRITER_FACTORY_CLASS); - if (factory != null) { - try { - Class factoryClass = Class.forName(factory); - return (XMLStreamWriterFactory) factoryClass.newInstance(); - } catch (Exception e) { - throw new EntityProviderException( - EntityProviderException.EXCEPTION_OCCURRED.addContent(e.getMessage())); - } - } - return new JavaxStaxWriterWrapper(); - } -} + XMLStreamWriter createXMLStreamWriter(Object content) throws XMLStreamException, EntityProviderException; +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/15785c68/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 new file mode 100644 index 0000000..1937f2e --- /dev/null +++ b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/xml/XmlStreamFactory.java @@ -0,0 +1,79 @@ +/******************************************************************************* + * 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; + +/** + * + */ +public class XmlStreamFactory implements XMLStreamWriterFactory, XMLStreamReaderFactory { + + public static XMLStreamReader createStreamReader(final Object content) + throws EntityProviderException { + XmlStreamFactory factory = new XmlStreamFactory(); + return factory.createXMLStreamReader(content); + } + + public static XMLStreamWriter createStreamWriter(final Object content) + throws EntityProviderException, XMLStreamException { + XmlStreamFactory factory = new XmlStreamFactory(); + return factory.createXMLStreamWriter(content); + } + + public XMLStreamReaderFactory createReaderFactory() throws EntityProviderException { + String factory = System.getProperty(XML_STREAM_READER_FACTORY_CLASS); + if(factory != null) { + try { + Class factoryClass = Class.forName(factory); + return (XMLStreamReaderFactory) factoryClass.newInstance(); + } catch (Exception e) { + throw new EntityProviderException( + EntityProviderException.EXCEPTION_OCCURRED.addContent(e.getMessage())); + } + } + return JavaxStaxReaderWrapper.createFactory(); + } + + public XMLStreamWriterFactory createWriterFactory() throws EntityProviderException { + String factory = System.getProperty(XML_STREAM_WRITER_FACTORY_CLASS); + if (factory != null) { + try { + Class factoryClass = Class.forName(factory); + return (XMLStreamWriterFactory) factoryClass.newInstance(); + } catch (Exception e) { + throw new EntityProviderException( + EntityProviderException.EXCEPTION_OCCURRED.addContent(e.getMessage())); + } + } + return JavaxStaxWriterWrapper.createFactory(); + } + + @Override + public XMLStreamReader createXMLStreamReader(Object content) throws EntityProviderException { + XMLStreamReaderFactory factory = createReaderFactory(); + return factory.createXMLStreamReader(content); + } + + @Override + public XMLStreamWriter createXMLStreamWriter(Object content) throws XMLStreamException, EntityProviderException { + XMLStreamWriterFactory factory = createWriterFactory(); + return factory.createXMLStreamWriter(content); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/15785c68/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/consumer/AbstractConsumerTest.java ---------------------------------------------------------------------- diff --git a/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/consumer/AbstractConsumerTest.java b/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/consumer/AbstractConsumerTest.java index 67bcd56..2846683 100644 --- a/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/consumer/AbstractConsumerTest.java +++ b/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/consumer/AbstractConsumerTest.java @@ -27,6 +27,7 @@ import org.apache.olingo.odata2.api.ep.feed.ODataFeed; import org.apache.olingo.odata2.api.exception.ODataException; import org.apache.olingo.odata2.core.xml.XMLStreamException; import org.apache.olingo.odata2.core.xml.XMLStreamReader; +import org.apache.olingo.odata2.core.xml.XmlStreamFactory; import org.apache.olingo.odata2.testutil.fit.BaseTest; import org.apache.olingo.odata2.testutil.mock.MockFacade; @@ -61,9 +62,9 @@ public abstract class AbstractConsumerTest extends BaseTest { // // return streamReader; if(input == null) { - return XMLStreamReader.createXMLStreamReader(null); + return XmlStreamFactory.createStreamReader(null); } - return XMLStreamReader.createXMLStreamReader(new ByteArrayInputStream(input.getBytes())); + return XmlStreamFactory.createStreamReader(new ByteArrayInputStream(input.getBytes())); // return XMLStreamReader.createXMLStreamWriter(new StringReader(input)); } http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/15785c68/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 3392dc1..92a5750 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 @@ -254,7 +254,7 @@ public class AtomServiceDocumentConsumerTest extends AbstractXmlConsumerTest { if (in == null) { throw new IOException("Requested file '" + fileName + "' was not found."); } - return org.apache.olingo.odata2.core.xml.XMLStreamReader.createXMLStreamReader(in); + return org.apache.olingo.odata2.core.xml.XmlStreamFactory.createStreamReader(in); } private XMLStreamReader createStreamReader2(final String fileName) throws IOException, EntityProviderException { http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/15785c68/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/XmlMetadataProducerTest.java ---------------------------------------------------------------------- diff --git a/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/XmlMetadataProducerTest.java b/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/XmlMetadataProducerTest.java index 8771438..1ae8a23 100644 --- a/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/XmlMetadataProducerTest.java +++ b/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/XmlMetadataProducerTest.java @@ -42,6 +42,7 @@ import org.apache.olingo.odata2.core.ep.AbstractXmlProducerTestHelper; import org.apache.olingo.odata2.core.ep.util.CircleStreamBuffer; import org.apache.olingo.odata2.core.xml.XMLStreamWriter; import org.apache.olingo.odata2.core.xml.XMLStreamWriterFactory; +import org.apache.olingo.odata2.core.xml.XmlStreamFactory; import org.apache.olingo.odata2.testutil.helper.StringHelper; import org.custommonkey.xmlunit.NamespaceContext; import org.custommonkey.xmlunit.SimpleNamespaceContext; @@ -59,7 +60,7 @@ public class XmlMetadataProducerTest extends AbstractXmlProducerTestHelper { @Before public void before() throws EntityProviderException { - xmlStreamWriterFactory = XMLStreamWriterFactory.create(); + xmlStreamWriterFactory = new XmlStreamFactory().createWriterFactory(); } @Test
