Author: veithen Date: Sun Jun 2 21:19:57 2013 New Revision: 1488794 URL: http://svn.apache.org/r1488794 Log: Removed some attributes in the OMText implementations that were only used by the deprecated getNamespace() method and that are actually not necessary.
Modified: webservices/axiom/trunk/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/TextNodeImpl.java webservices/axiom/trunk/modules/axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/OMImplementationTest.java webservices/axiom/trunk/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMTextImpl.java Modified: webservices/axiom/trunk/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/TextNodeImpl.java URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/TextNodeImpl.java?rev=1488794&r1=1488793&r2=1488794&view=diff ============================================================================== --- webservices/axiom/trunk/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/TextNodeImpl.java (original) +++ webservices/axiom/trunk/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/TextNodeImpl.java Sun Jun 2 21:19:57 2013 @@ -23,12 +23,14 @@ import org.apache.axiom.attachments.util import org.apache.axiom.ext.stax.datahandler.DataHandlerProvider; import org.apache.axiom.om.OMCloneOptions; import org.apache.axiom.om.OMContainer; +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; import org.apache.axiom.om.OMOutputFormat; import org.apache.axiom.om.OMText; +import org.apache.axiom.om.impl.common.OMNamespaceImpl; import org.apache.axiom.om.impl.common.serializer.push.OutputException; import org.apache.axiom.om.impl.common.serializer.push.Serializer; import org.apache.axiom.util.UIDGenerator; @@ -50,8 +52,6 @@ public abstract class TextNodeImpl exten private String contentID; - protected OMNamespace textNS; - protected char[] charArray; /** @@ -96,11 +96,6 @@ public abstract class TextNodeImpl exten } } - - // Turn off textNS...the namespace will need to be recalculated - // in the new tree's context. - this.textNS = null; - // Copy the optimized related settings. this.optimize = source.optimize; this.mimeType = source.mimeType; @@ -174,7 +169,7 @@ public abstract class TextNodeImpl exten public TextNodeImpl(OMContainer parent, QName text, int nodeType, OMFactory factory) { this(factory); - this.textNS = + OMNamespace textNS = ((ElementImpl) parent).handleNamespace(text.getNamespaceURI(), text.getPrefix()); this.textValue = textNS == null ? text.getLocalPart() : textNS.getPrefix() + ":" + text.getLocalPart(); } @@ -272,38 +267,8 @@ public abstract class TextNodeImpl exten return charArray != null ? new String(charArray) : textValue; } - private String getTextString() { - if (textNS != null) { - String prefix = textNS.getPrefix(); - if (prefix == null || "".equals(prefix)) { - return getTextFromProperPlace(); - } else { - return prefix + ":" + getTextFromProperPlace(); - } - } - - return null; - } - public QName getTextAsQName() { - if (textNS != null) { - String prefix = textNS.getPrefix(); - String name = textNS.getNamespaceURI(); - if (prefix == null || "".equals(prefix)) { - return new QName(name, getTextFromProperPlace()); - } else { - return new QName(textNS.getNamespaceURI(), getTextFromProperPlace(), prefix); - } - } else if (this.textValue != null || charArray != null) { - return new QName(getTextFromProperPlace()); - } else { - try { - // TODO: do we really want to build a QName from base64 encoded data?!? - return new QName(Base64Utils.encode((DataHandler) getDataHandler())); - } catch (Exception e) { - throw new OMException(e); - } - } + return ((OMElement)parentNode()).resolveQName(getTextFromProperPlace()); } public String getNodeValue() throws DOMException { @@ -322,10 +287,8 @@ public abstract class TextNodeImpl exten * this should return a DataHandler containing the binary data * reperesented by the Base64 strings stored in OMText */ - if ((textValue != null || charArray != null || textNS != null) & isBinary) { - String text = textNS == null ? getTextFromProperPlace() : getTextString(); - return DataHandlerUtils - .getDataHandlerFromText(text, mimeType); + if ((textValue != null || charArray != null) & isBinary) { + return DataHandlerUtils.getDataHandlerFromText(getTextFromProperPlace(), mimeType); } else { if (dataHandlerObject == null) { @@ -416,7 +379,14 @@ public abstract class TextNodeImpl exten } public OMNamespace getNamespace() { - return textNS; + // Note: efficiency is not important here; the method is deprecated anyway + QName qname = getTextAsQName(); + if (qname == null) { + return null; + } else { + String namespaceURI = qname.getNamespaceURI(); + return namespaceURI.length() == 0 ? null : new OMNamespaceImpl(namespaceURI, qname.getPrefix()); + } } public void setContentID(String cid) { Modified: webservices/axiom/trunk/modules/axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/OMImplementationTest.java URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/modules/axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/OMImplementationTest.java?rev=1488794&r1=1488793&r2=1488794&view=diff ============================================================================== --- webservices/axiom/trunk/modules/axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/OMImplementationTest.java (original) +++ webservices/axiom/trunk/modules/axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/OMImplementationTest.java Sun Jun 2 21:19:57 2013 @@ -33,7 +33,6 @@ import org.apache.axiom.ts.om.element.sr import org.apache.axiom.ts.om.node.TestInsertSiblingAfterOnChild; import org.apache.axiom.ts.om.node.TestInsertSiblingBeforeOnChild; import org.apache.axiom.ts.om.sourcedelement.TestGetSAXSourceWithPushOMDataSource; -import org.apache.axiom.ts.om.text.TestGetNamespace; public class OMImplementationTest extends TestCase { public static TestSuite suite() { @@ -64,8 +63,6 @@ public class OMImplementationTest extend // TODO: test case needing review builder.exclude(TestClose.class); - builder.exclude(TestGetNamespace.class); - return builder.build(); } } Modified: webservices/axiom/trunk/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMTextImpl.java URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMTextImpl.java?rev=1488794&r1=1488793&r2=1488794&view=diff ============================================================================== --- webservices/axiom/trunk/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMTextImpl.java (original) +++ webservices/axiom/trunk/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMTextImpl.java Sun Jun 2 21:19:57 2013 @@ -30,6 +30,7 @@ import org.apache.axiom.om.OMNamespace; import org.apache.axiom.om.OMNode; import org.apache.axiom.om.OMOutputFormat; import org.apache.axiom.om.OMText; +import org.apache.axiom.om.impl.common.OMNamespaceImpl; import org.apache.axiom.om.impl.common.serializer.push.OutputException; import org.apache.axiom.om.impl.common.serializer.push.Serializer; import org.apache.axiom.util.UIDGenerator; @@ -45,9 +46,6 @@ public class OMTextImpl extends OMLeafNo protected String value; protected char[] charArray; - private boolean calcNS; // Set to true after textNS is calculated - protected OMNamespace textNS; - protected String mimeType; protected boolean optimize; @@ -111,11 +109,6 @@ public class OMTextImpl extends OMLeafNo System.arraycopy(source.charArray, 0, this.charArray, 0, source.charArray.length); } - // Turn off calcNS...the namespace will need to be recalculated - // in the new tree's context. - this.calcNS = false; - this.textNS = null; - // Copy the optimized related settings. this.optimize = source.optimize; this.mimeType = source.mimeType; @@ -150,8 +143,7 @@ public class OMTextImpl extends OMLeafNo OMFactory factory) { super(parent, factory, false); if (text == null) throw new IllegalArgumentException("QName text arg cannot be null!"); - this.calcNS = true; - this.textNS = + OMNamespace textNS = ((OMElementImpl) parent).handleNamespace(text.getNamespaceURI(), text.getPrefix()); this.value = textNS == null ? text.getLocalPart() : textNS.getPrefix() + ":" + text.getLocalPart(); this.nodeType = nodeType; @@ -262,28 +254,14 @@ public class OMTextImpl extends OMLeafNo } public OMNamespace getNamespace() { - // If the namespace has already been determined, return it - // Otherwise calculate the namespace if the text contains a colon and is not detached. - if (calcNS) { - return textNS; + // Note: efficiency is not important here; the method is deprecated anyway + QName qname = getTextAsQName(); + if (qname == null) { + return null; } else { - calcNS = true; - if (getParent() != null) { - String text = getTextFromProperPlace(); - if (text != null) { - int colon = text.indexOf(':'); - if (colon > 0) { - textNS = ((OMElementImpl) getParent()). - findNamespaceURI(text.substring(0, colon)); - if (textNS != null) { - charArray = null; - value = text.substring(colon + 1); - } - } - } - } + String namespaceURI = qname.getNamespaceURI(); + return namespaceURI.length() == 0 ? null : new OMNamespaceImpl(namespaceURI, qname.getPrefix()); } - return textNS; } public boolean isOptimized() {