axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject svn commit: r398400 - in /webservices/axis2/trunk/java/modules: adb/src/org/apache/axis2/databinding/utils/reader/ adb/src/org/apache/axis2/util/ core/src/org/apache/axis2/context/
Date Sun, 30 Apr 2006 18:45:59 GMT
Author: dims
Date: Sun Apr 30 11:45:57 2006
New Revision: 398400

URL: http://svn.apache.org/viewcvs?rev=398400&view=rev
Log:
- Replace java.util.Stack with ArrayStack (Stack is derived from Vector which is synchronized
and hence slow)
- The ArrayStack is from jakarta commons collections.
- Fix isHeaderPresent in a better fashion (Thanks Eran!)
- Eliminate extra method call in ADBXMLStreamReaderImpl (merge next and updateStatus)


Added:
    webservices/axis2/trunk/java/modules/adb/src/org/apache/axis2/util/
    webservices/axis2/trunk/java/modules/adb/src/org/apache/axis2/util/ArrayStack.java
Modified:
    webservices/axis2/trunk/java/modules/adb/src/org/apache/axis2/databinding/utils/reader/ADBNamespaceContext.java
    webservices/axis2/trunk/java/modules/adb/src/org/apache/axis2/databinding/utils/reader/ADBXMLStreamReaderImpl.java
    webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/context/MessageContext.java

Modified: webservices/axis2/trunk/java/modules/adb/src/org/apache/axis2/databinding/utils/reader/ADBNamespaceContext.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/adb/src/org/apache/axis2/databinding/utils/reader/ADBNamespaceContext.java?rev=398400&r1=398399&r2=398400&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/adb/src/org/apache/axis2/databinding/utils/reader/ADBNamespaceContext.java
(original)
+++ webservices/axis2/trunk/java/modules/adb/src/org/apache/axis2/databinding/utils/reader/ADBNamespaceContext.java
Sun Apr 30 11:45:57 2006
@@ -1,8 +1,9 @@
 package org.apache.axis2.databinding.utils.reader;
 
+import org.apache.axis2.util.ArrayStack;
+
 import javax.xml.namespace.NamespaceContext;
 import java.util.Iterator;
-import java.util.Stack;
 import java.util.ArrayList;
 /*
  * Copyright 2004,2005 The Apache Software Foundation.
@@ -36,8 +37,8 @@
     //since the index of the entry will be used to relate them
     //use the minimum initial capacity to let things handle memory better
 
-    private Stack prefixStack = new Stack();
-    private Stack uriStack = new Stack();
+    private ArrayStack prefixStack = new ArrayStack();
+    private ArrayStack uriStack = new ArrayStack();
 
     /**
      * Register a namespace in this context

Modified: webservices/axis2/trunk/java/modules/adb/src/org/apache/axis2/databinding/utils/reader/ADBXMLStreamReaderImpl.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/adb/src/org/apache/axis2/databinding/utils/reader/ADBXMLStreamReaderImpl.java?rev=398400&r1=398399&r2=398400&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/adb/src/org/apache/axis2/databinding/utils/reader/ADBXMLStreamReaderImpl.java
(original)
+++ webservices/axis2/trunk/java/modules/adb/src/org/apache/axis2/databinding/utils/reader/ADBXMLStreamReaderImpl.java
Sun Apr 30 11:45:57 2006
@@ -159,10 +159,6 @@
 
     }
 
-    public int next() throws XMLStreamException {
-        return updateStatus();
-    }
-
     public void require(int i, String string, String string1)
             throws XMLStreamException {
         throw new UnsupportedOperationException();
@@ -793,10 +789,9 @@
 
     /**
      * By far this should be the most important method in this class
-     * this method changes the state of the parser according to the
-     * change in the
+     * this method changes the state of the parser 
      */
-    private int updateStatus() throws XMLStreamException {
+    public int next() throws XMLStreamException {
         int returnEvent = -1; //invalid state is the default state
         switch (state) {
             case START_ELEMENT_STATE:

Added: webservices/axis2/trunk/java/modules/adb/src/org/apache/axis2/util/ArrayStack.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/adb/src/org/apache/axis2/util/ArrayStack.java?rev=398400&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/adb/src/org/apache/axis2/util/ArrayStack.java (added)
+++ webservices/axis2/trunk/java/modules/adb/src/org/apache/axis2/util/ArrayStack.java Sun
Apr 30 11:45:57 2006
@@ -0,0 +1,186 @@
+/*
+ *  Copyright 2001-2004 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.axis2.util;
+
+import java.util.ArrayList;
+import java.util.EmptyStackException;
+
+/**
+ * An implementation of the {@link java.util.Stack} API that is based on an
+ * <code>ArrayList</code> instead of a <code>Vector</code>, so it
is not
+ * synchronized to protect against multi-threaded access.  The implementation
+ * is therefore operates faster in environments where you do not need to
+ * worry about multiple thread contention.
+ * <p>
+ * The removal order of an <code>ArrayStack</code> is based on insertion
+ * order: The most recently added element is removed first.  The iteration
+ * order is <i>not</i> the same as the removal order.  The iterator returns
+ * elements from the bottom up, whereas the {@link #remove()} method removes
+ * them from the top down.
+ * <p>
+ * Unlike <code>Stack</code>, <code>ArrayStack</code> accepts null
entries.
+ */
+public class ArrayStack extends ArrayList {
+
+    /** Ensure serialization compatibility */
+    private static final long serialVersionUID = 2130079159931574599L;
+
+    /**
+     * Constructs a new empty <code>ArrayStack</code>. The initial size
+     * is controlled by <code>ArrayList</code> and is currently 10.
+     */
+    public ArrayStack() {
+        super();
+    }
+
+    /**
+     * Constructs a new empty <code>ArrayStack</code> with an initial size.
+     *
+     * @param initialSize  the initial size to use
+     * @throws IllegalArgumentException  if the specified initial size
+     *  is negative
+     */
+    public ArrayStack(int initialSize) {
+        super(initialSize);
+    }
+
+    /**
+     * Return <code>true</code> if this stack is currently empty.
+     * <p>
+     * This method exists for compatibility with <code>java.util.Stack</code>.
+     * New users of this class should use <code>isEmpty</code> instead.
+     *
+     * @return true if the stack is currently empty
+     */
+    public boolean empty() {
+        return isEmpty();
+    }
+
+    /**
+     * Returns the top item off of this stack without removing it.
+     *
+     * @return the top item on the stack
+     * @throws EmptyStackException  if the stack is empty
+     */
+    public Object peek() throws EmptyStackException {
+        int n = size();
+        if (n <= 0) {
+            throw new EmptyStackException();
+        } else {
+            return get(n - 1);
+        }
+    }
+
+    /**
+     * Returns the n'th item down (zero-relative) from the top of this
+     * stack without removing it.
+     *
+     * @param n  the number of items down to go
+     * @return the n'th item on the stack, zero relative
+     * @throws EmptyStackException  if there are not enough items on the
+     *  stack to satisfy this request
+     */
+    public Object peek(int n) throws EmptyStackException {
+        int m = (size() - n) - 1;
+        if (m < 0) {
+            throw new EmptyStackException();
+        } else {
+            return get(m);
+        }
+    }
+
+    /**
+     * Pops the top item off of this stack and return it.
+     *
+     * @return the top item on the stack
+     * @throws EmptyStackException  if the stack is empty
+     */
+    public Object pop() throws EmptyStackException {
+        int n = size();
+        if (n <= 0) {
+            throw new EmptyStackException();
+        } else {
+            return remove(n - 1);
+        }
+    }
+
+    /**
+     * Pushes a new item onto the top of this stack. The pushed item is also
+     * returned. This is equivalent to calling <code>add</code>.
+     *
+     * @param item  the item to be added
+     * @return the item just pushed
+     */
+    public Object push(Object item) {
+        add(item);
+        return item;
+    }
+
+    /**
+     * Returns the one-based position of the distance from the top that the
+     * specified object exists on this stack, where the top-most element is
+     * considered to be at distance <code>1</code>.  If the object is not
+     * present on the stack, return <code>-1</code> instead.  The
+     * <code>equals()</code> method is used to compare to the items
+     * in this stack.
+     *
+     * @param object  the object to be searched for
+     * @return the 1-based depth into the stack of the object, or -1 if not found
+     */
+    public int search(Object object) {
+        int i = size() - 1;        // Current index
+        int n = 1;                 // Current distance
+        while (i >= 0) {
+            Object current = get(i);
+            if ((object == null && current == null) ||
+                (object != null && object.equals(current))) {
+                return n;
+            }
+            i--;
+            n++;
+        }
+        return -1;
+    }
+
+    /**
+     * Returns the element on the top of the stack.
+     *
+     * @return the element on the top of the stack
+     * @throws EmptyStackException  if the stack is empty
+     */
+    public Object get() {
+        int size = size();
+        if (size == 0) {
+            throw new EmptyStackException();
+        }
+        return get(size - 1);
+    }
+
+    /**
+     * Removes the element on the top of the stack.
+     *
+     * @return the removed element
+     * @throws EmptyStackException  if the stack is empty
+     */
+    public Object remove() {
+        int size = size();
+        if (size == 0) {
+            throw new EmptyStackException();
+        }
+        return remove(size - 1);
+    }
+
+}

Modified: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/context/MessageContext.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/context/MessageContext.java?rev=398400&r1=398399&r2=398400&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/context/MessageContext.java
(original)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/context/MessageContext.java
Sun Apr 30 11:45:57 2006
@@ -951,12 +951,9 @@
      * @return boolean
      */
     public boolean isHeaderPresent() {
-        OMNode node = getEnvelope().getFirstOMChild();
-        if(node instanceof OMElement){
-            OMElement firstChild = (OMElement) node;
-            if(firstChild.getQName().getLocalPart().equals(SOAPConstants.BODY_LOCAL_NAME))
{
-                return false;
-            }
+        OMElement node = getEnvelope().getFirstElement();
+        if (node != null && node.getQName().getLocalPart().equals(SOAPConstants.BODY_LOCAL_NAME))
{
+            return false;
         }
         return true;
     }



Mime
View raw message