You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ws.apache.org by ve...@apache.org on 2013/01/14 22:19:16 UTC
svn commit: r1433134 - in /webservices/axiom/branches/AXIOM-201: ./
code-coverage/ devguide/src/docbkx/ modules/axiom-common-impl-testsuite/
modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/
modules/axiom-dom/ modules/axiom-dom/s...
Author: veithen
Date: Mon Jan 14 21:19:15 2013
New Revision: 1433134
URL: http://svn.apache.org/viewvc?rev=1433134&view=rev
Log:
Merged latest changes from trunk.
Added:
webservices/axiom/branches/AXIOM-201/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestGetXMLStreamReaderWithoutCachingPartiallyBuiltModified.java
- copied unchanged from r1433133, webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestGetXMLStreamReaderWithoutCachingPartiallyBuiltModified.java
Removed:
webservices/axiom/branches/AXIOM-201/modules/axiom-common-impl-testsuite/
webservices/axiom/branches/AXIOM-201/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/OMNavigator.java
webservices/axiom/branches/AXIOM-201/modules/axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/CommonImplTest.java
webservices/axiom/branches/AXIOM-201/modules/axiom-impl/src/test/java/org/apache/axiom/om/impl/llom/CommonImplTest.java
Modified:
webservices/axiom/branches/AXIOM-201/ (props changed)
webservices/axiom/branches/AXIOM-201/code-coverage/pom.xml
webservices/axiom/branches/AXIOM-201/devguide/src/docbkx/devguide.xml
webservices/axiom/branches/AXIOM-201/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/SwitchingWrapper.java
webservices/axiom/branches/AXIOM-201/modules/axiom-dom/pom.xml
webservices/axiom/branches/AXIOM-201/modules/axiom-impl/pom.xml
webservices/axiom/branches/AXIOM-201/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/OMTestSuiteBuilder.java
webservices/axiom/branches/AXIOM-201/pom.xml
Propchange: webservices/axiom/branches/AXIOM-201/
------------------------------------------------------------------------------
Merged /webservices/commons/trunk/modules/axiom:r1432263-1433133
Modified: webservices/axiom/branches/AXIOM-201/code-coverage/pom.xml
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/AXIOM-201/code-coverage/pom.xml?rev=1433134&r1=1433133&r2=1433134&view=diff
==============================================================================
--- webservices/axiom/branches/AXIOM-201/code-coverage/pom.xml (original)
+++ webservices/axiom/branches/AXIOM-201/code-coverage/pom.xml Mon Jan 14 21:19:15 2013
@@ -80,7 +80,6 @@
<groupId>${project.groupId}</groupId>
<artifactId>axiom-impl</artifactId>
<version>${project.version}</version>
- <classifier>original</classifier>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
@@ -100,7 +99,6 @@
<groupId>${project.groupId}</groupId>
<artifactId>axiom-dom</artifactId>
<version>${project.version}</version>
- <classifier>original</classifier>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
@@ -169,6 +167,14 @@
<dependency>
<groupId>${project.groupId}</groupId>
+ <artifactId>spring-ws-tests</artifactId>
+ <version>${project.version}</version>
+ <classifier>jacoco</classifier>
+ <type>exec</type>
+ </dependency>
+
+ <dependency>
+ <groupId>${project.groupId}</groupId>
<artifactId>axiom-samples</artifactId>
<version>${project.version}</version>
<classifier>jacoco</classifier>
Modified: webservices/axiom/branches/AXIOM-201/devguide/src/docbkx/devguide.xml
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/AXIOM-201/devguide/src/docbkx/devguide.xml?rev=1433134&r1=1433133&r2=1433134&view=diff
==============================================================================
--- webservices/axiom/branches/AXIOM-201/devguide/src/docbkx/devguide.xml (original)
+++ webservices/axiom/branches/AXIOM-201/devguide/src/docbkx/devguide.xml Mon Jan 14 21:19:15 2013
@@ -170,7 +170,41 @@ javax.xml.stream.XMLOutputFactory=com.be
</chapter>
<chapter>
- <title>OSGi integration</title>
+ <title>OSGi integration and separation between API and implementation</title>
+ <section>
+ <title>Introduction</title>
+ <para>
+ This chapter addresses two related architectural questions:
+ </para>
+ <itemizedlist>
+ <listitem>
+ <para>
+ OSGi support was originally introduced in Axiom 1.2.9, but the implementation had
+ a couple of flaws. This chapter discusses the rationale behind the new OSGi
+ support introduced in Axiom 1.2.13.
+ </para>
+ </listitem>
+ <listitem>
+ <para>
+ Axiom is designed as a set of abstract APIs for which two implementations are
+ provided: LLOM and DOOM. It is important to make a clear distinction between what
+ is part of the public API and what should be considered implementation classes that
+ must not be used by application code directly. This also implies that Axiom must
+ provide the necessary APIs to allow application code to access all features without
+ the need to access implementation classes directly. This chapter in particular
+ discusses the question how application code can request factories that support DOM
+ without the need to refer directly to DOOM.
+ </para>
+ </listitem>
+ </itemizedlist>
+ <para>
+ These two questions are closely related because OSGi allows to enforce the distinction
+ between public API and implementation classes by carefully selecting the packages
+ exported by the different bundles: only classes belonging to the public API
+ should be exported, while implementation classes should be private to the bundles
+ containing them. This in turn has implications for the packaging of these artifacts.
+ </para>
+ </section>
<section>
<title>Requirements</title>
<formalpara id="osgi-req-no-separate-bundles">
@@ -195,6 +229,13 @@ javax.xml.stream.XMLOutputFactory=com.be
doesn't need to be rewritten.
</para>
</formalpara>
+ <note>
+ <para>
+ This requirement was already satisfied by the OSGi support introduced in Axiom 1.2.9.
+ It therefore also ensures that the transition to the new OSGi support in Axiom 1.2.13
+ is transparent for applications that already use Axiom in an OSGi container.
+ </para>
+ </note>
<formalpara id="osgi-req-same-impl-selection">
<title>Requirement 3</title>
<para>
@@ -205,19 +246,12 @@ javax.xml.stream.XMLOutputFactory=com.be
a system property is not meaningful.
</para>
</formalpara>
- <note>
- <para>
- This is currently not the case. In a non OSGi environment, recent versions of Axiom
- use JDK 1.3 service discovery to locate the default implementation and fall back to
- LLOM if none is found. DOOM will never be selected as the default implementation.
- On the other hand, the current OSGi integration will select any Axiom implementation
- as default implementation, but gives priority to LLOM.
- </para>
- </note>
<formalpara id="osgi-ref-impl-not-exported">
<title>Requirement 4</title>
<para>
- The bundles for the LLOM and DOOM implementations MUST NOT export any packages.
+ Only classes belonging to the public API should be exported by the OSGi bundles.
+ Implementation classes should not be exported. In particular,
+ the bundles for the LLOM and DOOM implementations MUST NOT export any packages.
This is required to keep a clean separation between the public API and implementation
specific classes and to make sure that the implementations can be modified without the
risk of breaking existing code.
@@ -234,29 +268,30 @@ javax.xml.stream.XMLOutputFactory=com.be
they should be used in scope <literal>runtime</literal>.
</para>
<para>
- Although this requirement is easy to implement for the Axiom project, there are
- currently a couple of issues in the downstreams project that need to be addressed
- to make this work:
+ Although this requirement is easy to implement for the Axiom project, it requires
+ changes to downstreams project to make this actually work:
</para>
<itemizedlist>
<listitem>
<para>
As explained in <ulink url="https://issues.apache.org/jira/browse/AXIS2-4902">AXIS2-4902</ulink>,
- there are many places in Axis2 that still refer directly to Axiom implementation classes.
+ there used to be many places in Axis2 that still referred directly to Axiom implementation classes.
+ The same was true for Rampart and Sandesha2. This has now been fixed and all three projects
+ use <literal>axiom-impl</literal> and <literal>axiom-dom</literal> as dependencies in scope
+ <literal>runtime</literal>.
</para>
</listitem>
<listitem>
<para>
- The <literal>axis2-saaj</literal> module is tightly coupled to <literal>axiom-dom</literal>.
- Making this work will probably require using <literal>maven-shade-plugin</literal> to
- include (a relocated copy of) the DOOM classes into <literal>axis2-saaj</literal>.
+ Abdera extends the LLOM implementation. Probably, some <literal>maven-shade-plugin</literal>
+ magic will be required here to create Abdera OSGi bundles that work properly with
+ the Axiom bundles.
</para>
</listitem>
<listitem>
<para>
- Abdera extends the LLOM implementation. Probably, some <literal>maven-shade-plugin</literal>
- magic will be required here as well to create Abdera OSGi bundles that work properly with
- the Axiom bundles.
+ For Spring Web Services this issue is addressed by
+ <ulink url="https://jira.springsource.org/browse/SWS-822">SWS-822</ulink>.
</para>
</listitem>
</itemizedlist>
@@ -515,8 +550,9 @@ javax.xml.stream.XMLOutputFactory=com.be
<note>
<para>
DOOM is generally not considered suitable as a default implementation because it doesn't
- implement the complete Axiom API (e.g. it doesn't support <classname>OMSourcedElement</classname>)
- and because the factory classes are not stateless.
+ implement the complete Axiom API (e.g. it doesn't support <classname>OMSourcedElement</classname>).
+ In addition, in earlier versions of Axiom, the factory classes for DOOM were not stateless
+ (see <ulink url="https://issues.apache.org/jira/browse/AXIOM-412">AXIOM-412</ulink>).
</para>
</note>
<para>
@@ -603,6 +639,119 @@ javax.xml.stream.XMLOutputFactory=com.be
Axiom implementations (e.g. if the JAR is an uber-JAR repackaged from the standard Axiom JARs).
</para>
</section>
+ <section>
+ <title>Common implementation classes</title>
+ <para>
+ Obviously the LLOM and DOOM implementations share some amount of common code. Historically,
+ implementation classes reusable between LLOM and DOOM were placed in <literal>axiom-api</literal>.
+ This however tends to blur the distinction between the public API and implementation classes.
+ Starting with Axiom 1.2.13 such classes are placed into a separate module called
+ <literal>axiom-common-impl</literal>. However, <literal>axiom-common-impl</literal> cannot simply
+ be a dependency of <literal>axiom-impl</literal> and <literal>axiom-dom</literal>.
+ The reason is that in an OSGi environment, the <literal>axiom-common-impl</literal> bundle
+ would have to export these shared classes, which is in contradiction with <xref linkend="osgi-ref-impl-not-exported"/>.
+ Therefore the code from <literal>axiom-common-impl</literal> needs to be packaged into
+ <literal>axiom-impl</literal> and <literal>axiom-dom</literal> by the build process so that
+ the <literal>axiom-common-impl</literal> artifact is not required at runtime.
+ <xref linkend="osgi-req-no-separate-bundles"/> forbids using embedded JARs to achieve this.
+ Instead <literal>maven-shade-plugin</literal> is used to include the classes
+ from <literal>axiom-common-impl</literal> into <literal>axiom-impl</literal> and <literal>axiom-dom</literal>
+ (and to modify the POMs to remove the dependencies on <literal>axiom-common-impl</literal>).
+ </para>
+ <para>
+ This raises the question whether <literal>maven-shade-plugin</literal> should be configured to
+ simply copy the classes or to relocate them (i.e. to change their package names). There are a couple
+ of arguments in favor of relocating them:
+ </para>
+ <itemizedlist>
+ <listitem>
+ <para>
+ According to <xref linkend="osgi-req-no-separate-bundles"/>, the Axiom artifacts should be
+ usable both as normal JARs and as OSGi bundles. Obviously the expectation is that from the
+ point of view of application code, they should work in the same in OSGi and non OSGi environments.
+ Relocation is required if one wants to strictly satisfy this requirement even if different versions
+ of <literal>axiom-impl</literal> and <literal>axiom-dom</literal> are mixed.
+ Since the container creates separate class loaders for the <literal>axiom-impl</literal> and <literal>axiom-dom</literal> bundles,
+ it is always possible to do that in an OSGi environment: even if the shared classes
+ included in <literal>axiom-impl</literal> and <literal>axiom-dom</literal> are
+ not relocated, but have the same names, this will not result in conflicts.
+ The situation is different in a non OSGi environment where the classes in <literal>axiom-impl</literal>
+ and <literal>axiom-dom</literal> are loaded by the same class loader. If the shared classes
+ are not relocated, then there may be a conflict if the versions don't match.
+ </para>
+ <para>
+ However, in practice it is unlikely that there are valid use case where one would use
+ <literal>axiom-impl</literal> and <literal>axiom-dom</literal> artifacts from different Axiom versions.
+ </para>
+ </listitem>
+ <listitem>
+ <para>
+ Relocation allows to preserve compatibility when duplicate code from
+ <literal>axiom-impl</literal> and <literal>axiom-dom</literal> is merged and moved
+ to <literal>axiom-common-impl</literal>. The <classname>OMNamespaceImpl</classname>,
+ <classname>OMNavigator</classname> and <classname>OMStAXWrapper</classname> classes
+ from <literal>axiom-impl</literal> and the <classname>NamespaceImpl</classname>,
+ <classname>DOMNavigator</classname> and <classname>DOMStAXWrapper</classname>
+ classes from <literal>axiom-dom</literal> that existed in earlier versions of Axiom
+ are examples of this. The classes in <literal>axiom-dom</literal> were almost identical
+ to the corresponding classes in <literal>axiom-impl</literal>. These classes have been
+ merged and moved to <literal>axiom-common-impl</literal>. Relocation then allows them
+ to retain their original name (including the original package name) in the
+ <literal>axiom-impl</literal> and <literal>axiom-dom</literal> artifacts.
+ </para>
+ <para>
+ However, this is only a concern if one wants to preserve compatibility with existing
+ code that directly uses these implementation specific classes (which is something that is
+ strongly discouraged). One example where this was relevant was the SAAJ implementation
+ in Axis2 which used to be very strongly coupled to the DOOM implementation. This however
+ has been fixed now.
+ </para>
+ </listitem>
+ </itemizedlist>
+ <para>
+ Using relocation also has some serious disadvantages:
+ </para>
+ <itemizedlist>
+ <listitem>
+ <para>
+ Stack traces may contain class names that don't match class names in the Axiom source
+ code, making debugging harder.
+ </para>
+ </listitem>
+ <listitem>
+ <para>
+ Axiom now uses JaCoCo to produce code coverage reports. However these reports are
+ incomplete if relocation is used. This doesn't affect test cases executed in
+ the <literal>axiom-impl</literal> and <literal>axiom-dom</literal> modules
+ (because they are executed with the original classes), but tests in separate modules
+ (such as integration tests). There are actually two issues:
+ </para>
+ <itemizedlist>
+ <listitem>
+ <para>
+ For the relocated classes, JaCoCo is unable to find the corresponding source code.
+ This means that the reported code coverage is inaccurate for classes in
+ <literal>axiom-common-impl</literal>.
+ </para>
+ </listitem>
+ <listitem>
+ <para>
+ Relocation not only modifies the classes in <literal>axiom-common-impl</literal>, but
+ also the classes in <literal>axiom-impl</literal> and <literal>axiom-dom</literal>
+ that use them. JaCoCo <ulink url="https://github.com/jacoco/jacoco/issues/51">detects this</ulink>
+ and excludes the data from the coverage analysis. This means that the
+ reported code coverage will also be inaccurate for classes in
+ <literal>axiom-impl</literal> and <literal>axiom-dom</literal>.
+ </para>
+ </listitem>
+ </itemizedlist>
+ </listitem>
+ </itemizedlist>
+ <para>
+ In Axiom 1.2.14 relocation was used, but this has been changed in Axiom 1.2.15 because the disadvantages
+ outweigh the advantages.
+ </para>
+ </section>
</chapter>
<chapter>
Modified: webservices/axiom/branches/AXIOM-201/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/SwitchingWrapper.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/AXIOM-201/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/SwitchingWrapper.java?rev=1433134&r1=1433133&r2=1433134&view=diff
==============================================================================
--- webservices/axiom/branches/AXIOM-201/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/SwitchingWrapper.java (original)
+++ webservices/axiom/branches/AXIOM-201/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/SwitchingWrapper.java Mon Jan 14 21:19:15 2013
@@ -26,7 +26,6 @@ import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.NoSuchElementException;
-import java.util.Stack;
import javax.activation.DataHandler;
import javax.xml.namespace.NamespaceContext;
@@ -46,7 +45,6 @@ import org.apache.axiom.om.OMDocType;
import org.apache.axiom.om.OMDocument;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMEntityReference;
-import org.apache.axiom.om.OMException;
import org.apache.axiom.om.OMNamespace;
import org.apache.axiom.om.OMNode;
import org.apache.axiom.om.OMProcessingInstruction;
@@ -54,6 +52,7 @@ import org.apache.axiom.om.OMSerializabl
import org.apache.axiom.om.OMSourcedElement;
import org.apache.axiom.om.OMText;
import org.apache.axiom.om.OMXMLParserWrapper;
+import org.apache.axiom.om.impl.OMNodeEx;
import org.apache.axiom.om.impl.builder.StAXBuilder;
import org.apache.axiom.om.impl.exception.OMStreamingException;
import org.apache.axiom.util.namespace.MapBasedNamespaceContext;
@@ -70,8 +69,26 @@ class SwitchingWrapper extends AbstractX
private static final Log log = LogFactory.getLog(SwitchingWrapper.class);
- /** Field navigator */
- private OMNavigator navigator;
+ /**
+ * The current node, corresponding to the current event.
+ */
+ private OMSerializable node;
+
+ /**
+ * If the current node is an {@link OMContainer}, then this flag indicates whether the current
+ * event is the start event ({@link XMLStreamConstants#START_DOCUMENT} or
+ * {@link XMLStreamConstants#START_ELEMENT}) or the end event
+ * ({@link XMLStreamConstants#END_DOCUMENT} or {@link XMLStreamConstants#END_ELEMENT}) for that
+ * node. In the latter case, we have already visited the node before, hence the name of the
+ * attribute.
+ */
+ private boolean visited;
+
+ /**
+ * Indicates if an OMSourcedElement with an OMDataSource should
+ * be considered as an interior node or a leaf node.
+ */
+ private boolean isDataSourceALeaf;
/** Field builder */
private OMXMLParserWrapper builder;
@@ -85,14 +102,13 @@ class SwitchingWrapper extends AbstractX
*/
private DataHandlerReader dataHandlerReader;
- private boolean _isClosed = false; // Indicate if parser is closed
- private boolean _releaseParserOnClose = false; // Defaults to legacy behavior, which is keep the reference
-
- /** Field rootNode */
- private OMContainer rootNode;
+ private boolean isClosed = false; // Indicate if parser is closed
+ private boolean releaseParserOnClose = false; // Defaults to legacy behavior, which is keep the reference
- /** Field isFirst */
- private boolean isFirst = true;
+ /**
+ * The root node, i.e. the node from which the {@link XMLStreamReader} has been requested.
+ */
+ private final OMContainer rootNode;
// Navigable means the output should be taken from the navigator.
// As soon as the navigator returns a null navigable will be reset
@@ -101,7 +117,6 @@ class SwitchingWrapper extends AbstractX
/** Field NAVIGABLE */
private static final short NAVIGABLE = 0;
- private static final short SWITCH_AT_NEXT = 1;
/**
* Indicates that the last event before the final {@link XMLStreamConstants#END_DOCUMENT} event
@@ -137,27 +152,6 @@ class SwitchingWrapper extends AbstractX
*/
private final boolean preserveNamespaceContext;
- /** Field elementStack */
- private Stack nodeStack = null;
-
- // keeps the next event. The parser actually keeps one step ahead to
- // detect the end of navigation. (at the end of the stream the navigator
- // returns a null
-
- /** Field nextNode */
- private OMSerializable nextNode = null;
-
- // holder for the current node. Needs this to generate events from the
- // current node
-
- /** Field currentNode */
- private OMSerializable currentNode = null;
-
- // needs this to refer to the last known node
-
- /** Field lastNode */
- private OMSerializable lastNode = null;
-
/** Track depth to ensure we stop generating events when we are done with the root node. */
int depth = 0;
@@ -181,29 +175,18 @@ class SwitchingWrapper extends AbstractX
public SwitchingWrapper(OMXMLParserWrapper builder, OMContainer startNode,
boolean cache, boolean preserveNamespaceContext) {
- // create a navigator
- this.navigator = new OMNavigator(startNode);
this.builder = builder;
this.rootNode = startNode;
this.cache = cache;
this.preserveNamespaceContext = preserveNamespaceContext;
- // initiate the next and current nodes
- // Note - navigator is written in such a way that it first
- // returns the starting node at the first call to it
-
- currentNode = navigator.getNext();
- updateNextNode(!cache);
+ // If the start node is a document it become the current node. If the start node
+ // is an element, then there is no current node, because there is no node
+ // corresponding to the current event (START_DOCUMENT).
if (startNode instanceof OMDocument) {
- currentEvent = -1;
- try {
- next();
- } catch (XMLStreamException ex) {
- throw new OMException(ex);
- }
- } else {
- currentEvent = START_DOCUMENT;
+ node = startNode;
}
+ currentEvent = START_DOCUMENT;
}
/**
@@ -216,7 +199,7 @@ class SwitchingWrapper extends AbstractX
} else {
if ((currentEvent == START_ELEMENT)
|| (currentEvent == END_ELEMENT)) {
- return ((OMElement)lastNode).getPrefix();
+ return ((OMElement)node).getPrefix();
} else {
throw new IllegalStateException();
}
@@ -233,7 +216,7 @@ class SwitchingWrapper extends AbstractX
} else {
if ((currentEvent == START_ELEMENT)
|| (currentEvent == END_ELEMENT)) {
- return ((OMElement)lastNode).getNamespaceURI();
+ return ((OMElement)node).getNamespaceURI();
} else {
throw new IllegalStateException();
}
@@ -264,9 +247,9 @@ class SwitchingWrapper extends AbstractX
switch (currentEvent) {
case START_ELEMENT:
case END_ELEMENT:
- return ((OMElement)lastNode).getLocalName();
+ return ((OMElement)node).getLocalName();
case ENTITY_REFERENCE:
- return ((OMEntityReference)lastNode).getName();
+ return ((OMEntityReference)node).getName();
default:
throw new IllegalStateException();
}
@@ -283,7 +266,7 @@ class SwitchingWrapper extends AbstractX
} else {
if ((currentEvent == START_ELEMENT)
|| (currentEvent == END_ELEMENT)) {
- return ((OMElement)lastNode).getQName();
+ return ((OMElement)node).getQName();
} else {
throw new IllegalStateException();
}
@@ -368,11 +351,11 @@ class SwitchingWrapper extends AbstractX
// and the other ones in getTextFromNode().
switch (currentEvent) {
case DTD:
- String internalSubset = ((OMDocType)lastNode).getInternalSubset();
+ String internalSubset = ((OMDocType)node).getInternalSubset();
// Woodstox returns the empty string if there is no internal subset
return internalSubset != null ? internalSubset : "";
case ENTITY_REFERENCE:
- return ((OMEntityReference)lastNode).getReplacementText();
+ return ((OMEntityReference)node).getReplacementText();
default:
return getTextFromNode();
}
@@ -391,9 +374,9 @@ class SwitchingWrapper extends AbstractX
case CHARACTERS:
case CDATA:
case SPACE:
- return ((OMText)lastNode).getText();
+ return ((OMText)node).getText();
case COMMENT:
- return ((OMComment)lastNode).getValue();
+ return ((OMComment)node).getValue();
default:
throw new IllegalStateException();
}
@@ -407,7 +390,7 @@ class SwitchingWrapper extends AbstractX
case CHARACTERS:
case CDATA:
case SPACE:
- OMText text = (OMText)lastNode;
+ OMText text = (OMText)node;
if (text.isCharacters()) {
writer.write(text.getTextCharacters());
} else {
@@ -416,7 +399,7 @@ class SwitchingWrapper extends AbstractX
}
break;
case COMMENT:
- writer.write(((OMComment)lastNode).getValue());
+ writer.write(((OMComment)node).getValue());
break;
default:
throw new IllegalStateException();
@@ -437,7 +420,7 @@ class SwitchingWrapper extends AbstractX
private void loadAttributes() {
if (attributeCount == -1) {
attributeCount = 0;
- for (Iterator it = ((OMElement)lastNode).getAllAttributes(); it.hasNext(); ) {
+ for (Iterator it = ((OMElement)node).getAllAttributes(); it.hasNext(); ) {
OMAttribute attr = (OMAttribute)it.next();
if (attributeCount == attributes.length) {
OMAttribute[] newAttributes = new OMAttribute[attributes.length*2];
@@ -458,11 +441,11 @@ class SwitchingWrapper extends AbstractX
private void loadNamespaces() {
if (namespaceCount == -1) {
namespaceCount = 0;
- for (Iterator it = ((OMElement)lastNode).getAllDeclaredNamespaces(); it.hasNext(); ) {
+ for (Iterator it = ((OMElement)node).getAllDeclaredNamespaces(); it.hasNext(); ) {
addNamespace((OMNamespace)it.next());
}
- if (preserveNamespaceContext && lastNode == rootNode) {
- OMElement element = (OMElement)lastNode;
+ if (preserveNamespaceContext && node == rootNode) {
+ OMElement element = (OMElement)node;
while (true) {
OMContainer container = element.getParent();
if (container instanceof OMElement) {
@@ -736,7 +719,7 @@ class SwitchingWrapper extends AbstractX
} else {
if (isStartElement()) {
QName qname = new QName(s, s1);
- OMAttribute attrib = ((OMElement) lastNode).getAttribute(qname);
+ OMAttribute attrib = ((OMElement) node).getAttribute(qname);
if (attrib != null) {
returnString = attrib.getAttributeValue();
}
@@ -819,9 +802,9 @@ class SwitchingWrapper extends AbstractX
} else {
if (isStartElement() || isEndElement()) {
- if (lastNode instanceof OMElement) {
+ if (node instanceof OMElement) {
OMNamespace namespaceURI =
- ((OMElement) lastNode).findNamespaceURI(prefix);
+ ((OMElement) node).findNamespaceURI(prefix);
return namespaceURI != null ? namespaceURI.getNamespaceURI() : null;
}
}
@@ -848,9 +831,9 @@ class SwitchingWrapper extends AbstractX
parser.close();
}
} finally {
- _isClosed = true;
+ isClosed = true;
// Release the parser so that it can be GC'd or reused.
- if (_releaseParserOnClose) {
+ if (releaseParserOnClose) {
setParser(null);
}
}
@@ -883,6 +866,94 @@ class SwitchingWrapper extends AbstractX
}
}
+ /** Private method to encapsulate the searching logic. */
+ private void nextNode() {
+ if (node == null) {
+ // We get here if rootNode is an element and the current event is START_DOCUMENT
+ node = rootNode;
+ } else if (!isLeaf(node) && !visited) {
+ OMNode firstChild = _getFirstChild((OMContainer) node);
+ if (firstChild != null) {
+ node = firstChild;
+ visited = false;
+ } else if (node.isComplete()) {
+ visited = true;
+ } else {
+ node = null;
+ }
+ } else {
+ OMNode nextNode = (OMNode)node;
+ OMContainer parent = nextNode.getParent();
+ OMNode nextSibling = getNextSibling(nextNode);
+ if (nextSibling != null) {
+ node = nextSibling;
+ visited = false;
+ } else if (parent.isComplete()) {
+ node = parent;
+ visited = true;
+ } else {
+ node = null;
+ }
+ }
+ }
+
+ /**
+ * @param n OMNode
+ * @return true if this OMNode should be considered a leaf node
+ */
+ private boolean isLeaf(OMSerializable n) {
+ if (n instanceof OMContainer) {
+ return this.isDataSourceALeaf && isOMSourcedElement(n) && n != rootNode;
+ } else {
+ return true;
+ }
+ }
+
+ private boolean isOMSourcedElement(OMSerializable node) {
+ if (node instanceof OMSourcedElement) {
+ try {
+ return ((OMSourcedElement)node).getDataSource() != null;
+ } catch (UnsupportedOperationException e) {
+ // Operation unsupported for some implementations
+ return false;
+ }
+ } else {
+ return false;
+ }
+ }
+
+ /**
+ * @param node
+ * @return first child or null
+ */
+ private OMNode _getFirstChild(OMContainer node) {
+ if (cache) {
+ return node.getFirstOMChild();
+ } else if (node.getBuilder() != rootNode.getBuilder()) {
+ // TODO: We have a problem if the tree has parts constructed by different builders; this is related to AXIOM-201 and AXIOM-431
+ OMNode first = node.getFirstOMChild();
+ OMNode sibling = first;
+ while (sibling != null) {
+ sibling = sibling.getNextOMSibling();
+ }
+ return first;
+ } else {
+ return ((IContainer)node).getFirstOMChildIfAvailable();
+ }
+ }
+
+ /**
+ * @param node
+ * @return next sibling or null
+ */
+ private OMNode getNextSibling(OMNode node) {
+ if (cache || isOMSourcedElement(node)) {
+ return node.getNextOMSibling();
+ } else {
+ return ((OMNodeEx) node).getNextOMSiblingIfAvailable();
+ }
+ }
+
/**
* Method next.
*
@@ -897,35 +968,32 @@ class SwitchingWrapper extends AbstractX
state = DOCUMENT_COMPLETE;
currentEvent = END_DOCUMENT;
break;
- case SWITCH_AT_NEXT:
- state = SWITCHED;
+ case NAVIGABLE:
+ nextNode();
+ if (node != null) {
+ currentEvent = generateEvents(node);
+ attributeCount = -1;
+ namespaceCount = -1;
+ } else {
+ // reset caching (the default is ON so it was not needed in the
+ // earlier case!
+ builder.setCache(false);
+ state = SWITCHED;
- // load the parser
- try {
- setParser((XMLStreamReader) builder.getParser());
- } catch (Exception e) {
- throw new XMLStreamException("problem accessing the parser. " + e.getMessage(),
- e);
- }
+ // load the parser
+ try {
+ setParser((XMLStreamReader) builder.getParser());
+ } catch (Exception e) {
+ throw new XMLStreamException("problem accessing the parser. " + e.getMessage(),
+ e);
+ }
- // We should throw an END_DOCUMENT
- if ((currentEvent == START_DOCUMENT)
- && (currentEvent == parser.getEventType())) {
currentEvent = parser.next();
- } else {
- currentEvent = parser.getEventType();
}
updateCompleteStatus();
break;
- case NAVIGABLE:
- currentEvent = generateEvents(currentNode);
- updateCompleteStatus();
- updateLastNode();
- break;
case SWITCHED:
- if (parser.hasNext()) {
- currentEvent = parser.next();
- }
+ currentEvent = parser.next();
updateCompleteStatus();
break;
default:
@@ -970,57 +1038,6 @@ class SwitchingWrapper extends AbstractX
return null;
}
- /**
- * This is a very important method. It keeps the navigator one step ahead and pushes it one
- * event ahead. If the nextNode is null then navigable is set to false. At the same time the
- * parser and builder are set up for the upcoming event generation.
- *
- * @throws XMLStreamException
- */
- private void updateLastNode() throws XMLStreamException {
- lastNode = currentNode;
- attributeCount = -1;
- namespaceCount = -1;
- currentNode = nextNode;
- updateNextNode(!cache);
- }
-
- /** Method updateNextNode. */
- private void updateNextNode(boolean switchingAllowed) {
- if (navigator.isNavigable()) {
- nextNode = navigator.getNext();
- } else {
- if (!switchingAllowed) {
- if (navigator.isCompleted() || builder == null || builder.isCompleted()) {
- nextNode = null;
- if (log.isDebugEnabled()) {
- if (builder == null || builder.isCompleted()) {
- log.debug("Builder is complete. Next node is set to null.");
- }
- }
- } else {
- builder.next();
- navigator.step();
- nextNode = navigator.getNext();
- }
- } else {
- //at this point check whether the navigator is done
- //if the navigator is done then we are fine and can directly
- // jump to the complete state ?
- if (navigator.isCompleted()) {
- nextNode = null;
- } else {
- // reset caching (the default is ON so it was not needed in the
- // earlier case!
- if (builder != null) {
- builder.setCache(false);
- }
- state = SWITCH_AT_NEXT;
- }
- }
- }
- }
-
/** Method updateCompleteStatus. */
private void updateCompleteStatus() {
if (currentEvent == START_ELEMENT) {
@@ -1029,10 +1046,8 @@ class SwitchingWrapper extends AbstractX
depth--;
}
if (state == NAVIGABLE) {
- if (rootNode == currentNode) {
- if (isFirst) {
- isFirst = false;
- } else if (currentEvent == END_DOCUMENT) {
+ if (rootNode == node && visited) {
+ if (currentEvent == END_DOCUMENT) {
state = DOCUMENT_COMPLETE;
} else {
state = COMPLETED;
@@ -1061,7 +1076,7 @@ class SwitchingWrapper extends AbstractX
return currentEvent == END_DOCUMENT ? new MapBasedNamespaceContext(Collections.EMPTY_MAP) : parser.getNamespaceContext();
} else {
return new MapBasedNamespaceContext(
- currentEvent == END_DOCUMENT ? Collections.EMPTY_MAP : getAllNamespaces(lastNode));
+ currentEvent == END_DOCUMENT ? Collections.EMPTY_MAP : getAllNamespaces(node));
}
}
@@ -1075,8 +1090,8 @@ class SwitchingWrapper extends AbstractX
return parser.getEncoding();
} else {
if (currentEvent == START_DOCUMENT) {
- if (lastNode instanceof OMDocument) {
- return ((OMDocument)lastNode).getCharsetEncoding();
+ if (node instanceof OMDocument) {
+ return ((OMDocument)node).getCharsetEncoding();
} else {
return null;
}
@@ -1123,8 +1138,8 @@ class SwitchingWrapper extends AbstractX
return parser.getCharacterEncodingScheme();
} else {
if (currentEvent == START_DOCUMENT) {
- if (lastNode instanceof OMDocument) {
- return ((OMDocument)lastNode).getXMLEncoding();
+ if (node instanceof OMDocument) {
+ return ((OMDocument)node).getXMLEncoding();
} else {
return null;
}
@@ -1144,7 +1159,7 @@ class SwitchingWrapper extends AbstractX
return parser.getPITarget();
} else {
if (currentEvent == PROCESSING_INSTRUCTION) {
- return ((OMProcessingInstruction)lastNode).getTarget();
+ return ((OMProcessingInstruction)node).getTarget();
} else {
throw new IllegalStateException();
}
@@ -1161,7 +1176,7 @@ class SwitchingWrapper extends AbstractX
return parser.getPIData();
} else {
if (currentEvent == PROCESSING_INSTRUCTION) {
- return ((OMProcessingInstruction)lastNode).getValue();
+ return ((OMProcessingInstruction)node).getValue();
} else {
throw new IllegalStateException();
}
@@ -1184,8 +1199,8 @@ class SwitchingWrapper extends AbstractX
return false;
}
} else {
- if (lastNode instanceof OMText) {
- return ((OMText)lastNode).isBinary();
+ if (node instanceof OMText) {
+ return ((OMText)node).isBinary();
} else {
return false;
}
@@ -1200,8 +1215,8 @@ class SwitchingWrapper extends AbstractX
throw new IllegalStateException();
}
} else {
- if (lastNode instanceof OMText) {
- return ((OMText)lastNode).isOptimized();
+ if (node instanceof OMText) {
+ return ((OMText)node).isOptimized();
} else {
throw new IllegalStateException();
}
@@ -1216,7 +1231,7 @@ class SwitchingWrapper extends AbstractX
throw new IllegalStateException();
}
} else {
- if (lastNode instanceof OMText) {
+ if (node instanceof OMText) {
// TODO: we should support deferred building of the DataHandler
return false;
} else {
@@ -1233,8 +1248,8 @@ class SwitchingWrapper extends AbstractX
throw new IllegalStateException();
}
} else {
- if (lastNode instanceof OMText) {
- return ((OMText)lastNode).getContentID();
+ if (node instanceof OMText) {
+ return ((OMText)node).getContentID();
} else {
throw new IllegalStateException();
}
@@ -1249,8 +1264,8 @@ class SwitchingWrapper extends AbstractX
throw new IllegalStateException();
}
} else {
- if (lastNode instanceof OMText) {
- return (DataHandler)((OMText)lastNode).getDataHandler();
+ if (node instanceof OMText) {
+ return (DataHandler)((OMText)node).getDataHandler();
} else {
throw new IllegalStateException();
}
@@ -1284,34 +1299,15 @@ class SwitchingWrapper extends AbstractX
* @return Returns int.
*/
private int generateEvents(OMSerializable node) {
- if (node == null) {
- if (log.isDebugEnabled()) {
- log.debug("Node is null...returning END_DOCUMENT");
- }
- return END_DOCUMENT;
- }
- if (node instanceof OMDocument) {
- return generateContainerEvents((OMDocument)node, true);
- } else {
- int nodeType = ((OMNode)node).getType();
- if (nodeType == OMNode.ELEMENT_NODE) {
- return generateContainerEvents((OMElement)node, false);
+ if (node instanceof OMContainer) {
+ OMContainer container = (OMContainer)node;
+ if (visited) {
+ return container instanceof OMDocument ? END_DOCUMENT : END_ELEMENT;
} else {
- return nodeType;
+ return container instanceof OMDocument ? START_DOCUMENT : START_ELEMENT;
}
- }
- }
-
- private int generateContainerEvents(OMContainer container, boolean isDocument) {
- if (nodeStack == null) {
- nodeStack = new Stack();
- }
- if (!nodeStack.isEmpty() && nodeStack.peek().equals(container)) {
- nodeStack.pop();
- return isDocument ? END_DOCUMENT : END_ELEMENT;
} else {
- nodeStack.push(container);
- return isDocument ? START_DOCUMENT : START_ELEMENT;
+ return ((OMNode)node).getType();
}
}
@@ -1373,7 +1369,7 @@ class SwitchingWrapper extends AbstractX
if (builder != null && builder instanceof StAXBuilder) {
return ((StAXBuilder) builder).isClosed();
} else {
- return _isClosed;
+ return isClosed;
}
}
@@ -1395,7 +1391,7 @@ class SwitchingWrapper extends AbstractX
if (isClosed() && value) {
setParser(null);
}
- _releaseParserOnClose = value;
+ releaseParserOnClose = value;
}
}
@@ -1405,15 +1401,14 @@ class SwitchingWrapper extends AbstractX
*/
public OMDataSource getDataSource() {
if (getEventType() != XMLStreamReader.START_ELEMENT ||
- !(state == NAVIGABLE ||
- state == SWITCH_AT_NEXT)) {
+ state != NAVIGABLE) {
return null;
}
OMDataSource ds = null;
- if (lastNode != null &&
- lastNode instanceof OMSourcedElement) {
+ if (node != null &&
+ node instanceof OMSourcedElement) {
try {
- ds = ((OMSourcedElement) lastNode).getDataSource();
+ ds = ((OMSourcedElement) node).getDataSource();
} catch (UnsupportedOperationException e) {
// Some implementations throw an UnsupportedOperationException.
ds =null;
@@ -1436,6 +1431,6 @@ class SwitchingWrapper extends AbstractX
* @param value boolean
*/
public void enableDataSourceEvents(boolean value) {
- navigator.setDataSourceIsLeaf(value);
+ isDataSourceALeaf = value;
}
}
Modified: webservices/axiom/branches/AXIOM-201/modules/axiom-dom/pom.xml
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/AXIOM-201/modules/axiom-dom/pom.xml?rev=1433134&r1=1433133&r2=1433134&view=diff
==============================================================================
--- webservices/axiom/branches/AXIOM-201/modules/axiom-dom/pom.xml (original)
+++ webservices/axiom/branches/AXIOM-201/modules/axiom-dom/pom.xml Mon Jan 14 21:19:15 2013
@@ -144,31 +144,6 @@
<include>${project.groupId}:axiom-common-impl</include>
</includes>
</artifactSet>
- <relocations>
- <!-- We try to preserve as much as possible the class names from previous releases in
- order to support old code and code that is tightly coupled to the DOOM implementation
- (such as the SAAJ implementation in Axis2). -->
- <relocation>
- <pattern>org.apache.axiom.om.impl.common.OMNamespaceImpl</pattern>
- <shadedPattern>org.apache.axiom.om.impl.dom.NamespaceImpl</shadedPattern>
- </relocation>
- <relocation>
- <pattern>org.apache.axiom.om.impl.common.OMNavigator</pattern>
- <shadedPattern>org.apache.axiom.om.impl.dom.DOMNavigator</shadedPattern>
- </relocation>
- <relocation>
- <pattern>org.apache.axiom.om.impl.common.OMStAXWrapper</pattern>
- <shadedPattern>org.apache.axiom.om.impl.dom.DOMStAXWrapper</shadedPattern>
- </relocation>
- <relocation>
- <pattern>org.apache.axiom.om.impl.common</pattern>
- <shadedPattern>org.apache.axiom.om.impl.dom</shadedPattern>
- </relocation>
- <relocation>
- <pattern>org.apache.axiom.soap.impl.common</pattern>
- <shadedPattern>org.apache.axiom.soap.impl.dom</shadedPattern>
- </relocation>
- </relocations>
<transformers>
<transformer implementation="org.apache.axiom.buildutils.OSGiManifestResourceTransformer" />
</transformers>
@@ -183,27 +158,6 @@
</dependency>
</dependencies>
</plugin>
- <plugin>
- <groupId>org.codehaus.mojo</groupId>
- <artifactId>build-helper-maven-plugin</artifactId>
- <executions>
- <execution>
- <id>attach-original-jar</id>
- <phase>package</phase>
- <goals>
- <goal>attach-artifact</goal>
- </goals>
- <configuration>
- <artifacts>
- <artifact>
- <file>${project.build.directory}/original-${project.build.finalName}.jar</file>
- <classifier>original</classifier>
- </artifact>
- </artifacts>
- </configuration>
- </execution>
- </executions>
- </plugin>
<!-- Attach a JAR with the test classes so that we can reuse them in other modules
(see http://maven.apache.org/guides/mini/guide-attached-tests.html). -->
<plugin>
Modified: webservices/axiom/branches/AXIOM-201/modules/axiom-impl/pom.xml
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/AXIOM-201/modules/axiom-impl/pom.xml?rev=1433134&r1=1433133&r2=1433134&view=diff
==============================================================================
--- webservices/axiom/branches/AXIOM-201/modules/axiom-impl/pom.xml (original)
+++ webservices/axiom/branches/AXIOM-201/modules/axiom-impl/pom.xml Mon Jan 14 21:19:15 2013
@@ -142,16 +142,6 @@
<include>${project.groupId}:axiom-common-impl</include>
</includes>
</artifactSet>
- <relocations>
- <relocation>
- <pattern>org.apache.axiom.om.impl.common</pattern>
- <shadedPattern>org.apache.axiom.om.impl.llom</shadedPattern>
- </relocation>
- <relocation>
- <pattern>org.apache.axiom.soap.impl.common</pattern>
- <shadedPattern>org.apache.axiom.soap.impl.llom</shadedPattern>
- </relocation>
- </relocations>
<transformers>
<transformer implementation="org.apache.axiom.buildutils.OSGiManifestResourceTransformer" />
</transformers>
@@ -166,27 +156,6 @@
</dependency>
</dependencies>
</plugin>
- <plugin>
- <groupId>org.codehaus.mojo</groupId>
- <artifactId>build-helper-maven-plugin</artifactId>
- <executions>
- <execution>
- <id>attach-original-jar</id>
- <phase>package</phase>
- <goals>
- <goal>attach-artifact</goal>
- </goals>
- <configuration>
- <artifacts>
- <artifact>
- <file>${project.build.directory}/original-${project.build.finalName}.jar</file>
- <classifier>original</classifier>
- </artifact>
- </artifacts>
- </configuration>
- </execution>
- </executions>
- </plugin>
<!-- Attach a JAR with the test classes so that we can reuse them in other modules
(see http://maven.apache.org/guides/mini/guide-attached-tests.html). -->
<plugin>
Modified: webservices/axiom/branches/AXIOM-201/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/OMTestSuiteBuilder.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/AXIOM-201/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/OMTestSuiteBuilder.java?rev=1433134&r1=1433133&r2=1433134&view=diff
==============================================================================
--- webservices/axiom/branches/AXIOM-201/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/OMTestSuiteBuilder.java (original)
+++ webservices/axiom/branches/AXIOM-201/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/OMTestSuiteBuilder.java Mon Jan 14 21:19:15 2013
@@ -292,6 +292,7 @@ public class OMTestSuiteBuilder extends
addTest(new org.apache.axiom.ts.om.element.TestGetXMLStreamReaderWithOMSourcedElementDescendant(metaFactory));
}
addTest(new org.apache.axiom.ts.om.element.TestGetXMLStreamReaderWithoutCachingPartiallyBuilt(metaFactory));
+ addTest(new org.apache.axiom.ts.om.element.TestGetXMLStreamReaderWithoutCachingPartiallyBuiltModified(metaFactory));
addTest(new org.apache.axiom.ts.om.element.TestGetXMLStreamReaderWithPreserveNamespaceContext(metaFactory));
addTest(new org.apache.axiom.ts.om.element.TestIsCompleteAfterAddingIncompleteChild(metaFactory));
addTest(new org.apache.axiom.ts.om.element.TestMultipleDefaultNS(metaFactory));
Modified: webservices/axiom/branches/AXIOM-201/pom.xml
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/AXIOM-201/pom.xml?rev=1433134&r1=1433133&r2=1433134&view=diff
==============================================================================
--- webservices/axiom/branches/AXIOM-201/pom.xml (original)
+++ webservices/axiom/branches/AXIOM-201/pom.xml Mon Jan 14 21:19:15 2013
@@ -736,7 +736,6 @@
<module>modules/axiom-api</module>
<module>modules/axiom-testsuite</module>
<module>modules/axiom-common-impl</module>
- <module>modules/axiom-common-impl-testsuite</module>
<module>modules/axiom-impl</module>
<module>modules/axiom-dom</module>
<module>modules/axiom-compat</module>