Author: veithen
Date: Wed Jan 19 21:22:03 2011
New Revision: 1060995
URL: http://svn.apache.org/viewvc?rev=1060995&view=rev
Log:
AXIOM-353: Also provide replacements for the old
OMXMLBuilderFactory#createStAXSOAPModelBuilder method.
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMMetaFactory.java
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMXMLBuilderFactory.java
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/AbstractOMMetaFactory.java
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/soap/SOAPTestCase.java
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMMetaFactory.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMMetaFactory.java?rev=1060995&r1=1060994&r2=1060995&view=diff
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMMetaFactory.java
(original)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMMetaFactory.java
Wed Jan 19 21:22:03 2011
@@ -63,11 +63,14 @@ public interface OMMetaFactory {
SOAPFactory getSOAP12Factory();
/**
- * Create an object model builder that pulls events from a StAX stream
reader.
+ * Create an object model builder for plain XML that pulls events from a
StAX stream reader.
*
* @param omFactory
- * the object model factory to use; must be obtained from the
same
- * {@link OMMetaFactory}
+ * The object model factory to use. This factory must be
obtained from the same
+ * {@link OMMetaFactory} instance as the one used to invoke
this method. In general
+ * the factory will be retrieved from {@link #getOMFactory()}),
but in some cases it
+ * may be necessary to pass a {@link SOAPFactory} instance,
although this method will
+ * never produce a SOAP infoset.
* @param parser
* the stream reader to read the XML data from
* @return the builder
@@ -75,12 +78,15 @@ public interface OMMetaFactory {
OMXMLParserWrapper createStAXOMBuilder(OMFactory omFactory,
XMLStreamReader parser);
/**
- * Create an object model builder that reads an XML document from the
provided input
+ * Create an object model builder for plain XML that reads a document from
the provided input
* source.
*
* @param omFactory
- * the object model factory to use; must be obtained from the
same
- * {@link OMMetaFactory}
+ * The object model factory to use. This factory must be
obtained from the same
+ * {@link OMMetaFactory} instance as the one used to invoke
this method. In general
+ * the factory will be retrieved from {@link #getOMFactory()}),
but in some cases it
+ * may be necessary to pass a {@link SOAPFactory} instance,
although this method will
+ * never produce a SOAP infoset.
* @param configuration
* the parser configuration to use
* @param is
@@ -88,4 +94,32 @@ public interface OMMetaFactory {
* @return the builder
*/
OMXMLParserWrapper createOMBuilder(OMFactory omFactory,
StAXParserConfiguration configuration, InputSource is);
+
+ /**
+ * Create an object model builder for SOAP that pulls events from a StAX
stream reader. The
+ * implementation will select the appropriate {@link SOAPFactory} based on
the namespace URI of
+ * the SOAP envelope.
+ *
+ * @param configuration
+ * the parser configuration to use; for security reasons, this
should in general be
+ * {@link StAXParserConfiguration#SOAP}
+ * @param parser
+ * the stream reader to read the SOAP message from
+ * @return the builder
+ */
+ OMXMLParserWrapper createStAXSOAPModelBuilder(XMLStreamReader reader);
+
+ /**
+ * Create an object model builder for SOAP that reads a message from the
provided input source.
+ * The implementation will select the appropriate {@link SOAPFactory}
based on the namespace URI
+ * of the SOAP envelope.
+ *
+ * @param configuration
+ * the parser configuration to use; for security reasons, this
should in general be
+ * {@link StAXParserConfiguration#SOAP}
+ * @param is
+ * the source of the SOAP message
+ * @return the builder
+ */
+ OMXMLParserWrapper createSOAPModelBuilder(StAXParserConfiguration
configuration, InputSource is);
}
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMXMLBuilderFactory.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMXMLBuilderFactory.java?rev=1060995&r1=1060994&r2=1060995&view=diff
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMXMLBuilderFactory.java
(original)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMXMLBuilderFactory.java
Wed Jan 19 21:22:03 2011
@@ -24,6 +24,7 @@ import java.io.Reader;
import javax.xml.stream.XMLStreamReader;
import org.apache.axiom.om.util.StAXParserConfiguration;
+import org.apache.axiom.soap.SOAPFactory;
import org.xml.sax.InputSource;
/**
@@ -176,4 +177,22 @@ public class OMXMLBuilderFactory {
public static OMXMLParserWrapper createOMBuilder(OMFactory omFactory,
StAXParserConfiguration configuration, Reader in) {
return omFactory.getMetaFactory().createOMBuilder(omFactory,
configuration, new InputSource(in));
}
+
+ /**
+ * Create an object model builder for SOAP that reads a message from the
provided input stream,
+ * using a given charset encoding. The method will select the appropriate
{@link SOAPFactory}
+ * based on the namespace URI of the SOAP envelope. It will configure the
underlying parser as
+ * specified by {@link StAXParserConfiguration#SOAP}.
+ *
+ * @param in
+ * the input stream containing the SOAP message
+ * @param encoding
+ * the charset encoding
+ * @return the builder
+ */
+ public static OMXMLParserWrapper createSOAPModelBuilder(InputStream in,
String encoding) {
+ InputSource is = new InputSource(in);
+ is.setEncoding(encoding);
+ return
OMAbstractFactory.getMetaFactory().createSOAPModelBuilder(StAXParserConfiguration.SOAP,
is);
+ }
}
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/AbstractOMMetaFactory.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/AbstractOMMetaFactory.java?rev=1060995&r1=1060994&r2=1060995&view=diff
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/AbstractOMMetaFactory.java
(original)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/AbstractOMMetaFactory.java
Wed Jan 19 21:22:03 2011
@@ -28,6 +28,7 @@ import org.apache.axiom.om.OMXMLParserWr
import org.apache.axiom.om.impl.builder.StAXOMBuilder;
import org.apache.axiom.om.util.StAXParserConfiguration;
import org.apache.axiom.om.util.StAXUtils;
+import org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder;
import org.xml.sax.InputSource;
/**
@@ -35,34 +36,46 @@ import org.xml.sax.InputSource;
* ({@link org.apache.axiom.om.impl.builder.StAXOMBuilder} and its subclasses).
*/
public abstract class AbstractOMMetaFactory implements OMMetaFactory {
- public OMXMLParserWrapper createStAXOMBuilder(OMFactory omFactory,
XMLStreamReader parser) {
- StAXOMBuilder builder = new StAXOMBuilder(omFactory, parser);
- // StAXOMBuilder defaults to the "legacy" behavior, which is to keep a
reference to the
- // parser after the builder has been closed. Since releasing this
reference is a good idea
- // we default to releaseParserOnClose=true for builders created
through the OMMetaFactory
- // API.
- builder.releaseParserOnClose(true);
- return builder;
- }
-
- public OMXMLParserWrapper createOMBuilder(OMFactory omFactory,
StAXParserConfiguration configuration, InputSource is) {
+ private XMLStreamReader createXMLStreamReader(StAXParserConfiguration
configuration, InputSource is) {
try {
- XMLStreamReader reader;
if (is.getByteStream() != null) {
String encoding = is.getEncoding();
if (encoding == null) {
- reader = StAXUtils.createXMLStreamReader(configuration,
is.getByteStream());
+ return StAXUtils.createXMLStreamReader(configuration,
is.getByteStream());
} else {
- reader = StAXUtils.createXMLStreamReader(configuration,
is.getByteStream(), encoding);
+ return StAXUtils.createXMLStreamReader(configuration,
is.getByteStream(), encoding);
}
} else if (is.getCharacterStream() != null) {
- reader = StAXUtils.createXMLStreamReader(configuration,
is.getCharacterStream());
+ return StAXUtils.createXMLStreamReader(configuration,
is.getCharacterStream());
} else {
throw new IllegalArgumentException();
}
- return createStAXOMBuilder(omFactory, reader);
} catch (XMLStreamException ex) {
throw new OMException(ex);
}
}
+
+ public OMXMLParserWrapper createStAXOMBuilder(OMFactory omFactory,
XMLStreamReader parser) {
+ StAXOMBuilder builder = new StAXOMBuilder(omFactory, parser);
+ // StAXOMBuilder defaults to the "legacy" behavior, which is to keep a
reference to the
+ // parser after the builder has been closed. Since releasing this
reference is a good idea
+ // we default to releaseParserOnClose=true for builders created
through the OMMetaFactory
+ // API.
+ builder.releaseParserOnClose(true);
+ return builder;
+ }
+
+ public OMXMLParserWrapper createOMBuilder(OMFactory omFactory,
StAXParserConfiguration configuration, InputSource is) {
+ return createStAXOMBuilder(omFactory,
createXMLStreamReader(configuration, is));
+ }
+
+ public OMXMLParserWrapper createStAXSOAPModelBuilder(XMLStreamReader
parser) {
+ StAXSOAPModelBuilder builder = new StAXSOAPModelBuilder(this, parser);
+ builder.releaseParserOnClose(true);
+ return builder;
+ }
+
+ public OMXMLParserWrapper createSOAPModelBuilder(StAXParserConfiguration
configuration, InputSource is) {
+ return createStAXSOAPModelBuilder(createXMLStreamReader(configuration,
is));
+ }
}
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/soap/SOAPTestCase.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/soap/SOAPTestCase.java?rev=1060995&r1=1060994&r2=1060995&view=diff
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/soap/SOAPTestCase.java
(original)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/soap/SOAPTestCase.java
Wed Jan 19 21:22:03 2011
@@ -18,16 +18,16 @@
*/
package org.apache.axiom.ts.soap;
-import javax.xml.stream.XMLStreamException;
-import javax.xml.stream.XMLStreamReader;
+import java.io.InputStream;
import org.apache.axiom.om.AbstractTestCase;
import org.apache.axiom.om.OMMetaFactory;
-import org.apache.axiom.om.util.StAXUtils;
+import org.apache.axiom.om.OMXMLBuilderFactory;
+import org.apache.axiom.om.util.StAXParserConfiguration;
import org.apache.axiom.soap.SOAPEnvelope;
import org.apache.axiom.soap.SOAPFactory;
-import org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder;
import org.apache.axiom.ts.AxiomTestCase;
+import org.xml.sax.InputSource;
public class SOAPTestCase extends AxiomTestCase {
protected static final String MESSAGE = "message.xml";
@@ -50,14 +50,10 @@ public class SOAPTestCase extends AxiomT
}
protected SOAPEnvelope getTestMessage(String name) {
- String folder = spec.getName();
- XMLStreamReader parser;
- try {
- parser =
StAXUtils.createXMLStreamReader(AbstractTestCase.getTestResource("soap/" +
folder + "/" + name));
- } catch (XMLStreamException ex) {
- fail("Failed to get test message " + name + ": " +
ex.getMessage());
- return null;
- }
- return new StAXSOAPModelBuilder(parser, soapFactory,
spec.getEnvelopeNamespaceURI()).getSOAPEnvelope();
+ InputStream in = AbstractTestCase.getTestResource("soap/" +
spec.getName() + "/" + name);
+ SOAPEnvelope envelope =
(SOAPEnvelope)metaFactory.createSOAPModelBuilder(StAXParserConfiguration.SOAP,
+ new InputSource(in)).getDocumentElement();
+ assertSame(spec.getEnvelopeNamespaceURI(),
((SOAPFactory)envelope.getOMFactory()).getSoapVersionURI());
+ return envelope;
}
}