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/04/07 12:39:07 UTC

svn commit: r392244 - in /webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om: ./ impl/builder/ impl/dom/ impl/dom/factory/ impl/llom/ impl/llom/factory/

Author: chinthaka
Date: Fri Apr  7 03:39:04 2006
New Revision: 392244

URL: http://svn.apache.org/viewcvs?rev=392244&view=rev
Log:
Adding methods to deal with char arrays within OMtext.


Modified:
    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/builder/StAXBuilder.java
    webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/impl/builder/StAXOMBuilder.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/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/OMFactory.java
URL: http://svn.apache.org/viewcvs/webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/OMFactory.java?rev=392244&r1=392243&r2=392244&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 Fri Apr  7 03:39:04 2006
@@ -106,6 +106,7 @@
      * @return Returns OMText.
      */
     public OMText createText(OMElement parent, String text, int type);
+    public OMText createText(OMElement parent, char[] charArary, int type);
 
     /**
      * @param parent

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=392244&r1=392243&r2=392244&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 Fri Apr  7 03:39:04 2006
@@ -20,7 +20,9 @@
 
 
 /**
- * Interface OMText
+ * Interface OMText.
+ *
+ * OMText can contain data as a String, char[] or a DataHandler.
  */
 public interface OMText extends OMNode {
     /**
@@ -29,6 +31,10 @@
      * @return Returns String.
      */
     String getText();
+
+    char[] getTextCharacters();
+    boolean isCharacters();
+
     QName getTextAsQName();
 
     /**

Modified: webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/impl/builder/StAXBuilder.java
URL: http://svn.apache.org/viewcvs/webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/impl/builder/StAXBuilder.java?rev=392244&r1=392243&r2=392244&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/impl/builder/StAXBuilder.java (original)
+++ webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/impl/builder/StAXBuilder.java Fri Apr  7 03:39:04 2006
@@ -178,12 +178,10 @@
             return null;
         } else if (!lastNode.isComplete()) {
             node = createOMText((OMElement) lastNode, textType);
-//            node = omfactory.createText((OMElement) lastNode, parser.getText(), textType);
         } else {
             OMContainer parent = lastNode.getParent();
             if (!(parent instanceof OMDocument)) {
                 node = createOMText((OMElement) parent, textType);
-//                node = omfactory.createText((OMElement) parent, parser.getText(), textType);
             }
         }
         return node;

Modified: webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/impl/builder/StAXOMBuilder.java
URL: http://svn.apache.org/viewcvs/webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/impl/builder/StAXOMBuilder.java?rev=392244&r1=392243&r2=392244&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/impl/builder/StAXOMBuilder.java (original)
+++ webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/impl/builder/StAXOMBuilder.java Fri Apr  7 03:39:04 2006
@@ -96,101 +96,6 @@
     }
 
     /**
-     * Method createOMElement.
-     *
-     * @return Returns OMNode.
-     * @throws OMException
-     */
-    protected OMNode createOMElement() throws OMException {
-        OMElement node;
-        String elementName = parser.getLocalName();
-        if (lastNode == null) {
-            node = omfactory.createOMElement(elementName, null, document, this);
-        } else if (lastNode.isComplete()) {
-            node = omfactory.createOMElement(elementName, null,
-                    lastNode.getParent(), this);
-            ((OMNodeEx) lastNode).setNextOMSibling(node);
-            ((OMNodeEx) node).setPreviousOMSibling(lastNode);
-        } else {
-            OMElement e = (OMElement) lastNode;
-            node = omfactory.createOMElement(elementName, null,
-                    (OMElement) lastNode, this);
-            e.setFirstChild(node);
-        }
-        // create the namespaces
-        processNamespaceData(node);
-        // fill in the attributes
-        processAttributes(node);
-        node.setLineNumber(parser.getLocation().getLineNumber());
-        return node;
-    }
-
-    /**
-     * Method createOMText.
-     *
-     * @return Returns OMNode.
-     * @throws OMException
-     */
-    protected OMNode createComment() throws OMException {
-        OMNode node;
-        if (lastNode == null) {
-            node = omfactory.createOMComment(document, parser.getText());
-        } else if (lastNode.isComplete()) {
-            node = omfactory.createOMComment(lastNode.getParent(), parser.getText());
-        } else {
-            node = omfactory.createOMComment((OMElement) lastNode, parser.getText());
-        }
-        return node;
-    }
-
-    /**
-     * Method createDTD.
-     *
-     * @return Returns OMNode.
-     * @throws OMException
-     */
-    protected OMNode createDTD() throws OMException {
-        if (!parser.hasText())
-            return null;
-        return omfactory.createOMDocType(document, parser.getText());
-    }
-
-    /**
-     * Method createPI.
-     *
-     * @return Returns OMNode.
-     * @throws OMException
-     */
-    protected OMNode createPI() throws OMException {
-        OMNode node;
-        String target = parser.getPITarget();
-        String data = parser.getPIData();
-        if (lastNode == null) {
-            node = omfactory.createOMProcessingInstruction(document, target, data);
-        } else if (lastNode.isComplete()) {
-            node = omfactory.createOMProcessingInstruction(lastNode.getParent(), target, data);
-        } else if (lastNode instanceof OMText) {
-            node = omfactory.createOMProcessingInstruction(lastNode.getParent(), target, data);
-        } else {
-            node = omfactory.createOMProcessingInstruction((OMContainer) lastNode, target, data);
-        }
-        return node;
-    }
-
-    protected void endElement() {
-        if (lastNode.isComplete()) {
-            OMElement parent = (OMElement) lastNode.getParent();
-            ((OMNodeEx) parent).setComplete(true);
-            lastNode = parent;
-        } else {
-            OMElement e = (OMElement) lastNode;
-            ((OMNodeEx) e).setComplete(true);
-        }
-
-        //return lastNode;
-    }
-
-    /**
      * Method next.
      *
      * @return Returns int.
@@ -286,6 +191,102 @@
         } catch (Exception e) {
             throw new OMException(e);
         }
+    }
+    
+
+    /**
+     * Method createOMElement.
+     *
+     * @return Returns OMNode.
+     * @throws OMException
+     */
+    protected OMNode createOMElement() throws OMException {
+        OMElement node;
+        String elementName = parser.getLocalName();
+        if (lastNode == null) {
+            node = omfactory.createOMElement(elementName, null, document, this);
+        } else if (lastNode.isComplete()) {
+            node = omfactory.createOMElement(elementName, null,
+                    lastNode.getParent(), this);
+            ((OMNodeEx) lastNode).setNextOMSibling(node);
+            ((OMNodeEx) node).setPreviousOMSibling(lastNode);
+        } else {
+            OMElement e = (OMElement) lastNode;
+            node = omfactory.createOMElement(elementName, null,
+                    (OMElement) lastNode, this);
+            e.setFirstChild(node);
+        }
+        // create the namespaces
+        processNamespaceData(node);
+        // fill in the attributes
+        processAttributes(node);
+        node.setLineNumber(parser.getLocation().getLineNumber());
+        return node;
+    }
+
+    /**
+     * Method createOMText.
+     *
+     * @return Returns OMNode.
+     * @throws OMException
+     */
+    protected OMNode createComment() throws OMException {
+        OMNode node;
+        if (lastNode == null) {
+            node = omfactory.createOMComment(document, parser.getText());
+        } else if (lastNode.isComplete()) {
+            node = omfactory.createOMComment(lastNode.getParent(), parser.getText());
+        } else {
+            node = omfactory.createOMComment((OMElement) lastNode, parser.getText());
+        }
+        return node;
+    }
+
+    /**
+     * Method createDTD.
+     *
+     * @return Returns OMNode.
+     * @throws OMException
+     */
+    protected OMNode createDTD() throws OMException {
+        if (!parser.hasText())
+            return null;
+        return omfactory.createOMDocType(document, parser.getText());
+    }
+
+    /**
+     * Method createPI.
+     *
+     * @return Returns OMNode.
+     * @throws OMException
+     */
+    protected OMNode createPI() throws OMException {
+        OMNode node;
+        String target = parser.getPITarget();
+        String data = parser.getPIData();
+        if (lastNode == null) {
+            node = omfactory.createOMProcessingInstruction(document, target, data);
+        } else if (lastNode.isComplete()) {
+            node = omfactory.createOMProcessingInstruction(lastNode.getParent(), target, data);
+        } else if (lastNode instanceof OMText) {
+            node = omfactory.createOMProcessingInstruction(lastNode.getParent(), target, data);
+        } else {
+            node = omfactory.createOMProcessingInstruction((OMContainer) lastNode, target, data);
+        }
+        return node;
+    }
+
+    protected void endElement() {
+        if (lastNode.isComplete()) {
+            OMElement parent = (OMElement) lastNode.getParent();
+            ((OMNodeEx) parent).setComplete(true);
+            lastNode = parent;
+        } else {
+            OMElement e = (OMElement) lastNode;
+            ((OMNodeEx) e).setComplete(true);
+        }
+
+        //return lastNode;
     }
 
     /**

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=392244&r1=392243&r2=392244&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 Fri Apr  7 03:39:04 2006
@@ -304,6 +304,14 @@
         }
     }
 
+    public char[] getTextCharacters() {
+        return textValue.toString().toCharArray();
+    }
+
+    public boolean isCharacters() {
+        return false;  //To change body of implemented methods use File | Settings | File Templates.
+    }
+
     public QName getTextAsQName() {
         throw new UnsupportedOperationException();
     }

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=392244&r1=392243&r2=392244&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 Fri Apr  7 03:39:04 2006
@@ -200,7 +200,13 @@
         return textNode;
     }
 
+    public OMText createText(OMElement parent, char[] charArary, int type) {
+        // TODO : Fix me
+        throw new UnsupportedOperationException();
+    }
+
     public OMText createText(OMElement parent, QName text, int type) {
+        // TODO : Fix me
         throw new UnsupportedOperationException();
     }
 

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=392244&r1=392243&r2=392244&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 Fri Apr  7 03:39:04 2006
@@ -44,6 +44,7 @@
             "http://www.w3.org/2004/08/xop/include", "xop");
 
     protected String value = null;
+    protected char[] charArray;
 
     protected OMNamespace textNS;
 
@@ -114,6 +115,14 @@
         this.nodeType = nodeType;
     }
 
+    public OMTextImpl(OMElement parent, char[] charArray, int nodeType,
+                      OMFactory factory) {
+        super(parent, factory);
+        this.charArray = charArray;
+        done = true;
+        this.nodeType = nodeType;
+    }
+
 
     public OMTextImpl(OMElement parent, QName text, OMFactory factory) {
         this(parent, text, TEXT_NODE, factory);
@@ -221,8 +230,8 @@
     public String getText() throws OMException {
         if (textNS != null) {
             return getTextString();
-        } else if (this.value != null) {
-            return this.value;
+        } else if (charArray != null || this.value != null) {
+            return getTextFromProperPlace();
         } else {
             try {
                 InputStream inStream;
@@ -247,6 +256,22 @@
         }
     }
 
+    public char[] getTextCharacters() {
+        return charArray != null ? charArray : value.toCharArray();
+    }
+
+    public boolean isCharacters() {
+        return charArray != null;
+    }
+
+    /**
+     * This OMText contains two data source:value and charArray. This method will return text from
+     * correct place.
+     */
+    private String getTextFromProperPlace() {
+        return charArray != null ? new String(charArray) : value;
+    }
+
 
     /**
      * Returns the value.
@@ -254,13 +279,14 @@
     public QName getTextAsQName() throws OMException {
         if (textNS != null) {
             String prefix = textNS.getPrefix();
+            String name = textNS.getName();
             if (prefix == null || "".equals(prefix)) {
-                return new QName(textNS.getName(), value);
+                return new QName(name, getTextFromProperPlace());
             } else {
-                return new QName(textNS.getName(), value, prefix);
+                return new QName(textNS.getName(), getTextFromProperPlace(), prefix);
             }
-        } else if (this.value != null) {
-            return new QName(value);
+        } else if (this.value != null || charArray != null) {
+            return new QName(getTextFromProperPlace());
         } else {
             try {
                 InputStream inStream;
@@ -303,8 +329,8 @@
      * @return Returns javax.activation.DataHandler
      */
     public Object getDataHandler() {
-        if ((value != null || textNS != null) & isBinary) {
-            String text = textNS == null ? value : getTextString();
+        if ((value != null || charArray != null || textNS != null) & isBinary) {
+            String text = textNS == null ? getTextFromProperPlace() : getTextString();
             return org.apache.axiom.attachments.DataHandlerUtils.getDataHandlerFromText(text, mimeType);
         } else {
 
@@ -323,9 +349,9 @@
         if (textNS != null) {
             String prefix = textNS.getPrefix();
             if (prefix == null || "".equals(prefix)) {
-                return value;
+                return getTextFromProperPlace();
             } else {
-                return prefix + ":" + value;
+                return prefix + ":" + getTextFromProperPlace();
             }
         }
 

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=392244&r1=392243&r2=392244&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 Fri Apr  7 03:39:04 2006
@@ -148,6 +148,10 @@
         return new OMTextImpl(parent, text, type, this);
     }
 
+    public OMText createText(OMElement parent, char[] charArary, int type) {
+        return new OMTextImpl(parent, charArary, type, this);
+    }
+
     public OMText createText(OMElement parent, QName text, int type) {
         return new OMTextImpl(parent, text, type, this);
     }