You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commons-dev@ws.apache.org by ch...@apache.org on 2006/03/28 19:02:13 UTC
svn commit: r389542 - in
/webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om: ./
impl/dom/ impl/dom/factory/ impl/llom/ impl/llom/factory/
Author: chinthaka
Date: Tue Mar 28 09:02:11 2006
New Revision: 389542
URL: http://svn.apache.org/viewcvs?rev=389542&view=rev
Log:
Introducing Texts to contain QNames directly.
Now one can directly create a Text giving a QName or call OMElement.setText(QName).
TODO :
- test cases
- implementing this for DOOM
Modified:
webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/OMElement.java
webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/OMFactory.java
webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/OMText.java
webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/impl/dom/ElementImpl.java
webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/impl/dom/TextImpl.java
webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/impl/dom/factory/OMDOMFactory.java
webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/impl/llom/OMElementImpl.java
webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/impl/llom/OMTextImpl.java
webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/impl/llom/factory/OMLinkedListImplFactory.java
Modified: webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/OMElement.java
URL: http://svn.apache.org/viewcvs/webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/OMElement.java?rev=389542&r1=389541&r2=389542&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/OMElement.java (original)
+++ webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/OMElement.java Tue Mar 28 09:02:11 2006
@@ -221,6 +221,7 @@
* @param text
*/
public void setText(String text);
+ public void setText(QName text);
/**
* Returns the non-empty text children as a String.
Modified: webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/OMFactory.java
URL: http://svn.apache.org/viewcvs/webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/OMFactory.java?rev=389542&r1=389541&r2=389542&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/OMFactory.java (original)
+++ webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/OMFactory.java Tue Mar 28 09:02:11 2006
@@ -23,18 +23,20 @@
*/
public interface OMFactory {
- /**
- * Creates a new OMDocument.
- */
- public OMDocument createOMDocument();
- public OMDocument createOMDocument(OMXMLParserWrapper builder);
-
-
+ /**
+ * Creates a new OMDocument.
+ */
+ public OMDocument createOMDocument();
+
+ public OMDocument createOMDocument(OMXMLParserWrapper builder);
+
+
/**
* @param localName
* @param ns
*/
public OMElement createOMElement(String localName, OMNamespace ns);
+
public OMElement createOMElement(String localName, OMNamespace ns, OMContainer parent) throws OMException;
/**
@@ -90,28 +92,41 @@
public OMText createText(OMElement parent, String text);
/**
- *
+ * @param parent
+ * @param text - This text itself can contain a namespace inside it.
+ * @return
+ */
+ public OMText createText(OMElement parent, QName text);
+
+ /**
* @param parent
* @param text
- * @param type - this should be either of XMLStreamConstants.CHARACTERS, XMLStreamConstants.CDATA,
- * XMLStreamConstants.SPACE, XMLStreamConstants.ENTITY_REFERENCE
+ * @param type - this should be either of XMLStreamConstants.CHARACTERS, XMLStreamConstants.CDATA,
+ * XMLStreamConstants.SPACE, XMLStreamConstants.ENTITY_REFERENCE
* @return Returns OMText.
*/
public OMText createText(OMElement parent, String text, int type);
/**
+ * @param parent
+ * @param text - This text itself can contain a namespace inside it.
+ * @param type
+ * @return
+ */
+ public OMText createText(OMElement parent, QName text, int type);
+
+ /**
* @param s
* @return Returns OMText.
*/
public OMText createText(String s);
/**
- *
* @param s
* @param type - OMText node can handle SPACE, CHARACTERS, CDATA and ENTITY REFERENCES. For Constants, use either
- * XMLStreamConstants or constants found in OMNode.
+ * XMLStreamConstants or constants found in OMNode.
* @return Returns OMText.
- */
+ */
public OMText createText(String s, int type);
public OMText createText(String s, String mimeType, boolean optimize);
@@ -122,14 +137,15 @@
boolean optimize);
public OMText createText(String contentID, OMElement parent,
- OMXMLParserWrapper builder);
-
+ OMXMLParserWrapper builder);
+
public OMAttribute createOMAttribute(String localName,
OMNamespace ns,
String value);
/**
* Creates DocType/DTD.
+ *
* @param parent
* @param content
* @return Returns doctype.
@@ -138,6 +154,7 @@
/**
* Creates a PI.
+ *
* @param parent
* @param piTarget
* @param piData
@@ -147,6 +164,7 @@
/**
* Creates a comment.
+ *
* @param parent
* @param content
* @return Returns OMComment.
Modified: webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/OMText.java
URL: http://svn.apache.org/viewcvs/webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/OMText.java?rev=389542&r1=389541&r2=389542&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/OMText.java (original)
+++ webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/OMText.java Tue Mar 28 09:02:11 2006
@@ -16,6 +16,8 @@
package org.apache.axiom.om;
+import javax.xml.namespace.QName;
+
/**
* Interface OMText
@@ -27,6 +29,7 @@
* @return Returns String.
*/
String getText();
+ QName getTextAsQName();
/**
* Gets the datahandler.
@@ -51,4 +54,5 @@
* @return Returns String.
*/
String getContentID();
+
}
Modified: webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/impl/dom/ElementImpl.java
URL: http://svn.apache.org/viewcvs/webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/impl/dom/ElementImpl.java?rev=389542&r1=389541&r2=389542&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/impl/dom/ElementImpl.java (original)
+++ webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/impl/dom/ElementImpl.java Tue Mar 28 09:02:11 2006
@@ -966,9 +966,13 @@
child = child.getNextOMSibling();
}
- TextImpl textNode = (TextImpl) ((DocumentImpl) this.ownerNode)
+ TextImpl textNode = (TextImpl) (this.ownerNode)
.createTextNode(text);
this.addChild(textNode);
+ }
+
+ public void setText(QName text) {
+ throw new UnsupportedOperationException();
}
/*
Modified: webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/impl/dom/TextImpl.java
URL: http://svn.apache.org/viewcvs/webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/impl/dom/TextImpl.java?rev=389542&r1=389541&r2=389542&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/impl/dom/TextImpl.java (original)
+++ webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/impl/dom/TextImpl.java Tue Mar 28 09:02:11 2006
@@ -33,6 +33,7 @@
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;
+import javax.xml.namespace.QName;
import java.io.IOException;
import java.io.InputStream;
@@ -310,6 +311,10 @@
throw new OMException(e);
}
}
+ }
+
+ public QName getTextAsQName() {
+ throw new UnsupportedOperationException();
}
public String getNodeValue() throws DOMException {
Modified: webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/impl/dom/factory/OMDOMFactory.java
URL: http://svn.apache.org/viewcvs/webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/impl/dom/factory/OMDOMFactory.java?rev=389542&r1=389541&r2=389542&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/impl/dom/factory/OMDOMFactory.java (original)
+++ webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/impl/dom/factory/OMDOMFactory.java Tue Mar 28 09:02:11 2006
@@ -190,10 +190,18 @@
return txt;
}
+ public OMText createText(OMElement parent, QName text) {
+ throw new UnsupportedOperationException();
+ }
+
public OMText createText(OMElement parent, String text, int type) {
OMText textNode = createText(parent, text);
((OMNodeEx) textNode).setType(type);
return textNode;
+ }
+
+ public OMText createText(OMElement parent, QName text, int type) {
+ throw new UnsupportedOperationException();
}
/**
Modified: webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/impl/llom/OMElementImpl.java
URL: http://svn.apache.org/viewcvs/webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/impl/llom/OMElementImpl.java?rev=389542&r1=389541&r2=389542&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/impl/llom/OMElementImpl.java (original)
+++ webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/impl/llom/OMElementImpl.java Tue Mar 28 09:02:11 2006
@@ -140,7 +140,7 @@
/**
* Method handleNamespace.
*/
- private OMNamespace handleNamespace(QName qname) {
+ OMNamespace handleNamespace(QName qname) {
OMNamespace ns = null;
// first try to find a namespace from the scope
@@ -617,6 +617,24 @@
* mixed content) before setting the text.
*/
public void setText(String text) {
+
+ OMNode child = this.getFirstOMChild();
+ while (child != null) {
+ if (child.getType() == OMNode.TEXT_NODE) {
+ child.detach();
+ }
+ child = child.getNextOMSibling();
+ }
+
+ OMAbstractFactory.getOMFactory().createText(this, text);
+ }
+
+ /**
+ * Sets the text, as a QName, of the given element.
+ * caution - This method will wipe out all the text elements (and hence any
+ * mixed content) before setting the text.
+ */
+ public void setText(QName text) {
OMNode child = this.getFirstOMChild();
while (child != null) {
Modified: webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/impl/llom/OMTextImpl.java
URL: http://svn.apache.org/viewcvs/webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/impl/llom/OMTextImpl.java?rev=389542&r1=389541&r2=389542&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/impl/llom/OMTextImpl.java (original)
+++ webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/impl/llom/OMTextImpl.java Tue Mar 28 09:02:11 2006
@@ -32,12 +32,15 @@
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;
+import javax.xml.namespace.QName;
import java.io.IOException;
import java.io.InputStream;
public class OMTextImpl extends OMNodeImpl implements OMText, OMConstants {
protected String value = null;
+ protected OMNamespace textNS;
+
protected String mimeType;
protected boolean optimize = false;
@@ -52,7 +55,7 @@
/**
* Field dataHandler contains the DataHandler
- * Declaring as Object to remove the dependency on
+ * Declaring as Object to remove the dependency on
* Javax.activation.DataHandler
*/
private Object dataHandlerObject = null;
@@ -60,7 +63,7 @@
/**
* Field nameSpace used when serializing Binary stuff as MTOM optimized.
*/
- protected OMNamespace ns = null;
+ protected OMNamespace xopNS = null;
/**
* Field localName used when serializing Binary stuff as MTOM optimized.
@@ -78,11 +81,7 @@
* @param s
*/
public OMTextImpl(String s, OMFactory factory) {
- super(factory);
- this.value = s;
- this.nodeType = TEXT_NODE;
- this.ns = new OMNamespaceImpl(
- "http://www.w3.org/2004/08/xop/include", "xop", factory);
+ this(s, TEXT_NODE, factory);
}
/**
@@ -94,9 +93,9 @@
super(factory);
this.value = s;
this.nodeType = nodeType;
- this.ns = new OMNamespaceImpl(
+ this.xopNS = new OMNamespaceImpl(
"http://www.w3.org/2004/08/xop/include", "xop", factory);
- }
+ }
/**
* Constructor OMTextImpl.
@@ -105,21 +104,32 @@
* @param text
*/
public OMTextImpl(OMElement parent, String text, OMFactory factory) {
+ this(parent, text, TEXT_NODE, factory);
+ }
+
+ public OMTextImpl(OMElement parent, String text, int nodeType,
+ OMFactory factory) {
super(parent, factory);
this.value = text;
done = true;
- this.nodeType = TEXT_NODE;
- this.ns = new OMNamespaceImpl(
+ this.nodeType = nodeType;
+ this.xopNS = new OMNamespaceImpl(
"http://www.w3.org/2004/08/xop/include", "xop", factory);
}
- public OMTextImpl(OMElement parent, String text, int nodeType,
- OMFactory factory) {
+
+ public OMTextImpl(OMElement parent, QName text, OMFactory factory) {
+ this(parent, text, TEXT_NODE, factory);
+ }
+
+ public OMTextImpl(OMElement parent, QName text, int nodeType,
+ OMFactory factory) {
super(parent, factory);
- this.value = text;
+ this.textNS = ((OMElementImpl) parent).handleNamespace(text);
+ this.value = text.getLocalPart();
done = true;
this.nodeType = nodeType;
- this.ns = new OMNamespaceImpl(
+ this.xopNS = new OMNamespaceImpl(
"http://www.w3.org/2004/08/xop/include", "xop", factory);
}
@@ -127,8 +137,8 @@
* @param s - base64 encoded String representation of Binary
* @param mimeType of the Binary
*/
- public OMTextImpl(String s, String mimeType, boolean optimize,
- OMFactory factory) {
+ public OMTextImpl(String s, String mimeType, boolean optimize,
+ OMFactory factory) {
this(null, s, mimeType, optimize, factory);
}
@@ -166,7 +176,7 @@
this.optimize = optimize;
done = true;
this.nodeType = TEXT_NODE;
- this.ns = new OMNamespaceImpl(
+ this.xopNS = new OMNamespaceImpl(
"http://www.w3.org/2004/08/xop/include", "xop", factory);
}
@@ -185,7 +195,7 @@
this.isBinary = true;
this.builder = builder;
this.nodeType = TEXT_NODE;
- this.ns = new OMNamespaceImpl(
+ this.xopNS = new OMNamespaceImpl(
"http://www.w3.org/2004/08/xop/include", "xop", factory);
}
@@ -220,7 +230,9 @@
* Returns the value.
*/
public String getText() throws OMException {
- if (this.value != null) {
+ if (textNS != null) {
+ return getTextString();
+ }else if (this.value != null) {
return this.value;
} else {
try {
@@ -229,16 +241,16 @@
byte[] data;
StringBuffer text = new StringBuffer();
do {
- data = new byte[1024];
- int len;
- while((len = inStream.read(data)) > 0) {
- byte[] temp = new byte[len];
- System.arraycopy(data,0,temp,0,len);
- text.append(Base64.encode(temp));
- }
+ data = new byte[1024];
+ int len;
+ while ((len = inStream.read(data)) > 0) {
+ byte[] temp = new byte[len];
+ System.arraycopy(data, 0, temp, 0, len);
+ text.append(Base64.encode(temp));
+ }
} while (inStream.available() > 0);
-
+
return text.toString();
} catch (Exception e) {
throw new OMException(e);
@@ -246,21 +258,59 @@
}
}
+
+/**
+ * Returns the value.
+ */
+ public QName getTextAsQName() throws OMException {
+ if (textNS != null) {
+ String prefix = textNS.getPrefix();
+ if (prefix == null || "".equals(prefix)) {
+ return new QName(textNS.getName(), value);
+ }else {
+ return new QName(textNS.getName(), value, prefix);
+ }
+ }else if (this.value != null) {
+ return new QName(value);
+ } else {
+ try {
+ InputStream inStream;
+ inStream = this.getInputStream();
+ byte[] data;
+ StringBuffer text = new StringBuffer();
+ do {
+ data = new byte[1024];
+ int len;
+ while ((len = inStream.read(data)) > 0) {
+ byte[] temp = new byte[len];
+ System.arraycopy(data, 0, temp, 0, len);
+ text.append(Base64.encode(temp));
+ }
+
+ } while (inStream.available() > 0);
+
+ return new QName(text.toString());
+ } catch (Exception e) {
+ throw new OMException(e);
+ }
+ }
+ }
+
public boolean isOptimized() {
return optimize;
}
public void setOptimize(boolean value) {
this.optimize = value;
- if (value)
- {
- isBinary = true;
- }
+ if (value) {
+ isBinary = true;
+ }
}
-
+
/**
* Gets the datahandler.
+ *
* @return Returns javax.activation.DataHandler
*/
public Object getDataHandler() {
@@ -268,8 +318,14 @@
* this should return a DataHandler containing the binary data
* reperesented by the Base64 strings stored in OMText
*/
- if (value != null & isBinary) {
- return org.apache.axiom.attachments.DataHandlerUtils.getDataHandlerFromText(value,mimeType);
+
+ if(isBinary){
+
+ }
+
+ if ((value != null || textNS != null) & isBinary) {
+ String text = textNS == null ? value : getTextString();
+ return org.apache.axiom.attachments.DataHandlerUtils.getDataHandlerFromText(text, mimeType);
} else {
if (dataHandlerObject == null) {
@@ -283,6 +339,19 @@
}
}
+ private String getTextString() {
+ if(textNS != null){
+ String prefix = textNS.getPrefix();
+ if (prefix == null || "".equals(prefix)) {
+ return value;
+ }else {
+ return prefix + ":" + value;
+ }
+ }
+
+ return null;
+ }
+
public String getLocalName() {
return localName;
}
@@ -293,7 +362,7 @@
getDataHandler();
}
InputStream inStream;
- javax.activation.DataHandler dataHandler = (javax.activation.DataHandler)dataHandlerObject;
+ javax.activation.DataHandler dataHandler = (javax.activation.DataHandler) dataHandlerObject;
try {
inStream = dataHandler.getDataSource().getInputStream();
} catch (IOException e) {
@@ -333,14 +402,14 @@
}
// send binary as MTOM optimised
this.attribute = new OMAttributeImpl("href",
- new OMNamespaceImpl("", "", this.factory), "cid:" + getContentID(),
+ new OMNamespaceImpl("", "", this.factory), "cid:" + getContentID(),
this.factory);
this.serializeStartpart(omOutput);
omOutput.writeOptimized(this);
omOutput.getXmlStreamWriter().writeEndElement();
} else {
omOutput.getXmlStreamWriter().writeCharacters(this.getText());
- }
+ }
}
}
@@ -353,10 +422,10 @@
String writer_prefix;
String prefix;
XMLStreamWriter writer = omOutput.getXmlStreamWriter();
- if (this.ns != null) {
- nameSpaceName = this.ns.getName();
+ if (this.xopNS != null) {
+ nameSpaceName = this.xopNS.getName();
writer_prefix = writer.getPrefix(nameSpaceName);
- prefix = this.ns.getPrefix();
+ prefix = this.xopNS.getPrefix();
if (nameSpaceName != null) {
if (writer_prefix != null) {
writer
@@ -385,7 +454,7 @@
// add the elements attribute "href"
serializeAttribute(this.attribute, omOutput);
// add the namespace
- serializeNamespace(this.ns, omOutput);
+ serializeNamespace(this.xopNS, omOutput);
}
/**
@@ -448,4 +517,5 @@
builder.discard((OMElement) this.parent);
}
}
+
}
Modified: webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/impl/llom/factory/OMLinkedListImplFactory.java
URL: http://svn.apache.org/viewcvs/webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/impl/llom/factory/OMLinkedListImplFactory.java?rev=389542&r1=389541&r2=389542&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/impl/llom/factory/OMLinkedListImplFactory.java (original)
+++ webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/impl/llom/factory/OMLinkedListImplFactory.java Tue Mar 28 09:02:11 2006
@@ -140,7 +140,15 @@
return new OMTextImpl(parent, text, this);
}
+ public OMText createText(OMElement parent, QName text) {
+ return new OMTextImpl(parent, text, this);
+ }
+
public OMText createText(OMElement parent, String text, int type) {
+ return new OMTextImpl(parent, text, type, this);
+ }
+
+ public OMText createText(OMElement parent, QName text, int type) {
return new OMTextImpl(parent, text, type, this);
}