You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by ch...@apache.org on 2005/08/29 11:05:17 UTC

svn commit: r264102 - in /webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om: OMFactory.java OMNode.java impl/llom/OMTextImpl.java impl/llom/builder/StAXOMBuilder.java impl/llom/factory/OMLinkedListImplFactory.java

Author: chinthaka
Date: Mon Aug 29 02:05:06 2005
New Revision: 264102

URL: http://svn.apache.org/viewcvs?rev=264102&view=rev
Log:
- Making OMStaxBuilder to handle Entity refs, Spaces.
- Adding factory method to create variations of OMText
- Aligning constants with XMLStreamConstants

Modified:
    webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/OMFactory.java
    webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/OMNode.java
    webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMTextImpl.java
    webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/builder/StAXOMBuilder.java
    webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/factory/OMLinkedListImplFactory.java

Modified: webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/OMFactory.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/OMFactory.java?rev=264102&r1=264101&r2=264102&view=diff
==============================================================================
--- webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/OMFactory.java (original)
+++ webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/OMFactory.java Mon Aug 29 02:05:06 2005
@@ -96,6 +96,15 @@
      */
     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.
+     * @return
+     */
+    public OMText createText(String s, int type);
+
     public OMText createText(String s, String mimeType, boolean optimize);
 
     public OMText createText(DataHandler dataHandler, boolean optimize);

Modified: webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/OMNode.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/OMNode.java?rev=264102&r1=264101&r2=264102&view=diff
==============================================================================
--- webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/OMNode.java (original)
+++ webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/OMNode.java Mon Aug 29 02:05:06 2005
@@ -17,6 +17,7 @@
 
 import org.apache.axis2.om.impl.OMOutputImpl;
 
+import javax.xml.stream.XMLStreamConstants;
 import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamWriter;
 
@@ -32,27 +33,37 @@
     /**
      * The node is a <code>Text</code> node.
      */
-    public static final short TEXT_NODE = 4;
+    public static final short TEXT_NODE = XMLStreamConstants.CHARACTERS;
 
     /**
      * The node is a <code>CDATASection</code>.
      */
-    public static final short CDATA_SECTION_NODE = 12;
+    public static final short CDATA_SECTION_NODE = XMLStreamConstants.CDATA;
 
     /**
      * The node is a <code>Comment</code>.
      */
-    public static final short COMMENT_NODE = 8;
+    public static final short COMMENT_NODE = XMLStreamConstants.COMMENT;
 
     /**
      * This node is a <code>DTD</code>.
      */
-    public static final short DTD_NODE = 9;
+    public static final short DTD_NODE = XMLStreamConstants.DTD;
 
     /**
      * This node is a <code>ProcessingInstruction</code>.
      */
-    public static final short PI_NODE = 10;
+    public static final short PI_NODE = XMLStreamConstants.PROCESSING_INSTRUCTION;
+
+    /**
+     * This node is a <code>Entity Reference</code>.
+     */
+    public static final short ENTITY_REFERENCE_NODE = XMLStreamConstants.ENTITY_REFERENCE;
+
+    /**
+     * This node is a <code>Entity Reference</code>.
+     */
+    public static final short SPACE_NODE = XMLStreamConstants.SPACE;
 
     /**
      * This method should return the immediate parent of the node.
@@ -210,6 +221,7 @@
     /**
      * The build method will not read the information from stream and build MTOM stuff.
      * This method is to build the normal model and force build the MTOM stuff too.
+     *
      * @throws OMException
      */
     public void buildWithMTOM() throws OMException;

Modified: webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMTextImpl.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMTextImpl.java?rev=264102&r1=264101&r2=264102&view=diff
==============================================================================
--- webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMTextImpl.java (original)
+++ webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMTextImpl.java Mon Aug 29 02:05:06 2005
@@ -71,7 +71,7 @@
 
     /**
      * Constructor OMTextImpl
-     * 
+     *
      * @param s
      */
     public OMTextImpl(String s) {
@@ -80,8 +80,18 @@
     }
 
     /**
+     * @param s
+     * @param nodeType - OMText can handler CHARACTERS, SPACES, CDATA and ENTITY REFERENCES.
+     *                 Constants for this can be found in OMNode.
+     */
+    public OMTextImpl(String s, int nodeType) {
+        this.value = s;
+        this.nodeType = nodeType;
+    }
+
+    /**
      * Constructor OMTextImpl
-     * 
+     *
      * @param parent
      * @param text
      */
@@ -93,10 +103,9 @@
     }
 
     /**
-     * @param s -
-     *            base64 encoded String representation of Binary
-     * @param mimeType
-     *            of the Binary
+     * @param s        -
+     *                 base64 encoded String representation of Binary
+     * @param mimeType of the Binary
      */
     public OMTextImpl(String s, String mimeType, boolean optimize) {
         this(null, s, mimeType, optimize);
@@ -104,13 +113,12 @@
 
     /**
      * @param parent
-     * @param s -
-     *            base64 encoded String representation of Binary
-     * @param mimeType
-     *            of the Binary
+     * @param s        -
+     *                 base64 encoded String representation of Binary
+     * @param mimeType of the Binary
      */
     public OMTextImpl(OMElement parent, String s, String mimeType,
-            boolean optimize) {
+                      boolean optimize) {
         this(parent, s);
         this.mimeType = mimeType;
         this.optimize = optimize;
@@ -119,8 +127,7 @@
     }
 
     /**
-     * @param dataHandler
-     *            To send binary optimised content Created programatically.
+     * @param dataHandler To send binary optimised content Created programatically.
      */
     public OMTextImpl(DataHandler dataHandler) {
         this(dataHandler, true);
@@ -128,8 +135,7 @@
 
     /**
      * @param dataHandler
-     * @param optimize
-     *            To send binary content. Created progrmatically.
+     * @param optimize    To send binary content. Created progrmatically.
      */
     public OMTextImpl(DataHandler dataHandler, boolean optimize) {
         this.dataHandler = dataHandler;
@@ -142,13 +148,12 @@
     /**
      * @param contentID
      * @param parent
-     * @param builder
-     *            Used when the builder is encountered with a XOP:Include tag
-     *            Stores a reference to the builder and the content-id. Supports
-     *            deffered parsing of MIME messages
+     * @param builder   Used when the builder is encountered with a XOP:Include tag
+     *                  Stores a reference to the builder and the content-id. Supports
+     *                  deffered parsing of MIME messages
      */
     public OMTextImpl(String contentID, OMElement parent,
-            OMXMLParserWrapper builder) {
+                      OMXMLParserWrapper builder) {
         super(parent);
         this.contentID = contentID;
         this.optimize = true;
@@ -170,16 +175,19 @@
 
     /**
      * Writes the relevant output
+     *
      * @param omOutput
      * @throws XMLStreamException
      */
     private void writeOutput(OMOutputImpl omOutput) throws XMLStreamException {
         XMLStreamWriter writer = omOutput.getXmlStreamWriter();
         int type = getType();
-        if (type == TEXT_NODE) {
+        if (type == TEXT_NODE || type == SPACE_NODE) {
             writer.writeCharacters(this.getText());
         } else if (type == CDATA_SECTION_NODE) {
             writer.writeCData(this.getText());
+        } else if (type == ENTITY_REFERENCE_NODE) {
+            writer.writeEntityRef(this.getText());
         }
     }
 
@@ -195,7 +203,7 @@
                 inStream = this.getInputStream();
                 //int x = inStream.available();
                 byte[] data;
-                StringBuffer text= new StringBuffer();
+                StringBuffer text = new StringBuffer();
                 // There are times, this inStream reports the Available bytes
                 // incorrectly.
                 // Reading the First byte & then getting the available number of
@@ -204,7 +212,7 @@
                     data = new byte[3];
                     IOUtils.readFully(inStream, data, 0, 3);
                     text.append(Base64.encode(data));
-                }while (inStream.available()>0);
+                } while (inStream.available() > 0);
                 return text.toString();
             } catch (Exception e) {
                 throw new OMException(e);
@@ -227,7 +235,7 @@
     /**
      * @return
      * @throws org.apache.axis2.om.OMException
-     * 
+     *
      * @throws OMException
      */
     public DataHandler getDataHandler() {
@@ -294,12 +302,12 @@
 
     public void serialize(org.apache.axis2.om.impl.OMOutputImpl omOutput)
             throws XMLStreamException {
-           serializeLocal(omOutput);
+        serializeLocal(omOutput);
     }
 
     private void serializeLocal(OMOutputImpl omOutput) throws XMLStreamException {
         if (!this.isBinary) {
-             writeOutput(omOutput);
+            writeOutput(omOutput);
         } else {
             if (omOutput.isOptimized()) {
                 if (contentID == null) {
@@ -311,12 +319,9 @@
                 this.serializeStartpart(omOutput);
                 omOutput.writeOptimized(this);
                 omOutput.getXmlStreamWriter().writeEndElement();
-            } else if(this.getType() == OMNode.TEXT_NODE){
+            } else {
                 omOutput.getXmlStreamWriter().writeCharacters(this.getText());
-            }else if(this.getType() == OMNode.CDATA_SECTION_NODE){
-                omOutput.getXmlStreamWriter().writeCData(this.getText());
-            }
-
+            } 
         }
     }
 
@@ -366,7 +371,7 @@
 
     /**
      * Method serializeAttribute
-     * 
+     *
      * @param attr
      * @param omOutput
      * @throws XMLStreamException
@@ -396,13 +401,13 @@
 
     /**
      * Method serializeNamespace
-     * 
+     *
      * @param namespace
      * @param omOutput
      * @throws XMLStreamException
      */
     static void serializeNamespace(OMNamespace namespace,
-            org.apache.axis2.om.impl.OMOutputImpl omOutput)
+                                   org.apache.axis2.om.impl.OMOutputImpl omOutput)
             throws XMLStreamException {
         XMLStreamWriter writer = omOutput.getXmlStreamWriter();
         if (namespace != null) {
@@ -415,7 +420,7 @@
 
     /**
      * Slightly different implementation of the discard method
-     * 
+     *
      * @throws OMException
      */
     public void discard() throws OMException {

Modified: webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/builder/StAXOMBuilder.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/builder/StAXOMBuilder.java?rev=264102&r1=264101&r2=264102&view=diff
==============================================================================
--- webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/builder/StAXOMBuilder.java (original)
+++ webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/builder/StAXOMBuilder.java Mon Aug 29 02:05:06 2005
@@ -232,7 +232,7 @@
                     if(doDebug) {
                         System.out.println("SPACE: [" + parser.getText() + "]");
                     }
-                    handleSpace();
+                    lastNode = createOMText(XMLStreamConstants.SPACE);
                     break;
                 case XMLStreamConstants.COMMENT:
                     if(doDebug) {
@@ -256,7 +256,7 @@
                     if(doDebug) {
                         System.out.println("ENTITY_REFERENCE: " + parser.getLocalName() + "[" + parser.getText() + "]");
                     }
-                    handleEntityReference();
+                    lastNode = createOMText(XMLStreamConstants.ENTITY_REFERENCE);
                     break;
                 default :
                     throw new OMException();
@@ -270,15 +270,7 @@
         }
     }
 
-    private void handleSpace() {
-        //TODO
-    }
-
-    private void handleEntityReference() {
-        //TODO
-    }
-
-    /**
+   /**
      * Method getDocumentElement
      *
      * @return root element

Modified: webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/factory/OMLinkedListImplFactory.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/factory/OMLinkedListImplFactory.java?rev=264102&r1=264101&r2=264102&view=diff
==============================================================================
--- webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/factory/OMLinkedListImplFactory.java (original)
+++ webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/factory/OMLinkedListImplFactory.java Mon Aug 29 02:05:06 2005
@@ -121,6 +121,10 @@
         return new OMTextImpl(s);
     }
 
+    public OMText createText(String s, int type) {
+        return new OMTextImpl(s, type);
+    }
+
     /**
      * create Text
      * @param s