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 2012/07/07 20:24:12 UTC
svn commit: r1358610 [4/10] - in /webservices/axiom/branches/AXIOM-201: ./
modules/axiom-api/
modules/axiom-api/src/main/java/org/apache/axiom/attachments/
modules/axiom-api/src/main/java/org/apache/axiom/locator/
modules/axiom-api/src/main/java/org/ap...
Modified: webservices/axiom/branches/AXIOM-201/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/DOMTestSuiteBuilder.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/AXIOM-201/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/DOMTestSuiteBuilder.java?rev=1358610&r1=1358609&r2=1358610&view=diff
==============================================================================
--- webservices/axiom/branches/AXIOM-201/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/DOMTestSuiteBuilder.java (original)
+++ webservices/axiom/branches/AXIOM-201/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/DOMTestSuiteBuilder.java Sat Jul 7 18:24:00 2012
@@ -20,6 +20,7 @@ package org.apache.axiom.ts.dom;
import javax.xml.parsers.DocumentBuilderFactory;
+import org.apache.axiom.testutils.conformance.Conformance;
import org.apache.axiom.testutils.suite.TestSuiteBuilder;
public class DOMTestSuiteBuilder extends TestSuiteBuilder {
@@ -30,6 +31,12 @@ public class DOMTestSuiteBuilder extends
}
protected void addTests() {
+ String[] conformanceFiles = Conformance.getConformanceTestFiles();
+ addTest(new org.apache.axiom.ts.dom.attr.TestCloneNode(dbf, true));
+ addTest(new org.apache.axiom.ts.dom.attr.TestCloneNode(dbf, false));
+ addTest(new org.apache.axiom.ts.dom.attr.TestGetChildNodes(dbf));
+ addTest(new org.apache.axiom.ts.dom.attr.TestGetFirstChild(dbf));
+ addTest(new org.apache.axiom.ts.dom.attr.TestGetValueWithMultipleChildren(dbf));
addTest(new org.apache.axiom.ts.dom.attr.TestSetPrefixNotNullWithNamespace(dbf));
addTest(new org.apache.axiom.ts.dom.attr.TestSetPrefixNotNullWithoutNamespace(dbf));
addTest(new org.apache.axiom.ts.dom.builder.TestWhitespaceAroundDocumentElement(dbf));
@@ -38,6 +45,9 @@ public class DOMTestSuiteBuilder extends
addTest(new org.apache.axiom.ts.dom.document.TestAdoptNodeWithParent(dbf));
addTest(new org.apache.axiom.ts.dom.document.TestAllowedChildren(dbf));
addTest(new org.apache.axiom.ts.dom.document.TestAppendChildWrongDocument(dbf));
+ for (int i=0; i<conformanceFiles.length; i++) {
+ addTest(new org.apache.axiom.ts.dom.document.TestCloneNode(dbf, conformanceFiles[i]));
+ }
addTest(new org.apache.axiom.ts.dom.document.TestCreateAttribute(dbf));
addTest(new org.apache.axiom.ts.dom.document.TestCreateAttributeNS(dbf));
addTest(new org.apache.axiom.ts.dom.document.TestCreateAttributeNSWithoutNamespace(dbf));
@@ -56,6 +66,7 @@ public class DOMTestSuiteBuilder extends
addTest(new org.apache.axiom.ts.dom.document.TestTransformerWithStylesheet(dbf, org.apache.xalan.processor.TransformerFactoryImpl.class));
addTest(new org.apache.axiom.ts.dom.document.TestTransformerWithStylesheet(dbf, net.sf.saxon.TransformerFactoryImpl.class));
addTest(new org.apache.axiom.ts.dom.document.TestValidator(dbf));
+ addTest(new org.apache.axiom.ts.dom.documentfragment.TestCloneNode(dbf));
addTest(new org.apache.axiom.ts.dom.element.TestAppendChild(dbf));
addTest(new org.apache.axiom.ts.dom.element.TestAppendChildCyclic(dbf));
addTest(new org.apache.axiom.ts.dom.element.TestAppendChildSelf(dbf));
@@ -65,6 +76,7 @@ public class DOMTestSuiteBuilder extends
addTest(new org.apache.axiom.ts.dom.element.TestAttributes3(dbf));
addTest(new org.apache.axiom.ts.dom.element.TestAttributes4(dbf));
addTest(new org.apache.axiom.ts.dom.element.TestCloneNode(dbf));
+ addTest(new org.apache.axiom.ts.dom.element.TestCloneNodeWithAttributeHavingMultipleChildren(dbf));
addTest(new org.apache.axiom.ts.dom.element.TestCloneNodeWithAttributes(dbf, true));
addTest(new org.apache.axiom.ts.dom.element.TestCloneNodeWithAttributes(dbf, false));
addTest(new org.apache.axiom.ts.dom.element.TestGetElementsByTagName(dbf));
@@ -83,9 +95,11 @@ public class DOMTestSuiteBuilder extends
addTest(new org.apache.axiom.ts.dom.element.TestRemoveSingleChild(dbf));
addTest(new org.apache.axiom.ts.dom.element.TestReplaceChild(dbf));
addTest(new org.apache.axiom.ts.dom.element.TestReplaceChildWrongDocument(dbf));
+ addTest(new org.apache.axiom.ts.dom.element.TestSetAttributeNodeNSInUse(dbf));
addTest(new org.apache.axiom.ts.dom.element.TestSetAttributeNodeNSReplace(dbf));
addTest(new org.apache.axiom.ts.dom.element.TestSetAttributeNodeNSWrongDocument(dbf));
addTest(new org.apache.axiom.ts.dom.element.TestSetAttributeNodeWrongDocument(dbf));
+ addTest(new org.apache.axiom.ts.dom.element.TestSetAttributeNS(dbf));
addTest(new org.apache.axiom.ts.dom.element.TestSetPrefixNotNullWithNamespace(dbf));
addTest(new org.apache.axiom.ts.dom.element.TestSetPrefixNotNullWithoutNamespace(dbf));
addTest(new org.apache.axiom.ts.dom.element.TestSetPrefixNull(dbf));
@@ -93,6 +107,8 @@ public class DOMTestSuiteBuilder extends
addTest(new org.apache.axiom.ts.dom.element.attributes.TestSetNamedItemNSWrongDocument(dbf));
addTest(new org.apache.axiom.ts.dom.element.attributes.TestSetNamedItemWrongDocument(dbf));
addTest(new org.apache.axiom.ts.dom.text.TestAppendData(dbf));
+ addTest(new org.apache.axiom.ts.dom.text.TestGetChildNodes(dbf));
+ addTest(new org.apache.axiom.ts.dom.text.TestGetLength(dbf));
addTest(new org.apache.axiom.ts.dom.text.TestGetWholeText(dbf));
addTest(new org.apache.axiom.ts.dom.text.TestGetWholeTextWithCDATASection(dbf));
addTest(new org.apache.axiom.ts.dom.text.TestGetWholeTextWithComment(dbf));
Modified: webservices/axiom/branches/AXIOM-201/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/document/TestCreateAttributeNS.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/AXIOM-201/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/document/TestCreateAttributeNS.java?rev=1358610&r1=1358609&r2=1358610&view=diff
==============================================================================
--- webservices/axiom/branches/AXIOM-201/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/document/TestCreateAttributeNS.java (original)
+++ webservices/axiom/branches/AXIOM-201/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/document/TestCreateAttributeNS.java Sat Jul 7 18:24:00 2012
@@ -30,19 +30,23 @@ public class TestCreateAttributeNS exten
}
protected void runTest() throws Throwable {
- String attrName = "attrIdentifier";
- String attrValue = "attrValue";
- String attrNs = "http://ws.apache.org/axis2/ns";
- String attrNsPrefix = "axis2";
+ String localName = "attrIdentifier";
+ String uri = "http://ws.apache.org/axis2/ns";
+ String prefix = "axis2";
+ String name = prefix + ":" + localName;
Document doc = dbf.newDocumentBuilder().newDocument();
- Attr attr = doc.createAttributeNS(attrNs, attrNsPrefix + ":" + attrName);
- assertEquals("Attr name mismatch", attrName, attr.getLocalName());
- assertNotNull("Namespace value should not be null", attr.getNamespaceURI());
- assertEquals("NamsspaceURI mismatch", attrNs, attr.getNamespaceURI());
- assertEquals("namespace prefix mismatch", attrNsPrefix, attr.getPrefix());
+ Attr attr = doc.createAttributeNS(uri, name);
+
+ // Check name
+ assertEquals("Attr name mismatch", localName, attr.getLocalName());
+ assertEquals("NamsspaceURI mismatch", uri, attr.getNamespaceURI());
+ assertEquals("namespace prefix mismatch", prefix, attr.getPrefix());
+ assertEquals(name, attr.getName());
- attr.setValue(attrValue);
+ // Check defaults
+ assertNull(attr.getFirstChild());
+ assertEquals("", attr.getValue());
}
}
Modified: webservices/axiom/branches/AXIOM-201/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestCloneNodeWithAttributes.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/AXIOM-201/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestCloneNodeWithAttributes.java?rev=1358610&r1=1358609&r2=1358610&view=diff
==============================================================================
--- webservices/axiom/branches/AXIOM-201/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestCloneNodeWithAttributes.java (original)
+++ webservices/axiom/branches/AXIOM-201/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestCloneNodeWithAttributes.java Sat Jul 7 18:24:00 2012
@@ -44,8 +44,7 @@ public class TestCloneNodeWithAttributes
element.setAttributeNS(null, "attr1", "value1");
element.setAttributeNS("urn:ns2", "q:attr2", "value2");
Element clone = (Element)element.cloneNode(deep);
- // TODO: this doesn't work with DOOM yet
-// assertEquals(2, clone.getAttributes().getLength());
+ assertEquals(2, clone.getAttributes().getLength());
Attr attr1 = clone.getAttributeNodeNS(null, "attr1");
Attr attr2 = clone.getAttributeNodeNS("urn:ns2", "attr2");
assertNotNull(attr1);
Modified: webservices/axiom/branches/AXIOM-201/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/AttrImpl.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/AXIOM-201/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/AttrImpl.java?rev=1358610&r1=1358609&r2=1358610&view=diff
==============================================================================
--- webservices/axiom/branches/AXIOM-201/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/AttrImpl.java (original)
+++ webservices/axiom/branches/AXIOM-201/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/AttrImpl.java Sat Jul 7 18:24:00 2012
@@ -20,31 +20,29 @@
package org.apache.axiom.om.impl.dom;
import org.apache.axiom.om.OMAttribute;
+import org.apache.axiom.om.OMCloneOptions;
import org.apache.axiom.om.OMConstants;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMFactory;
import org.apache.axiom.om.OMNamespace;
+import org.apache.axiom.om.OMXMLParserWrapper;
import org.apache.axiom.om.impl.common.OMNamespaceImpl;
import org.w3c.dom.Attr;
import org.w3c.dom.DOMException;
-import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
+import org.w3c.dom.Text;
import org.w3c.dom.TypeInfo;
import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamWriter;
/** Implementation of <code>org.w3c.dom.Attr</code> and <code>org.apache.axiom.om.OMAttribute</code> */
-public class AttrImpl extends NodeImpl implements OMAttribute, Attr, NamedNode {
+public class AttrImpl extends RootNode implements OMAttribute, Attr, NamedNode {
+ private String localName;
- /** Name of the attribute */
- private String attrName;
-
- /** Attribute value */
- private TextImpl attrValue;
-
- /** Attribute type */
- private String attrType;
+ private String type;
/**
* The namespace of this attribute. Possible values:
@@ -58,10 +56,7 @@ public class AttrImpl extends NodeImpl i
* </ul>
* </ul>
*/
- private OMNamespaceImpl namespace;
-
- /** Flag to indicate whether this attr is used or not */
- private boolean used;
+ private OMNamespace namespace;
/**
* Owner of this attribute. This is either the owner element or the owner document (if the
@@ -72,11 +67,19 @@ public class AttrImpl extends NodeImpl i
/** Flag used to mark an attribute as per the DOM Level 3 specification */
protected boolean isId;
- protected AttrImpl(DocumentImpl ownerDocument, OMFactory factory) {
+ private AttrImpl(DocumentImpl ownerDocument, OMFactory factory) {
super(factory);
owner = ownerDocument;
}
+ // TODO: copy isId?
+ private AttrImpl(String localName, OMNamespace namespace, String type, OMFactory factory) {
+ this(null, factory);
+ this.localName = localName;
+ this.namespace = namespace;
+ this.type = type;
+ }
+
public AttrImpl(DocumentImpl ownerDocument, String localName,
OMNamespace ns, String value, OMFactory factory) {
this(ownerDocument, factory);
@@ -87,37 +90,45 @@ public class AttrImpl extends NodeImpl i
ns = null;
}
}
- this.attrName = localName;
- this.attrValue = new TextImpl(ownerDocument, value, factory);
- this.attrType = OMConstants.XMLATTRTYPE_CDATA;
- this.namespace = (OMNamespaceImpl) ns;
+ this.localName = localName;
+ internalAppendChild(new TextImpl(value, factory));
+ this.type = OMConstants.XMLATTRTYPE_CDATA;
+ this.namespace = ns;
}
public AttrImpl(DocumentImpl ownerDocument, String name, String value,
OMFactory factory) {
this(ownerDocument, factory);
- this.attrName = name;
- this.attrValue = new TextImpl(ownerDocument, value, factory);
- this.attrType = OMConstants.XMLATTRTYPE_CDATA;
+ this.localName = name;
+ internalAppendChild(new TextImpl(value, factory));
+ this.type = OMConstants.XMLATTRTYPE_CDATA;
}
public AttrImpl(DocumentImpl ownerDocument, String name, OMFactory factory) {
this(ownerDocument, factory);
- this.attrName = name;
+ this.localName = name;
//If this is a default namespace attr
if (OMConstants.XMLNS_NS_PREFIX.equals(name)) {
this.namespace = new OMNamespaceImpl(
OMConstants.XMLNS_NS_URI, OMConstants.XMLNS_NS_PREFIX);
}
- this.attrType = OMConstants.XMLATTRTYPE_CDATA;
+ this.type = OMConstants.XMLATTRTYPE_CDATA;
}
public AttrImpl(DocumentImpl ownerDocument, String localName,
OMNamespace namespace, OMFactory factory) {
this(ownerDocument, factory);
- this.attrName = localName;
- this.namespace = (OMNamespaceImpl) namespace;
- this.attrType = OMConstants.XMLATTRTYPE_CDATA;
+ this.localName = localName;
+ this.namespace = namespace;
+ this.type = OMConstants.XMLATTRTYPE_CDATA;
+ }
+
+ final ParentNode internalGetOwnerNode() {
+ return owner;
+ }
+
+ final void internalSetOwnerNode(ParentNode ownerNode) {
+ this.owner = ownerNode;
}
// /
@@ -128,9 +139,9 @@ public class AttrImpl extends NodeImpl i
public String getNodeName() {
return (this.namespace != null
&& !"".equals(this.namespace.getPrefix()) &&
- !(OMConstants.XMLNS_NS_PREFIX.equals(this.attrName)))
- ? this.namespace.getPrefix() + ":" + this.attrName
- : this.attrName;
+ !(OMConstants.XMLNS_NS_PREFIX.equals(this.localName)))
+ ? this.namespace.getPrefix() + ":" + this.localName
+ : this.localName;
}
/**
@@ -148,7 +159,7 @@ public class AttrImpl extends NodeImpl i
* @see org.w3c.dom.Node#getNodeValue()
*/
public String getNodeValue() throws DOMException {
- return (this.attrValue == null) ? "" : this.attrValue.getData();
+ return getValue();
}
/**
@@ -157,7 +168,38 @@ public class AttrImpl extends NodeImpl i
* @see org.w3c.dom.Attr#getValue()
*/
public String getValue() {
- return (this.attrValue == null) ? null : this.attrValue.getText();
+ String value = null;
+ StringBuffer buffer = null;
+ Node child = getFirstChild();
+
+ while (child != null) {
+ String textValue = ((Text)child).getData();
+ if (textValue != null && textValue.length() != 0) {
+ if (value == null) {
+ // This is the first non empty text node. Just save the string.
+ value = textValue;
+ } else {
+ // We've already seen a non empty text node before. Concatenate using
+ // a StringBuffer.
+ if (buffer == null) {
+ // This is the first text node we need to append. Initialize the
+ // StringBuffer.
+ buffer = new StringBuffer(value);
+ }
+ buffer.append(textValue);
+ }
+ }
+ child = child.getNextSibling();
+ }
+
+ if (value == null) {
+ // We didn't see any text nodes. Return an empty string.
+ return "";
+ } else if (buffer != null) {
+ return buffer.toString();
+ } else {
+ return value;
+ }
}
// /
@@ -165,17 +207,17 @@ public class AttrImpl extends NodeImpl i
// /
public String getName() {
if (this.namespace != null) {
- if ((OMConstants.XMLNS_NS_PREFIX.equals(this.attrName))) {
- return this.attrName;
+ if ((OMConstants.XMLNS_NS_PREFIX.equals(this.localName))) {
+ return this.localName;
} else if (OMConstants.XMLNS_NS_URI.equals(this.namespace.getNamespaceURI())) {
- return OMConstants.XMLNS_NS_PREFIX + ":" + this.attrName;
+ return OMConstants.XMLNS_NS_PREFIX + ":" + this.localName;
} else if (this.namespace.getPrefix().equals("")) {
- return this.attrName;
+ return this.localName;
} else {
- return this.namespace.getPrefix() + ":" + this.attrName;
+ return this.namespace.getPrefix() + ":" + this.localName;
}
} else {
- return this.attrName;
+ return this.localName;
}
}
@@ -223,29 +265,19 @@ public class AttrImpl extends NodeImpl i
*/
public QName getQName() {
return (namespace == null) ?
- new QName(this.attrName) :
+ new QName(this.localName) :
new QName(namespace.getNamespaceURI(),
- attrName,
+ localName,
namespace.getPrefix());
}
- /**
- * Returns the attribute value.
- *
- * @see org.apache.axiom.om.OMAttribute#getAttributeValue()
- */
public String getAttributeValue() {
- return this.attrValue.getText();
+ return getValue();
}
- /**
- * Returns the attribute value.
- *
- * @see org.apache.axiom.om.OMAttribute#getAttributeType()
- */
public String getAttributeType() {
- return this.attrType;
+ return type;
}
/**
@@ -254,11 +286,11 @@ public class AttrImpl extends NodeImpl i
* @see org.apache.axiom.om.OMAttribute#setLocalName(String)
*/
public void setLocalName(String localName) {
- this.attrName = localName;
+ this.localName = localName;
}
public void internalSetNamespace(OMNamespace namespace) {
- this.namespace = (OMNamespaceImpl)namespace;
+ this.namespace = namespace;
}
/**
@@ -276,8 +308,7 @@ public class AttrImpl extends NodeImpl i
* @see org.apache.axiom.om.OMAttribute#setAttributeValue(String)
*/
public void setAttributeValue(String value) {
- this.attrValue = (TextImpl) this.getOwnerDocument().createTextNode(
- value);
+ setValue(value);
}
/**
@@ -286,17 +317,16 @@ public class AttrImpl extends NodeImpl i
* @see org.apache.axiom.om.OMAttribute#setAttributeType(String)
*/
public void setAttributeType(String attrType) {
- this.attrType = attrType;
- }
-
- /** @return Returns boolean. */
- protected boolean isUsed() {
- return used;
+ this.type = attrType;
}
- /** @param used The used to set. */
- protected void setUsed(boolean used) {
- this.used = used;
+ final void checkInUse() {
+ if (owner instanceof ElementImpl) {
+ String msg = DOMMessageFormatter.formatMessage(
+ DOMMessageFormatter.DOM_DOMAIN, DOMException.INUSE_ATTRIBUTE_ERR,
+ null);
+ throw new DOMException(DOMException.INUSE_ATTRIBUTE_ERR, msg);
+ }
}
/**
@@ -305,8 +335,11 @@ public class AttrImpl extends NodeImpl i
* @see org.w3c.dom.Attr#setValue(String)
*/
public void setValue(String value) throws DOMException {
- this.attrValue = (TextImpl) this.getOwnerDocument().createTextNode(
- value);
+ Node child;
+ while ((child = getFirstChild()) != null) {
+ removeChild(child);
+ }
+ internalAppendChild((TextImpl)getOwnerDocument().createTextNode(value));
}
public Node getParentNode() {
@@ -314,15 +347,8 @@ public class AttrImpl extends NodeImpl i
return null;
}
- /**
- * Returns the attribute name.
- *
- * @see org.w3c.dom.Node#getLocalName()
- */
public String getLocalName() {
- return (this.namespace == null) ? this.attrName : DOMUtil
- .getLocalName(this.attrName);
-
+ return localName;
}
/**
@@ -348,25 +374,6 @@ public class AttrImpl extends NodeImpl i
NamedNodeHelper.setPrefix(this, prefix);
}
- public Node cloneNode(boolean deep) {
-
- AttrImpl clone = (AttrImpl) super.cloneNode(deep);
-
- if (clone.attrValue == null) {
- // Need to break the association w/ original kids
- clone.attrValue = new TextImpl(this.attrValue.toString(), factory);
- if (this.attrValue.nextSibling != null) {
- throw new UnsupportedOperationException(
- "Attribute value can contain only a text " +
- "node with out any siblings");
- }
- }
- clone.isSpecified(true);
- clone.owner = (DocumentImpl)getOwnerDocument();
- clone.setUsed(false);
- return clone;
- }
-
/*
* DOM-Level 3 methods
*/
@@ -380,21 +387,11 @@ public class AttrImpl extends NodeImpl i
}
public String toString() {
- return (this.namespace == null) ? this.attrName : this.namespace
+ return (this.namespace == null) ? this.localName : this.namespace
.getPrefix()
- + ":" + this.attrName;
- }
-
- public Document getOwnerDocument() {
- return owner instanceof ElementImpl ? ((ElementImpl)owner).getOwnerDocument() : (DocumentImpl)owner;
+ + ":" + this.localName;
}
- /**
- * Returns the owner element of this attribute
- * @return OMElement - if the parent OMContainer is an instanceof OMElement
- * we return that OMElement else return null. To get the OMContainer itself use
- * getParent() method.
- */
public OMElement getOwner() {
return owner instanceof ElementImpl ? (OMElement)owner : null;
}
@@ -421,11 +418,12 @@ public class AttrImpl extends NodeImpl i
* @return True if the two objects are equal or else false. The equality is checked as explained above.
*/
public boolean equals(Object obj) {
+ String attrValue = getValue();
if (obj instanceof OMAttribute) { // Checks equality of an OMAttributeImpl or an AttrImpl with this instance
OMAttribute other = (OMAttribute) obj;
return (namespace == null ? other.getNamespace() == null :
namespace.equals(other.getNamespace()) &&
- attrName.equals(other.getLocalName()) &&
+ localName.equals(other.getLocalName()) &&
(attrValue == null ? other.getAttributeValue() == null :
attrValue.toString().equals(other.getAttributeValue())));
} else if (obj instanceof Attr) {// Checks equality of an org.w3c.dom.Attr with this instance
@@ -436,7 +434,7 @@ public class AttrImpl extends NodeImpl i
return false; // I don't have a namespace and the other has. So return false
} else {
// Both of us don't have namespaces. So check for name and value equality only
- return (attrName.equals(other.getLocalName()) &&
+ return (localName.equals(other.getLocalName()) &&
(attrValue == null ? other.getValue() == null :
attrValue.toString().equals(other.getValue())));
}
@@ -447,7 +445,7 @@ public class AttrImpl extends NodeImpl i
// First check for namespaceURI equality. Then check for prefix equality.
// Then check for name and value equality
return (ns.equals(otherNs) && (prefix == null ? otherPrefix == null : prefix.equals(otherPrefix)) &&
- (attrName.equals(other.getLocalName())) &&
+ (localName.equals(other.getLocalName())) &&
(attrValue == null ? other.getValue() == null :
attrValue.toString().equals(other.getValue())));
}
@@ -456,8 +454,31 @@ public class AttrImpl extends NodeImpl i
}
public int hashCode() {
- return attrName.hashCode() ^ (attrValue != null ? attrValue.toString().hashCode() : 0) ^
+ String attrValue = getValue();
+ return localName.hashCode() ^ (attrValue != null ? attrValue.toString().hashCode() : 0) ^
(namespace != null ? namespace.hashCode() : 0);
}
+ public void internalSerialize(XMLStreamWriter writer, boolean cache) throws XMLStreamException {
+ throw new UnsupportedOperationException();
+ }
+
+ ParentNode shallowClone(OMCloneOptions options, ParentNode targetParent, boolean namespaceRepairing) {
+ // Note: targetParent is always null here
+ return new AttrImpl(localName, namespace, type, factory);
+ }
+
+ public final OMXMLParserWrapper getBuilder() {
+ return null;
+ }
+
+ public final boolean isComplete() {
+ return true;
+ }
+
+ public final void setComplete(boolean state) {
+ if (state != true) {
+ throw new IllegalStateException();
+ }
+ }
}
Modified: webservices/axiom/branches/AXIOM-201/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/AttributeMap.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/AXIOM-201/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/AttributeMap.java?rev=1358610&r1=1358609&r2=1358610&view=diff
==============================================================================
--- webservices/axiom/branches/AXIOM-201/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/AttributeMap.java (original)
+++ webservices/axiom/branches/AXIOM-201/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/AttributeMap.java Sat Jul 7 18:24:00 2012
@@ -19,6 +19,7 @@
package org.apache.axiom.om.impl.dom;
+import org.apache.axiom.om.OMCloneOptions;
import org.w3c.dom.DOMException;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
@@ -31,16 +32,6 @@ public class AttributeMap implements Nam
private ElementImpl ownerNode;
- //
- // Data
- //
-
- private short flags;
-
- private final static short CHANGED = 0x1 << 1;
-
- private final static short HASDEFAULTS = 0x1 << 2;
-
AttributeMap(ElementImpl ownerNode) {
this.ownerNode = ownerNode;
}
@@ -141,7 +132,6 @@ public class AttributeMap implements Nam
}
attr.setOwnerElement((ElementImpl)this.ownerNode, true); // Set the owner node
- attr.setUsed(true); // Setting used to true
int i = findNamePoint(attr.getNodeName(), 0);
@@ -226,20 +216,7 @@ public class AttributeMap implements Nam
return previous;
}
- /**
- * BORROWED from Xerces impl. Cloning a NamedNodeMap is a DEEP OPERATION; it always clones all
- * the nodes contained in the map.
- */
-
- public AttributeMap cloneMap(ElementImpl ownerNode) {
- AttributeMap newmap = new AttributeMap(ownerNode);
- newmap.hasDefaults(hasDefaults());
- newmap.cloneContent(this);
- return newmap;
- } // cloneMap():AttributeMap
-
- /** BORROWED from Xerces impl. */
- protected void cloneContent(AttributeMap srcmap) {
+ void cloneContent(OMCloneOptions options, AttributeMap srcmap) {
Vector srcnodes = srcmap.nodes;
if (srcnodes != null) {
int size = srcnodes.size();
@@ -250,30 +227,13 @@ public class AttributeMap implements Nam
nodes.setSize(size);
for (int i = 0; i < size; ++i) {
AttrImpl n = (AttrImpl) srcnodes.elementAt(i);
- AttrImpl clone = (AttrImpl) n.cloneNode(true);
+ AttrImpl clone = (AttrImpl)n.clone(options, null, true, false);
clone.isSpecified(n.isSpecified());
nodes.setElementAt(clone, i);
clone.setOwnerElement(ownerNode, true);
}
}
}
- } // cloneContent():AttributeMap
-
-
- final boolean changed() {
- return (flags & CHANGED) != 0;
- }
-
- final void changed(boolean value) {
- flags = (short) (value ? flags | CHANGED : flags & ~CHANGED);
- }
-
- final boolean hasDefaults() {
- return (flags & HASDEFAULTS) != 0;
- }
-
- final void hasDefaults(boolean value) {
- flags = (short) (value ? flags | HASDEFAULTS : flags & ~HASDEFAULTS);
}
/**
Modified: webservices/axiom/branches/AXIOM-201/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/CDATASectionImpl.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/AXIOM-201/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/CDATASectionImpl.java?rev=1358610&r1=1358609&r2=1358610&view=diff
==============================================================================
--- webservices/axiom/branches/AXIOM-201/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/CDATASectionImpl.java (original)
+++ webservices/axiom/branches/AXIOM-201/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/CDATASectionImpl.java Sat Jul 7 18:24:00 2012
@@ -23,30 +23,17 @@ import org.apache.axiom.om.OMException;
import org.apache.axiom.om.OMFactory;
import org.apache.axiom.om.OMNode;
import org.w3c.dom.CDATASection;
-import org.w3c.dom.Node;
public class CDATASectionImpl extends TextNodeImpl implements CDATASection {
public CDATASectionImpl(String text, OMFactory factory) {
super(text, factory);
}
- public CDATASectionImpl(DocumentImpl ownerDocument, String text, OMFactory factory) {
- super(ownerDocument, text, factory);
- }
-
public int getType() throws OMException {
return OMNode.CDATA_SECTION_NODE;
}
- public void setType(int nodeType) throws OMException {
- if (nodeType != OMNode.CDATA_SECTION_NODE) {
- throw new UnsupportedOperationException();
- }
- }
-
- public Node cloneNode(boolean deep) {
- CDATASectionImpl textImpl = new CDATASectionImpl(this.textValue, this.factory);
- textImpl.setOwnerDocument(ownerDocument());
- return textImpl;
+ LeafNode createClone() {
+ return new CDATASectionImpl(textValue, factory);
}
}
Modified: webservices/axiom/branches/AXIOM-201/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/CharacterImpl.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/AXIOM-201/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/CharacterImpl.java?rev=1358610&r1=1358609&r2=1358610&view=diff
==============================================================================
--- webservices/axiom/branches/AXIOM-201/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/CharacterImpl.java (original)
+++ webservices/axiom/branches/AXIOM-201/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/CharacterImpl.java Sat Jul 7 18:24:00 2012
@@ -28,7 +28,7 @@ import org.w3c.dom.DOMException;
* This implements the OMText operations which are to be inherited by TextImpl, CommentImpl,
* CDATASectionImpl.
*/
-public abstract class CharacterImpl extends ChildNode implements CharacterData, OMNodeEx {
+public abstract class CharacterImpl extends LeafNode implements CharacterData, OMNodeEx {
protected String textValue;
@@ -36,13 +36,8 @@ public abstract class CharacterImpl exte
super(factory);
}
- /** @param ownerNode */
- public CharacterImpl(DocumentImpl ownerNode, OMFactory factory) {
- super(ownerNode, factory);
- }
-
- public CharacterImpl(DocumentImpl ownerNode, String value, OMFactory factory) {
- super(ownerNode, factory);
+ public CharacterImpl(String value, OMFactory factory) {
+ super(factory);
this.textValue = (value != null) ? value : "";
}
Modified: webservices/axiom/branches/AXIOM-201/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/CommentImpl.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/AXIOM-201/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/CommentImpl.java?rev=1358610&r1=1358609&r2=1358610&view=diff
==============================================================================
--- webservices/axiom/branches/AXIOM-201/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/CommentImpl.java (original)
+++ webservices/axiom/branches/AXIOM-201/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/CommentImpl.java Sat Jul 7 18:24:00 2012
@@ -20,7 +20,6 @@
package org.apache.axiom.om.impl.dom;
import org.apache.axiom.om.OMComment;
-import org.apache.axiom.om.OMException;
import org.apache.axiom.om.OMFactory;
import org.apache.axiom.om.OMNode;
import org.w3c.dom.Comment;
@@ -30,15 +29,8 @@ import javax.xml.stream.XMLStreamExcepti
import javax.xml.stream.XMLStreamWriter;
public class CommentImpl extends CharacterImpl implements Comment, OMComment {
-
- public CommentImpl(DocumentImpl ownerNode, OMFactory factory) {
- super(ownerNode, factory);
- this.done = true;
- }
-
- public CommentImpl(DocumentImpl ownerNode, String value, OMFactory factory) {
- super(ownerNode, value, factory);
- this.done = true;
+ public CommentImpl(String value, OMFactory factory) {
+ super(value, factory);
}
public String getNodeName() {
@@ -61,12 +53,11 @@ public class CommentImpl extends Charact
return OMNode.COMMENT_NODE;
}
- public void setType(int nodeType) throws OMException {
- throw new UnsupportedOperationException(
- "You should not set the node type of a comment");
- }
-
public void internalSerialize(XMLStreamWriter writer, boolean cache) throws XMLStreamException {
writer.writeComment(this.textValue);
}
+
+ LeafNode createClone() {
+ return new CommentImpl(getData(), factory);
+ }
}
Modified: webservices/axiom/branches/AXIOM-201/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DOMImplementationImpl.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/AXIOM-201/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DOMImplementationImpl.java?rev=1358610&r1=1358609&r2=1358610&view=diff
==============================================================================
--- webservices/axiom/branches/AXIOM-201/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DOMImplementationImpl.java (original)
+++ webservices/axiom/branches/AXIOM-201/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DOMImplementationImpl.java Sat Jul 7 18:24:00 2012
@@ -48,7 +48,7 @@ public class DOMImplementationImpl imple
new ElementImpl(doc, DOMUtil.getLocalName(qualifiedName),
new OMNamespaceImpl(namespaceURI, DOMUtil
- .getPrefix(qualifiedName)), factory);
+ .getPrefix(qualifiedName)), null, factory, false);
return doc;
}
Modified: webservices/axiom/branches/AXIOM-201/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DocumentFragmentImpl.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/AXIOM-201/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DocumentFragmentImpl.java?rev=1358610&r1=1358609&r2=1358610&view=diff
==============================================================================
--- webservices/axiom/branches/AXIOM-201/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DocumentFragmentImpl.java (original)
+++ webservices/axiom/branches/AXIOM-201/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DocumentFragmentImpl.java Sat Jul 7 18:24:00 2012
@@ -19,21 +19,32 @@
package org.apache.axiom.om.impl.dom;
-import org.apache.axiom.om.OMException;
+import org.apache.axiom.om.OMCloneOptions;
import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.OMXMLParserWrapper;
+import org.apache.axiom.om.impl.OMContainerEx;
import org.w3c.dom.DocumentFragment;
import org.w3c.dom.Node;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;
-public class DocumentFragmentImpl extends ParentNode implements
- DocumentFragment {
+public class DocumentFragmentImpl extends RootNode implements
+ DocumentFragment, OMContainerEx {
+ private ParentNode ownerNode;
+
/** @param ownerDocument */
- public DocumentFragmentImpl(DocumentImpl ownerDocument, OMFactory factory) {
- super(ownerDocument, factory);
- this.done = true;
+ public DocumentFragmentImpl(OMFactory factory) {
+ super(factory);
+ }
+
+ final ParentNode internalGetOwnerNode() {
+ return ownerNode;
+ }
+
+ final void internalSetOwnerNode(ParentNode ownerNode) {
+ this.ownerNode = ownerNode;
}
/*
@@ -54,24 +65,6 @@ public class DocumentFragmentImpl extend
return "#document-fragment";
}
- /*
- * (non-Javadoc)
- *
- * @see org.apache.axiom.om.OMNode#getType()
- */
- public int getType() throws OMException {
- return -1;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.apache.axiom.om.OMNode#setType(int)
- */
- public void setType(int nodeType) throws OMException {
- // DO Nothing :-?
- }
-
public void internalSerialize(XMLStreamWriter writer, boolean cache) throws XMLStreamException {
// TODO
throw new UnsupportedOperationException("TODO");
@@ -88,4 +81,21 @@ public class DocumentFragmentImpl extend
throw new UnsupportedOperationException("TODO");
}
+ ParentNode shallowClone(OMCloneOptions options, ParentNode targetParent, boolean namespaceRepairing) {
+ return new DocumentFragmentImpl(factory);
+ }
+
+ public final OMXMLParserWrapper getBuilder() {
+ return null;
+ }
+
+ public final boolean isComplete() {
+ return true;
+ }
+
+ public final void setComplete(boolean state) {
+ if (state != true) {
+ throw new IllegalStateException();
+ }
+ }
}
Modified: webservices/axiom/branches/AXIOM-201/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DocumentImpl.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/AXIOM-201/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DocumentImpl.java?rev=1358610&r1=1358609&r2=1358610&view=diff
==============================================================================
--- webservices/axiom/branches/AXIOM-201/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DocumentImpl.java (original)
+++ webservices/axiom/branches/AXIOM-201/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DocumentImpl.java Sat Jul 7 18:24:00 2012
@@ -19,11 +19,10 @@
package org.apache.axiom.om.impl.dom;
+import org.apache.axiom.om.OMCloneOptions;
import org.apache.axiom.om.OMConstants;
-import org.apache.axiom.om.OMContainer;
import org.apache.axiom.om.OMDocument;
import org.apache.axiom.om.OMElement;
-import org.apache.axiom.om.OMException;
import org.apache.axiom.om.OMFactory;
import org.apache.axiom.om.OMNamespace;
import org.apache.axiom.om.OMNode;
@@ -31,6 +30,7 @@ import org.apache.axiom.om.OMOutputForma
import org.apache.axiom.om.OMXMLParserWrapper;
import org.apache.axiom.om.dom.DOMMetaFactory;
import org.apache.axiom.om.impl.MTOMXMLStreamWriter;
+import org.apache.axiom.om.impl.OMContainerEx;
import org.apache.axiom.om.impl.OMNodeEx;
import org.apache.axiom.om.impl.common.OMDocumentImplUtil;
import org.apache.axiom.om.impl.common.OMNamespaceImpl;
@@ -59,7 +59,10 @@ import java.util.Hashtable;
import java.util.Iterator;
import java.util.Vector;
-public class DocumentImpl extends ParentNode implements Document, OMDocument {
+public class DocumentImpl extends RootNode implements Document, OMDocument, OMContainerEx {
+ protected OMXMLParserWrapper builder;
+
+ protected boolean done;
private String xmlVersion;
@@ -75,12 +78,6 @@ public class DocumentImpl extends Parent
private final DOMConfigurationImpl domConfig = new DOMConfigurationImpl();
- /** @param ownerDocument */
- public DocumentImpl(DocumentImpl ownerDocument, OMFactory factory) {
- super(ownerDocument, factory);
- this.done = true;
- }
-
public DocumentImpl(OMXMLParserWrapper parserWrapper, OMFactory factory) {
super(factory);
this.builder = parserWrapper;
@@ -91,10 +88,15 @@ public class DocumentImpl extends Parent
this.done = true;
}
- DocumentImpl ownerDocument() {
+ ParentNode internalGetOwnerNode() {
return this;
}
+ void internalSetOwnerNode(ParentNode ownerNode) {
+ // The owner node of a document node cannot be set
+ throw new UnsupportedOperationException();
+ }
+
public Document getOwnerDocument() {
return null;
}
@@ -104,59 +106,11 @@ public class DocumentImpl extends Parent
return super.clone();
}
- // /
- // /OMNode methods
- // //
- public void setType(int nodeType) throws OMException {
- throw new UnsupportedOperationException(
- "In OM Document object doesn't have a type");
- }
-
- public int getType() throws OMException {
- throw new UnsupportedOperationException(
- "In OM Document object doesn't have a type");
- }
-
public void internalSerialize(XMLStreamWriter writer, boolean cache) throws XMLStreamException {
internalSerialize(writer, cache, !((MTOMXMLStreamWriter) writer).isIgnoreXMLDeclaration());
}
// /
- // /Overrides ChildNode specific methods.
- // /
- public OMNode getNextOMSibling() throws OMException {
- return null;
- }
-
- public Node getNextSibling() {
- return null;
- }
-
- public OMContainer getParent() throws OMException {
- throw new UnsupportedOperationException("This is the document node");
- }
-
- public OMNode getPreviousOMSibling() {
- throw new UnsupportedOperationException("This is the document node");
- }
-
- public Node getPreviousSibling() {
- return null;
- }
-
- public void setNextOMSibling(OMNode node) {
- throw new UnsupportedOperationException("This is the document node");
- }
-
- public void setParent(OMContainer element) {
- throw new UnsupportedOperationException("This is the document node");
- }
-
- public void setPreviousOMSibling(OMNode node) {
- throw new UnsupportedOperationException("This is the document node");
- }
-
- // /
// /org.w3c.dom.Node methods
// /
public String getNodeName() {
@@ -201,19 +155,27 @@ public class DocumentImpl extends Parent
}
public CDATASection createCDATASection(String data) throws DOMException {
- return new CDATASectionImpl(this, data, factory);
+ CDATASectionImpl cdataSection = new CDATASectionImpl(data, factory);
+ cdataSection.setOwnerDocument(this);
+ return cdataSection;
}
public Comment createComment(String data) {
- return new CommentImpl(this, data, this.factory);
+ CommentImpl comment = new CommentImpl(data, this.factory);
+ comment.setOwnerDocument(this);
+ return comment;
}
public DocumentFragment createDocumentFragment() {
- return new DocumentFragmentImpl(this, this.factory);
+ DocumentFragmentImpl fragment = new DocumentFragmentImpl(this.factory);
+ fragment.setOwnerDocument(this);
+ return fragment;
}
public Element createElement(String tagName) throws DOMException {
- return new ElementImpl(this, tagName, this.factory);
+ ElementImpl element = new ElementImpl(null, tagName, null, null, this.factory, false);
+ element.setOwnerDocument(this);
+ return element;
}
public Element createElementNS(String ns, String qualifiedName)
@@ -235,10 +197,8 @@ public class DocumentImpl extends Parent
} else {
namespace = new OMNamespaceImpl(ns, prefix);
}
- // DOM doesn't create namespace declarations automatically. Therefore we set the
- // namespace afterwards with setNamespaceWithNoFindInCurrentScope.
- ElementImpl element = new ElementImpl(this, localName, null, this.factory);
- element.setNamespaceWithNoFindInCurrentScope(namespace);
+ ElementImpl element = new ElementImpl(null, localName, namespace, null, this.factory, false);
+ element.setOwnerDocument(this);
return element;
}
@@ -250,11 +210,15 @@ public class DocumentImpl extends Parent
public ProcessingInstruction createProcessingInstruction(String target,
String data) throws DOMException {
- return new ProcessingInstructionImpl(this, target, data, factory);
+ ProcessingInstructionImpl pi = new ProcessingInstructionImpl(target, data, factory);
+ pi.setOwnerDocument(this);
+ return pi;
}
public Text createTextNode(String value) {
- return new TextImpl(this, value, this.factory);
+ TextImpl text = new TextImpl(value, this.factory);
+ text.setOwnerDocument(this);
+ return text;
}
public DocumentType getDoctype() {
@@ -543,8 +507,8 @@ public class DocumentImpl extends Parent
}
public Node adoptNode(Node node) throws DOMException {
- if (node instanceof ChildNode) {
- ChildNode childNode = (ChildNode)node;
+ if (node instanceof NodeImpl) {
+ NodeImpl childNode = (NodeImpl)node;
if (childNode.hasParent()) {
childNode.detach();
}
@@ -623,4 +587,25 @@ public class DocumentImpl extends Parent
boolean includeXMLDeclaration) throws XMLStreamException {
OMDocumentImplUtil.internalSerialize(this, writer, cache, includeXMLDeclaration);
}
+
+ ParentNode shallowClone(OMCloneOptions options, ParentNode targetParent, boolean namespaceRepairing) {
+ DocumentImpl clone = new DocumentImpl(factory);
+ clone.xmlVersion = xmlVersion;
+ clone.xmlEncoding = xmlEncoding;
+ clone.xmlStandalone = xmlStandalone;
+ clone.charEncoding = charEncoding;
+ return clone;
+ }
+
+ public final OMXMLParserWrapper getBuilder() {
+ return builder;
+ }
+
+ public final boolean isComplete() {
+ return done;
+ }
+
+ public final void setComplete(boolean state) {
+ done = state;
+ }
}
Modified: webservices/axiom/branches/AXIOM-201/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DocumentTypeImpl.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/AXIOM-201/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DocumentTypeImpl.java?rev=1358610&r1=1358609&r2=1358610&view=diff
==============================================================================
--- webservices/axiom/branches/AXIOM-201/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DocumentTypeImpl.java (original)
+++ webservices/axiom/branches/AXIOM-201/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DocumentTypeImpl.java Sat Jul 7 18:24:00 2012
@@ -23,18 +23,16 @@ import javax.xml.stream.XMLStreamExcepti
import javax.xml.stream.XMLStreamWriter;
import org.apache.axiom.om.OMDocType;
-import org.apache.axiom.om.OMException;
import org.apache.axiom.om.OMFactory;
import org.apache.axiom.om.impl.OMNodeEx;
import org.w3c.dom.DocumentType;
import org.w3c.dom.NamedNodeMap;
-public class DocumentTypeImpl extends ChildNode implements DocumentType, OMDocType, OMNodeEx {
+public class DocumentTypeImpl extends LeafNode implements DocumentType, OMDocType, OMNodeEx {
private String value;
- public DocumentTypeImpl(DocumentImpl ownerDocument, OMFactory factory) {
- super(ownerDocument, factory);
- done = true;
+ public DocumentTypeImpl(OMFactory factory) {
+ super(factory);
}
public String getNodeName() {
@@ -49,10 +47,6 @@ public class DocumentTypeImpl extends Ch
throw new UnsupportedOperationException();
}
- public void setType(int nodeType) throws OMException {
- throw new UnsupportedOperationException();
- }
-
public int getType() {
return DTD_NODE;
}
@@ -89,4 +83,10 @@ public class DocumentTypeImpl extends Ch
public void setValue(String text) {
value = text;
}
+
+ LeafNode createClone() {
+ DocumentTypeImpl clone = new DocumentTypeImpl(factory);
+ clone.setValue(value);
+ return clone;
+ }
}
Modified: webservices/axiom/branches/AXIOM-201/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ElementImpl.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/AXIOM-201/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ElementImpl.java?rev=1358610&r1=1358609&r2=1358610&view=diff
==============================================================================
--- webservices/axiom/branches/AXIOM-201/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ElementImpl.java (original)
+++ webservices/axiom/branches/AXIOM-201/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ElementImpl.java Sat Jul 7 18:24:00 2012
@@ -20,6 +20,7 @@
package org.apache.axiom.om.impl.dom;
import org.apache.axiom.om.OMAttribute;
+import org.apache.axiom.om.OMCloneOptions;
import org.apache.axiom.om.OMConstants;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMException;
@@ -49,7 +50,6 @@ import org.w3c.dom.TypeInfo;
import javax.xml.namespace.NamespaceContext;
import javax.xml.namespace.QName;
-import javax.xml.stream.XMLStreamConstants;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;
import java.io.ByteArrayOutputStream;
@@ -66,6 +66,16 @@ public class ElementImpl extends ParentN
private static final Log log = LogFactory.getLog(ElementImpl.class);
+ protected OMXMLParserWrapper builder;
+
+ protected boolean done;
+
+ private ParentNode ownerNode;
+
+ private NodeImpl previousSibling;
+
+ private NodeImpl nextSibling;
+
private int lineNumber;
/**
@@ -94,79 +104,41 @@ public class ElementImpl extends ParentN
private static final OMNamespace XMLNS_NAMESPACE_WITHOUT_PREFIX = new OMNamespaceImpl(OMConstants.XMLNS_NS_URI, null);
- /** @param ownerDocument ownerDocument
- * @param tagName tagName
- * @param factory OMFactory
- *
- * */
- public ElementImpl(DocumentImpl ownerDocument, String tagName,
- OMFactory factory) {
- super(ownerDocument, factory);
- this.localName = tagName;
- this.attributes = new AttributeMap(this);
- this.done = true;
- }
-
- /**
- * Creates a new element with the namespace.
- *
- * @param ownerDocument
- * @param tagName
- * @param ns
- * @param factory
- */
- public ElementImpl(DocumentImpl ownerDocument, String tagName,
- OMNamespaceImpl ns, OMFactory factory) {
- super(ownerDocument, factory);
- this.localName = tagName;
- if (ns != null) {
- setNamespace(ns);
+ public ElementImpl(ParentNode parentNode, String localName, OMNamespace ns, OMXMLParserWrapper builder,
+ OMFactory factory, boolean generateNSDecl) {
+ super(factory);
+ this.localName = localName;
+ this.builder = builder;
+ this.done = builder == null;
+ if (parentNode != null) {
+ parentNode.addChild(this, builder != null);
}
this.attributes = new AttributeMap(this);
- this.done = true;
+ namespace = generateNSDecl ? handleNamespace(ns) : ns;
}
- public ElementImpl(DocumentImpl ownerDocument, String tagName,
- OMNamespaceImpl ns, OMXMLParserWrapper builder, OMFactory factory) {
- super(ownerDocument, factory);
- this.localName = tagName;
- if (ns != null) {
- setNamespace(ns);
- }
- this.builder = builder;
- this.attributes = new AttributeMap(this);
+ final ParentNode internalGetOwnerNode() {
+ return ownerNode;
}
- public ElementImpl(ParentNode parentNode, String tagName, OMNamespaceImpl ns,
- OMFactory factory) {
- this(null, tagName, null, factory);
- parentNode.addChild(this);
- this.done = true;
- namespace = handleNamespace(ns);
+ final void internalSetOwnerNode(ParentNode ownerNode) {
+ this.ownerNode = ownerNode;
}
- public ElementImpl(ParentNode parentNode, String tagName, OMNamespaceImpl ns,
- OMXMLParserWrapper builder, OMFactory factory) {
- this(tagName, ns, builder, factory);
- if (parentNode != null) {
- parentNode.addChild(this);
- }
-
+ final NodeImpl internalGetPreviousSibling() {
+ return previousSibling;
}
-
- public ElementImpl(String tagName, OMNamespaceImpl ns,
- OMXMLParserWrapper builder, OMFactory factory) {
- this(factory);
- this.localName = tagName;
- if (ns != null) {
- setNamespace(ns);
- }
- this.builder = builder;
- this.attributes = new AttributeMap(this);
+
+ final NodeImpl internalGetNextSibling() {
+ return nextSibling;
}
-
- public ElementImpl(OMFactory factory) {
- super(factory);
+
+ final void internalSetPreviousSibling(NodeImpl previousSibling) {
+ this.previousSibling = previousSibling;
+ }
+
+ final void internalSetNextSibling(NodeImpl nextSibling) {
+ this.nextSibling = nextSibling;
}
private OMNamespace handleNamespace(OMNamespace ns) {
@@ -185,7 +157,7 @@ public class ElementImpl extends ParentN
return null;
} else {
OMNamespace namespace = findNamespace(namespaceURI, prefix);
- if (namespace == null) {
+ if (namespace == null || (prefix != null && !namespace.getPrefix().equals(prefix))) {
namespace = declareNamespace(ns);
}
return namespace;
@@ -265,16 +237,6 @@ public class ElementImpl extends ParentN
return OMNode.ELEMENT_NODE;
}
- /*
- * (non-Javadoc)
- *
- * @see org.apache.axiom.om.OMNode#setType(int)
- */
- public void setType(int nodeType) throws OMException {
- // Do nothing ...
- // This is an Eement Node...
- }
-
// /
// / org.w3c.dom.Element methods
// /
@@ -431,12 +393,7 @@ public class ElementImpl extends ParentN
checkSameOwnerDocument(attr);
// check whether the attr is in use
- if (attrImpl.isUsed()) {
- String msg = DOMMessageFormatter
- .formatMessage(DOMMessageFormatter.DOM_DOMAIN,
- DOMException.INUSE_ATTRIBUTE_ERR, null);
- throw new DOMException(DOMException.INUSE_ATTRIBUTE_ERR, msg);
- }
+ attrImpl.checkInUse();
if (attr.getNodeName().startsWith(OMConstants.XMLNS_NS_PREFIX + ":")) {
// This is a ns declaration
@@ -504,19 +461,14 @@ public class ElementImpl extends ParentN
}
// check whether the attr is in use
- if (attrImpl.isUsed()) {
- String msg = DOMMessageFormatter.formatMessage(
- DOMMessageFormatter.DOM_DOMAIN, DOMException.INUSE_ATTRIBUTE_ERR,
- null);
- throw new DOMException(DOMException.INUSE_ATTRIBUTE_ERR, msg);
- }
+ attrImpl.checkInUse();
if (this.attributes == null) {
this.attributes = new AttributeMap(this);
}
// handle the namespaces
- if (attr.getNamespaceURI() != null
+ if (!useDomSemantics && attr.getNamespaceURI() != null
&& findNamespace(attr.getNamespaceURI(), attr.getPrefix())
== null) {
// TODO checkwhether the same ns is declared with a different
@@ -1155,15 +1107,41 @@ public class ElementImpl extends ParentN
}
}
- /**
- * Creates a clone which belongs to a new document.
- *
- * @see org.apache.axiom.om.OMElement#cloneOMElement()
- */
public OMElement cloneOMElement() {
- return (ElementImpl) this.cloneNode(true);
+ return cloneOMElement(new OMCloneOptions());
}
+ public OMElement cloneOMElement(OMCloneOptions options) {
+ return (OMElement)clone(options, null, true, true);
+ }
+
+ final ParentNode shallowClone(OMCloneOptions options, ParentNode targetParent, boolean namespaceRepairing) {
+ ElementImpl clone;
+ if (options.isPreserveModel()) {
+ clone = (ElementImpl)createClone(options, targetParent, namespaceRepairing);
+ } else {
+ clone = new ElementImpl(targetParent, localName, namespace, null, factory, namespaceRepairing);
+ }
+ for (Iterator it = getAllDeclaredNamespaces(); it.hasNext(); ) {
+ OMNamespace ns = (OMNamespace)it.next();
+ clone.declareNamespace(ns);
+ }
+ clone.attributes.cloneContent(options, attributes);
+ if (namespaceRepairing) {
+ for (Iterator it = getAllAttributes(); it.hasNext(); ) {
+ OMNamespace ns = ((OMAttribute)it.next()).getNamespace();
+ if (ns != null) {
+ clone.declareNamespace(ns);
+ }
+ }
+ }
+ return clone;
+ }
+
+ protected OMElement createClone(OMCloneOptions options, ParentNode targetParent, boolean generateNSDecl) {
+ return new ElementImpl(targetParent, localName, namespace, null, factory, generateNSDecl);
+ }
+
public void setLineNumber(int lineNumber) {
this.lineNumber = lineNumber;
}
@@ -1172,17 +1150,6 @@ public class ElementImpl extends ParentN
return lineNumber;
}
- public Node cloneNode(boolean deep) {
-
- ElementImpl newnode = (ElementImpl) super.cloneNode(deep);
- // Replicate NamedNodeMap rather than sharing it.
- if (attributes != null) {
- newnode.attributes = attributes.cloneMap(newnode);
- }
- return newnode;
-
- }
-
/** Returns the set of attributes of this node and the namespace declarations available. */
public NamedNodeMap getAttributes() {
AttributeMap attributeMap = new AttributeMap(this);
@@ -1245,16 +1212,6 @@ public class ElementImpl extends ParentN
}
}
- public OMNode getNextOMSibling() throws OMException {
- while (!done) {
- int token = builder.next();
- if (token == XMLStreamConstants.END_DOCUMENT) {
- throw new OMException();
- }
- }
- return super.getNextOMSibling();
- }
-
public void discard() throws OMException {
if (done) {
this.detach();
@@ -1369,4 +1326,42 @@ public class ElementImpl extends ParentN
}
super.normalize(config);
}
+
+ public final OMXMLParserWrapper getBuilder() {
+ return builder;
+ }
+
+ public final boolean isComplete() {
+ return done;
+ }
+
+ public final void setComplete(boolean state) {
+ done = state;
+ ParentNode parentNode = parentNode();
+ if (parentNode != null) {
+ if (!done) {
+ parentNode.setComplete(false);
+ } else {
+ parentNode.notifyChildComplete();
+ }
+ }
+ }
+
+ public OMNode detach() throws OMException {
+ if (isComplete() && !getParent().isComplete() && getNextOMSiblingIfAvailable() == null) {
+ // Special case: the node is complete, but the next node has not yet been created.
+ // In this case we want to detach the node without creating the next node because
+ // the builder may already have been closed (there is code in Axis2 that calls
+ // detach in that situation). We use discard for this: in this state, discard
+ // actually won't discard anything, but it will update the lastNode attribute
+ // of the builder.
+ getBuilder().discard(this);
+ } else {
+ if (!done) {
+ build();
+ }
+ super.detach();
+ }
+ return this;
+ }
}
Modified: webservices/axiom/branches/AXIOM-201/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/NodeImpl.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/AXIOM-201/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/NodeImpl.java?rev=1358610&r1=1358609&r2=1358610&view=diff
==============================================================================
--- webservices/axiom/branches/AXIOM-201/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/NodeImpl.java (original)
+++ webservices/axiom/branches/AXIOM-201/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/NodeImpl.java Sat Jul 7 18:24:00 2012
@@ -19,27 +19,35 @@
package org.apache.axiom.om.impl.dom;
+import org.apache.axiom.om.OMCloneOptions;
+import org.apache.axiom.om.OMContainer;
+import org.apache.axiom.om.OMException;
import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.OMNode;
+import org.apache.axiom.om.OMOutputFormat;
import org.apache.axiom.om.OMXMLParserWrapper;
+import org.apache.axiom.om.impl.MTOMXMLStreamWriter;
+import org.apache.axiom.om.impl.OMNodeEx;
+import org.apache.axiom.om.impl.builder.StAXBuilder;
+import org.apache.axiom.om.util.StAXUtils;
import org.w3c.dom.DOMException;
+import org.w3c.dom.Document;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
import org.w3c.dom.UserDataHandler;
+import java.io.OutputStream;
+import java.io.Writer;
import java.util.Hashtable;
-public abstract class NodeImpl implements Node, NodeList, Cloneable {
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamWriter;
+
+public abstract class NodeImpl implements Node {
/** Holds the user data objects */
private Hashtable userData; // Will be initialized in setUserData()
- /** Field builder */
- public OMXMLParserWrapper builder;
-
- /** Field done */
- protected boolean done = false;
-
/** Factory that created this node */
protected final OMFactory factory;
@@ -144,45 +152,15 @@ public abstract class NodeImpl implement
return null;
}
- /** Returns the next child of this node's parent, or null if none. */
- public Node getNextSibling() {
- return null; // default behavior, overriden in ChildNode
- }
-
- /** Returns the previous child of this node's parent, or null if none. */
- public Node getPreviousSibling() {
- return null; // default behavior, overriden in ChildNode
- }
-
- // public Node cloneNode(boolean deep) {
- // if(this instanceof OMElement) {
- // return (Node)((OMElement)this).cloneOMElement();
- // } else if(this instanceof OMText ){
- // return ((TextImpl)this).cloneText();
- // } else {
- // throw new UnsupportedOperationException("Only elements can be cloned
- // right now");
- // }
- // }
- //
- public Node cloneNode(boolean deep) {
- NodeImpl newnode;
- try {
- newnode = (NodeImpl) clone();
- } catch (CloneNotSupportedException e) {
- throw new RuntimeException("**Internal Error**" + e);
+ public final Node cloneNode(boolean deep) {
+ OMCloneOptions options = new OMCloneOptions();
+ // This is not specified by the API, but it's compatible with versions before 1.2.14
+ options.setPreserveModel(true);
+ NodeImpl clone = clone(options, null, getNodeType() == Node.ATTRIBUTE_NODE ? true : deep, false);
+ if (!(clone instanceof DocumentImpl)) {
+ clone.setOwnerDocument(ownerDocument());
}
-
- return newnode;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.w3c.dom.Node#getChildNodes()
- */
- public NodeList getChildNodes() {
- return this;
+ return clone;
}
public boolean isSupported(String feature, String version) {
@@ -191,82 +169,6 @@ public abstract class NodeImpl implement
}
/*
- * (non-Javadoc)
- *
- * @see org.w3c.dom.Node#appendChild(org.w3c.dom.Node)
- */
- public Node appendChild(Node newChild) throws DOMException {
- return insertBefore(newChild, null);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.w3c.dom.Node#removeChild(org.w3c.dom.Node)
- */
- public Node removeChild(Node oldChild) throws DOMException {
- throw new DOMException(DOMException.NOT_FOUND_ERR, DOMMessageFormatter
- .formatMessage(DOMMessageFormatter.DOM_DOMAIN, DOMException.NOT_FOUND_ERR,
- null));
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.w3c.dom.Node#insertBefore(org.w3c.dom.Node, org.w3c.dom.Node)
- */
- public Node insertBefore(Node newChild, Node refChild) throws DOMException {
- // Overridden in ParentNode
- throw new DOMException(DOMException.HIERARCHY_REQUEST_ERR,
- DOMMessageFormatter.formatMessage(
- DOMMessageFormatter.DOM_DOMAIN,
- DOMException.HIERARCHY_REQUEST_ERR, null));
-
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.w3c.dom.Node#replaceChild(org.w3c.dom.Node, org.w3c.dom.Node)
- */
- public Node replaceChild(Node newChild, Node oldChild) throws DOMException {
- throw new DOMException(DOMException.HIERARCHY_REQUEST_ERR,
- DOMMessageFormatter.formatMessage(
- DOMMessageFormatter.DOM_DOMAIN,
- DOMException.HIERARCHY_REQUEST_ERR, null));
- }
-
- //
- // NodeList methods
- //
-
- /**
- * NodeList method: Returns the number of immediate children of this node.
- * <p/>
- * By default we do not have any children, ParentNode overrides this.
- *
- * @return Returns int.
- * @see ParentNode
- */
- public int getLength() {
- return 0;
- }
-
- /**
- * NodeList method: Returns the Nth immediate child of this node, or null if the index is out of
- * bounds.
- * <p/>
- * By default we do not have any children, ParentNode overrides this.
- *
- * @param index
- * @return Returns org.w3c.dom.Node
- * @see ParentNode
- */
- public Node item(int index) {
- return null;
- }
-
- /*
* Flags setters and getters
*/
@@ -562,4 +464,414 @@ public abstract class NodeImpl implement
public OMFactory getOMFactory() {
return this.factory;
}
+
+
+ /**
+ * Get the parent or the owner document of the node. The meaning of the return value depends on
+ * the {@link NodeImpl#HAS_PARENT} flag.
+ */
+ abstract ParentNode internalGetOwnerNode();
+
+ abstract void internalSetOwnerNode(ParentNode ownerNode);
+
+ abstract NodeImpl internalGetPreviousSibling();
+
+ abstract NodeImpl internalGetNextSibling();
+
+ abstract void internalSetPreviousSibling(NodeImpl previousSibling);
+
+ abstract void internalSetNextSibling(NodeImpl nextSibling);
+
+ /**
+ * Get the owner document of this node. In contrast to {@link Node#getOwnerDocument()}, this
+ * method returns a non null value when invoked on a {@link Document} instance.
+ *
+ * @return the owner document
+ */
+ final DocumentImpl ownerDocument() {
+ ParentNode ownerNode = internalGetOwnerNode();
+ if (ownerNode == null) {
+ // As specified by DOMMetaFactory, the OMFactory for an implicitly created owner
+ // document is always the OMFactory for plain XML.
+ DocumentImpl document = new DocumentImpl(factory.getMetaFactory().getOMFactory());
+ internalSetOwnerNode(document);
+ return document;
+ } else if (ownerNode instanceof DocumentImpl) {
+ // Note: the value of the HAS_PARENT flag doesn't matter here. If the ownerNode is of
+ // type Document, it must be the owner document.
+ return (DocumentImpl)ownerNode;
+ } else {
+ return ownerNode.ownerDocument();
+ }
+ }
+
+ void checkSameOwnerDocument(Node otherNode) {
+ if (ownerDocument() != (otherNode instanceof AttrImpl
+ ? ((AttrImpl)otherNode).getOwnerDocument()
+ : ((NodeImpl)otherNode).ownerDocument())) {
+ throw new DOMException(DOMException.WRONG_DOCUMENT_ERR,
+ DOMMessageFormatter.formatMessage(
+ DOMMessageFormatter.DOM_DOMAIN,
+ DOMException.WRONG_DOCUMENT_ERR, null));
+ }
+ }
+
+ /**
+ * Sets the owner document.
+ *
+ * @param document
+ */
+ void setOwnerDocument(DocumentImpl document) {
+ if (hasParent()) {
+ throw new IllegalStateException();
+ }
+ internalSetOwnerNode(document);
+ }
+
+ public Document getOwnerDocument() {
+ return ownerDocument();
+ }
+
+ ParentNode parentNode() {
+ return hasParent() ? internalGetOwnerNode() : null;
+ }
+
+ public OMNode getNextOMSibling() throws OMException {
+ ParentNode parentNode = parentNode();
+ while (internalGetNextSibling() == null && parentNode != null && !parentNode.isComplete() && parentNode.getBuilder() != null) {
+ parentNode.buildNext();
+ }
+ return (OMNode)internalGetNextSibling();
+ }
+
+ public final OMNode getNextOMSiblingIfAvailable() {
+ return (OMNode)internalGetNextSibling();
+ }
+
+ public final Node getNextSibling() {
+ return (Node) this.getNextOMSibling();
+ }
+
+ public final OMNode getPreviousOMSibling() {
+ return (OMNode)internalGetPreviousSibling();
+ }
+
+ public final Node getPreviousSibling() {
+ return internalGetPreviousSibling();
+ }
+
+ // /
+ // /OMNode methods
+ // /
+ public final void setNextOMSibling(OMNode node) {
+ if (node == null) {
+ internalSetNextSibling(null);
+ return;
+ }
+ if (node instanceof NodeImpl) {
+ internalSetNextSibling((NodeImpl)node);
+ } else {
+ throw new OMException("The node is not a " + NodeImpl.class);
+ }
+ }
+
+ public final void setPreviousOMSibling(OMNode node) {
+ if (node == null) {
+ internalSetPreviousSibling(null);
+ return;
+ }
+ if (node instanceof NodeImpl) {
+ internalSetPreviousSibling((NodeImpl)node);
+ } else {
+ throw new OMException("The node is not a " + NodeImpl.class);
+ }
+ }
+
+ public final OMContainer getParent() throws OMException {
+ return (OMContainer)parentNode();
+ }
+
+ public Node getParentNode() {
+ return parentNode();
+ }
+
+ public final void setParent(OMContainer element) {
+ setParent((ParentNode)element, false);
+ }
+
+ protected void setParent(ParentNode parent, boolean useDomSemantics) {
+ if (parent == null) {
+ internalSetOwnerNode(useDomSemantics ? ownerDocument() : null);
+ hasParent(false);
+ } else {
+ internalSetOwnerNode(parent);
+ hasParent(true);
+ }
+ }
+
+ public OMNode detach() throws OMException {
+ return detach(false);
+ }
+
+ OMNode detach(boolean useDomSemantics) {
+ ParentNode parentNode = parentNode();
+ if (parentNode == null) {
+ throw new OMException("Parent level elements cannot be detached");
+ } else {
+ if (!isComplete()) {
+ build();
+ }
+ getNextOMSibling(); // Make sure that nextSibling is set correctly
+ NodeImpl previousSibling = internalGetPreviousSibling();
+ NodeImpl nextSibling = internalGetNextSibling();
+ if (previousSibling == null) { // This is the first child
+ if (nextSibling != null) {
+ parentNode.setFirstChild((OMNode)nextSibling);
+ } else {
+ parentNode.firstChild = null;
+ parentNode.lastChild = null;
+ }
+ } else {
+ previousSibling.setNextOMSibling((OMNode)nextSibling);
+ if (nextSibling == null) {
+ previousSibling.parentNode().setComplete(true);
+ }
+ }
+ if (nextSibling != null) {
+ nextSibling.setPreviousOMSibling((OMNode)previousSibling);
+ internalSetNextSibling(null);
+ }
+ if (parentNode != null && parentNode.lastChild == this) {
+ parentNode.lastChild = previousSibling;
+ }
+ setParent(null, useDomSemantics);
+ internalSetPreviousSibling(null);
+ }
+ return (OMNode)this;
+ }
+
+ /** Inserts the given sibling next to this item. */
+ public void insertSiblingAfter(OMNode sibling) throws OMException {
+ ParentNode parentNode = parentNode();
+ if (parentNode == null) {
+ throw new OMException("Parent can not be null");
+ } else if (this == sibling) {
+ throw new OMException("Inserting self as the sibling is not allowed");
+ }
+ ((OMNodeEx) sibling).setParent((OMContainer)parentNode);
+ if (sibling instanceof NodeImpl) {
+ NodeImpl domSibling = (NodeImpl) sibling;
+ domSibling.internalSetPreviousSibling(this);
+ NodeImpl nextSibling = internalGetNextSibling();
+ if (nextSibling == null) {
+ parentNode.setLastChild(sibling);
+ } else {
+ nextSibling.internalSetPreviousSibling(domSibling);
+ }
+ domSibling.internalSetNextSibling(nextSibling);
+ internalSetNextSibling(domSibling);
+
+ } else {
+ throw new OMException("The given child is not of type "
+ + NodeImpl.class);
+ }
+ }
+
+ /** Inserts the given sibling before this item. */
+ public void insertSiblingBefore(OMNode sibling) throws OMException {
+ ParentNode parentNode = parentNode();
+ // ((OMNodeEx)sibling).setParent(this.parentNode);
+ if (parentNode == null) {
+ throw new OMException("Parent can not be null");
+ } else if (this == sibling) {
+ throw new OMException("Inserting self as the sibling is not allowed");
+ }
+ if (sibling instanceof NodeImpl) {
+ // ChildNode domSibling = (ChildNode)sibling;
+ // domSibling.nextSibling = this;
+ // if(this.previousSibling != null) {
+ // this.previousSibling.nextSibling = domSibling;
+ // }
+ // domSibling.previousSibling = this.previousSibling;
+ // this.previousSibling = domSibling;
+ NodeImpl siblingImpl = (NodeImpl) sibling;
+ siblingImpl.internalSetNextSibling(this);
+ NodeImpl previousSibling = internalGetPreviousSibling();
+ if (previousSibling == null) {
+ parentNode.setFirstChild((OMNode)siblingImpl);
+ siblingImpl.internalSetPreviousSibling(null);
+ } else {
+ siblingImpl.setParent(parentNode, false);
+ previousSibling.setNextOMSibling((OMNode)siblingImpl);
+ siblingImpl.setPreviousOMSibling((OMNode)previousSibling);
+ }
+ internalSetPreviousSibling(siblingImpl);
+
+ } else {
+ throw new OMException("The given child is not of type "
+ + NodeImpl.class);
+ }
+
+ }
+
+ public abstract OMXMLParserWrapper getBuilder();
+
+ public abstract void setComplete(boolean state);
+
+ public abstract boolean isComplete();
+
+ /** Builds next element. */
+ public void build() {
+ while (!isComplete()) {
+ getBuilder().next();
+ }
+ }
+
+ /**
+ * Parses this node and builds the object structure in memory. AXIOM supports two levels of
+ * deffered building. First is deffered building of AXIOM using StAX. Second level is the deffered
+ * building of attachments. AXIOM reads in the attachements from the stream only when user asks by
+ * calling getDataHandler(). build() method builds the OM without the attachments. buildAll()
+ * builds the OM together with attachement data. This becomes handy when user wants to free the
+ * input stream.
+ */
+ public void buildWithAttachments() {
+ if (!this.isComplete()) {
+ this.build();
+ }
+ }
+
+ public void close(boolean build) {
+ OMXMLParserWrapper builder = getBuilder();
+ if (build) {
+ this.build();
+ }
+ setComplete(true);
+
+ // If this is a StAXBuilder, close it.
+ if (builder instanceof StAXBuilder &&
+ !((StAXBuilder) builder).isClosed()) {
+ ((StAXBuilder) builder).releaseParserOnClose(true);
+ ((StAXBuilder) builder).close();
+ }
+ }
+
+ public void serialize(XMLStreamWriter xmlWriter) throws XMLStreamException {
+ serialize(xmlWriter, true);
+ }
+
+ public void serializeAndConsume(XMLStreamWriter xmlWriter) throws XMLStreamException {
+ serialize(xmlWriter, false);
+ }
+
+ public void serialize(XMLStreamWriter xmlWriter, boolean cache) throws XMLStreamException {
+ MTOMXMLStreamWriter writer = xmlWriter instanceof MTOMXMLStreamWriter ?
+ (MTOMXMLStreamWriter) xmlWriter :
+ new MTOMXMLStreamWriter(xmlWriter);
+ internalSerialize(writer, cache);
+ writer.flush();
+ }
+
+ public void serialize(OutputStream output) throws XMLStreamException {
+ XMLStreamWriter xmlStreamWriter = StAXUtils.createXMLStreamWriter(output);
+ try {
+ serialize(xmlStreamWriter);
+ } finally {
+ xmlStreamWriter.close();
+ }
+ }
+
+ public void serialize(Writer writer) throws XMLStreamException {
+ XMLStreamWriter xmlStreamWriter = StAXUtils.createXMLStreamWriter(writer);
+ try {
+ serialize(xmlStreamWriter);
+ } finally {
+ xmlStreamWriter.close();
+ }
+ }
+
+ public void serializeAndConsume(OutputStream output)
+ throws XMLStreamException {
+ XMLStreamWriter xmlStreamWriter = StAXUtils.createXMLStreamWriter(output);
+ try {
+ serializeAndConsume(xmlStreamWriter);
+ } finally {
+ xmlStreamWriter.close();
+ }
+ }
+
+ public void serializeAndConsume(Writer writer) throws XMLStreamException {
+ XMLStreamWriter xmlStreamWriter = StAXUtils.createXMLStreamWriter(writer);
+ try {
+ serializeAndConsume(xmlStreamWriter);
+ } finally {
+ xmlStreamWriter.close();
+ }
+ }
+
+ public void serialize(OutputStream output, OMOutputFormat format)
+ throws XMLStreamException {
+ MTOMXMLStreamWriter writer = new MTOMXMLStreamWriter(output, format, true);
+ try {
+ internalSerialize(writer, true);
+ // TODO: the flush is necessary because of an issue with the lifecycle of MTOMXMLStreamWriter
+ writer.flush();
+ } finally {
+ writer.close();
+ }
+ }
+
+ public void serialize(Writer writer2, OMOutputFormat format)
+ throws XMLStreamException {
+ MTOMXMLStreamWriter writer = new MTOMXMLStreamWriter(StAXUtils
+ .createXMLStreamWriter(writer2));
+ writer.setOutputFormat(format);
+ try {
+ internalSerialize(writer, true);
+ // TODO: the flush is necessary because of an issue with the lifecycle of MTOMXMLStreamWriter
+ writer.flush();
+ } finally {
+ writer.close();
+ }
+ }
+
+ public void serializeAndConsume(OutputStream output, OMOutputFormat format)
+ throws XMLStreamException {
+ MTOMXMLStreamWriter writer = new MTOMXMLStreamWriter(output, format, false);
+ try {
+ internalSerialize(writer, false);
+ // TODO: the flush is necessary because of an issue with the lifecycle of MTOMXMLStreamWriter
+ writer.flush();
+ } finally {
+ writer.close();
+ }
+ }
+
+ public void serializeAndConsume(Writer writer2, OMOutputFormat format)
+ throws XMLStreamException {
+ MTOMXMLStreamWriter writer = new MTOMXMLStreamWriter(StAXUtils
+ .createXMLStreamWriter(writer2));
+ try {
+ writer.setOutputFormat(format);
+ // TODO: the flush is necessary because of an issue with the lifecycle of MTOMXMLStreamWriter
+ internalSerialize(writer, false);
+ writer.flush();
+ } finally {
+ writer.close();
+ }
+ }
+
+ public void internalSerialize(XMLStreamWriter writer) throws XMLStreamException {
+ internalSerialize(writer, true);
+ }
+
+ public void internalSerializeAndConsume(XMLStreamWriter writer) throws XMLStreamException {
+ internalSerialize(writer, false);
+ }
+
+ // This method is actually defined by OMNodeEx, but OMNodeEx is only implemented
+ // by certain subclasses (for the reason, see AXIOM-385).
+ public abstract void internalSerialize(XMLStreamWriter writer, boolean cache) throws XMLStreamException;
+
+ abstract NodeImpl clone(OMCloneOptions options, ParentNode targetParent, boolean deep, boolean namespaceRepairing);
}