axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gdani...@apache.org
Subject svn commit: r533506 - in /webservices/axis2/trunk/java/modules/kernel: src/org/apache/axis2/context/ src/org/apache/axis2/description/ src/org/apache/axis2/engine/ src/org/apache/axis2/phaseresolver/ test/org/apache/axis2/phaserule/
Date Sun, 29 Apr 2007 14:02:30 GMT
Author: gdaniels
Date: Sun Apr 29 07:02:29 2007
New Revision: 533506

URL: http://svn.apache.org/viewvc?view=rev&rev=533506
Log:
Clean up logic and code in Phase/PhaseRule.  Improve JavaDoc.  Use null instead of "" to represent
no value for before/after.

Modified:
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/context/ConfigurationContext.java
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/PhaseRule.java
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/engine/Handler.java
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/engine/Phase.java
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/phaseresolver/PhaseHolder.java
    webservices/axis2/trunk/java/modules/kernel/test/org/apache/axis2/phaserule/AddingHandlerToEachPhaseTest.java

Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/context/ConfigurationContext.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/context/ConfigurationContext.java?view=diff&rev=533506&r1=533505&r2=533506
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/context/ConfigurationContext.java
(original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/context/ConfigurationContext.java
Sun Apr 29 07:02:29 2007
@@ -101,11 +101,7 @@
 
     private static boolean shouldClusterBeInitiated(ClusterManager clusterManager) {
         Parameter param = clusterManager.getParameter(ClusteringConstants.AVOID_INITIATION_KEY);
-        if (param != null && JavaUtils.isTrueExplicitly(param.getValue())) {
-            return false;
-        } else {
-            return true;
-        }
+        return !(param != null && JavaUtils.isTrueExplicitly(param.getValue()));
     }
 
     protected void finalize() throws Throwable {

Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/PhaseRule.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/PhaseRule.java?view=diff&rev=533506&r1=533505&r2=533506
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/PhaseRule.java
(original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/PhaseRule.java
Sun Apr 29 07:02:29 2007
@@ -17,6 +17,8 @@
 
 package org.apache.axis2.description;
 
+import org.apache.axis2.phaseresolver.PhaseException;
+
 import java.io.Serializable;
 
 /**
@@ -53,14 +55,9 @@
      * Constructor PhaseRule.
      */
     public PhaseRule() {
-        this.before = "";
-        this.after = "";
-        this.phaseName = "";
     }
 
     public PhaseRule(String phaseName) {
-        this.before = "";
-        this.after = "";
         this.phaseName = phaseName;
     }
 
@@ -110,27 +107,29 @@
     }
 
     /**
-     * Method setAfter.
+     * Set the "after" name for this rule.
      *
-     * @param after
+     * @param after the name of the "after" handler
      */
     public void setAfter(String after) {
+        if ("".equals(after)) after = null;
         this.after = after;
     }
 
     /**
-     * Method setBefore.
+     * Set the "before" name for this rule.
      *
-     * @param before
+     * @param before the name of the "before" handler
      */
     public void setBefore(String before) {
+        if ("".equals(before)) before = null;
         this.before = before;
     }
 
     /**
      * Method setPhaseFirst.
      *
-     * @param phaseFirst
+     * @param phaseFirst true if this rule defines the first Handler in a Phase
      */
     public void setPhaseFirst(boolean phaseFirst) {
         this.phaseFirst = phaseFirst;
@@ -139,7 +138,7 @@
     /**
      * Method setPhaseLast.
      *
-     * @param phaseLast
+     * @param phaseLast true if this rule defines the last Handler in a Phase
      */
     public void setPhaseLast(boolean phaseLast) {
         this.phaseLast = phaseLast;
@@ -148,9 +147,27 @@
     /**
      * Method setPhaseName.
      *
-     * @param phaseName
+     * @param phaseName the name of the Phase
      */
     public void setPhaseName(String phaseName) {
         this.phaseName = phaseName;
+    }
+
+    /**
+     * Validate "sane" rules - cannot have both phaseFirst/phaseLast and before/after
+     *
+     * @throws PhaseException if phaseFirst/phaseLast is set along with before/after
+     */
+    public void validate() throws PhaseException {
+        if (before != null || after != null) {
+            if (phaseFirst) {
+                throw new PhaseException(
+                        "Invalid PhaseRule (phaseFirst is set along with before/after)");
+            }
+            if (phaseLast) {
+                throw new PhaseException(
+                        "Invalid PhaseRule (phaseLast is set along with before/after)");
+            }
+        }
     }
 }

Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/engine/Handler.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/engine/Handler.java?view=diff&rev=533506&r1=533505&r2=533506
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/engine/Handler.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/engine/Handler.java Sun
Apr 29 07:02:29 2007
@@ -23,7 +23,11 @@
 import org.apache.axis2.description.Parameter;
 
 /**
- * Interface Handler
+ * A Handler represents a piece of message processing functionality in Axis2.
+ *
+ * Handlers are combined into chains and phases in order to provide customizable functionality
+ * such as security, reliability, etc.  Handlers must be multi-thread safe and should keep
all
+ * their state in Context objects (see the org.apache.axis2.context package).
  */
 public interface Handler {
 
@@ -35,11 +39,11 @@
     public void cleanup();
 
     /**
-     * Method init.
+     * Initialize a Handler.
      *
-     * @param handlerdesc
+     * @param handlerDesc the HandlerDescription for this Handler
      */
-    public void init(HandlerDescription handlerdesc);
+    public void init(HandlerDescription handlerDesc);
 
     /**
      * This method will be called on each registered handler when a message
@@ -76,24 +80,24 @@
     public void flowComplete(MessageContext msgContext);
 
     /**
-     * Gets the HandlerDescription of a handler. This is used as an input to get phaseRule
of a handler.
+     * Gets the HandlerDescription of a handler.
      *
      * @return Returns HandlerDescription.
      */
     public HandlerDescription getHandlerDesc();
 
     /**
-     * Method getName.
+     * Return the name of this Handler
      *
-     * @return Returns String
+     * @return the handler's name as a String
      */
     public String getName();
 
     /**
-     * Method getParameter.
+     * Get a Parameter from this Handler
      *
-     * @param name
-     * @return Returns Parameter.
+     * @param name the name of the desired value
+     * @return the Parameter, or null.
      */
     public Parameter getParameter(String name);
 

Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/engine/Phase.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/engine/Phase.java?view=diff&rev=533506&r1=533505&r2=533506
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/engine/Phase.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/engine/Phase.java Sun
Apr 29 07:02:29 2007
@@ -38,26 +38,6 @@
     public static final String ALL_PHASES = "*";
 
     /**
-     * Field BOTH_BEFORE_AFTER
-     */
-    private static final int BOTH_BEFORE_AFTER = 0;
-
-    /**
-     * Field BEFORE
-     */
-    private static final int BEFORE = 1;
-
-    /**
-     * Field ANYWHERE
-     */
-    private static final int ANYWHERE = 3;
-
-    /**
-     * Field AFTER
-     */
-    private static final int AFTER = 2;
-
-    /**
      * Field log
      */
     private static final Log log = LogFactory.getLog(Phase.class);
@@ -78,23 +58,26 @@
     private String phaseName;
 
     /**
-     * Field phasefirstset
+     * Field phaseFirstSet
      */
-    private boolean phasefirstset;
+    private boolean phaseFirstSet;
 
     /**
-     * Field phaselastset
+     * Field phaseLastSet
      */
-    private boolean phaselastset;
+    private boolean phaseLastSet;
 
+    /**
+     * Default constructor
+     */
     public Phase() {
         this(null);
     }
 
     /**
-     * Constructor Phase.
+     * Create a named Phase
      *
-     * @param phaseName
+     * @param phaseName the name for this Phase
      */
     public Phase(String phaseName) {
         handlers = new ArrayList();
@@ -102,15 +85,15 @@
     }
 
     /**
-     * Adds handler to the collection.
+     * Add a handler to the Phase.
      *
-     * @param handler
+     * @param handler the Handler to add
      */
     public void addHandler(Handler handler) {
         log.debug("Handler " + handler.getName() + " added to Phase " + phaseName);
 
-        if (phaselastset) {
-            //handlers.size() can not be 0 , since when setting phase last it is always >
0
+        if (phaseLastSet) {
+            // handlers.size() can not be 0 , since when setting phase last it is always
> 0
             if (handlers.size() == 1) {
                 handlers.add(0, handler);
             } else {
@@ -122,235 +105,152 @@
     }
 
     /**
-     * Method addHandler.
+     * Add a HandlerDescription to the Phase
      *
-     * @param handler
-     * @throws PhaseException
+     * @param handlerDesc the HandlerDescription to add
+     * @throws PhaseException if there is a problem
      */
-    public void addHandler(HandlerDescription handler) throws PhaseException {
+    public void addHandler(HandlerDescription handlerDesc) throws PhaseException {
         Iterator handlers_itr = getHandlers().iterator();
 
         while (handlers_itr.hasNext()) {
             Handler hand = (Handler) handlers_itr.next();
-            HandlerDescription handlerDesc = hand.getHandlerDesc();
-            if (handler.getName().equals(handlerDesc.getName())) {
+            HandlerDescription thisDesc = hand.getHandlerDesc();
+            if (handlerDesc.getName().equals(thisDesc.getName())) {
                 return;
             }
         }
+
         if (isOneHandler) {
-            // TODO : should we allow both phaseFirst and phaseLast to be true for one Handler??
             throw new PhaseException(this.getPhaseName()
                     + "can only have one handler, since there is a "
-                    + "handler with both phaseFirst and PhaseLast true ");
+                    + "handler with both phaseFirst and phaseLast true ");
         }
 
-        if (handler.getRules().isPhaseFirst() && handler.getRules().isPhaseLast())
{
+        if (handlerDesc.getRules().isPhaseFirst() && handlerDesc.getRules().isPhaseLast())
{
             if (handlers.size() > 0) {
                 throw new PhaseException(this.getPhaseName()
-                        + " can not have more than one handler "
-                        + handler.getName()
-                        + " is invalid or incorrect phase rules");
+                        + " already contains Handlers, and "
+                        + handlerDesc.getName()
+                        + " cannot therefore be both phaseFirst and phaseLast.");
             } else {
-                handlers.add(handler.getHandler());
+                handlers.add(handlerDesc.getHandler());
                 isOneHandler = true;
             }
-        } else if (handler.getRules().isPhaseFirst()) {
-            setPhaseFirst(handler.getHandler());
-        } else if (handler.getRules().isPhaseLast()) {
-            setPhaseLast(handler.getHandler());
+        } else if (handlerDesc.getRules().isPhaseFirst()) {
+            setPhaseFirst(handlerDesc.getHandler());
+        } else if (handlerDesc.getRules().isPhaseLast()) {
+            setPhaseLast(handlerDesc.getHandler());
         } else {
-            insertHandler(handler);
+            insertHandler(handlerDesc);
         }
     }
 
     /**
-     * Method addHandler.
+     * Add a Handler at a particular index within the Phase.
      *
-     * @param handler
-     * @param index
+     * If we have a Phase with (H1, H2), calling addHandler(H3, 1) will result in (H1, H3,
H2)
+     *
+     * @param handler the Handler to add
+     * @param index the position in the Phase at which to place the Handler
      */
     public void addHandler(Handler handler, int index) {
-        log.debug("Handler " + handler.getName() + "Added to place " + index + " At the Phase
"
-                + phaseName);
+        if (log.isDebugEnabled()) {
+            log.debug("Handler " + handler.getName() + " inserted at position " + index +
+                    " of Phase " + phaseName);
+        }
         handlers.add(index, handler);
     }
 
+    /**
+     * Confirm that all post-conditions of this Phase are met.  After all Handlers in a
+     * Phase are invoke()d, this method will be called.  Subclasses should override it in
order
+     * to confirm that the purpose of the given Phase has been acheived.
+     *
+     * @param msgContext the active MessageContext
+     * @throws AxisFault if a post-condition has not been met, or other problems occur
+     */
     public void checkPostConditions(MessageContext msgContext) throws AxisFault {
-
         // Default version does nothing
     }
 
+    /**
+     * Check the preconditions for a Phase.  This method will be called when the Phase is
+     * invoked, BEFORE any Handlers are invoked.  Subclasses should override it in order
+     * to confirm that necessary preconditions are met before the Phase does its work.  They
+     * should throw an appropriate AxisFault if not.
+     *
+     * @param msgContext the active MessageContext
+     * @throws AxisFault if a precondition is not met, or in case of other problem
+     */
     public void checkPreconditions(MessageContext msgContext) throws AxisFault {
-
         // Default version does nothing
     }
 
     public void cleanup() {
-
         // Default version does nothing
     }
 
     public void init(HandlerDescription handlerdesc) {
-
         // Default version does nothing
     }
 
-    /**
-     * Method insertAfter.
-     *
-     * @param handler
-     */
-    private void insertAfter(Handler handler) throws PhaseException {
-        String afterName = handler.getHandlerDesc().getRules().getAfter();
-
-        for (int i = 0; i < handlers.size(); i++) {
-            Handler temphandler = (Handler) handlers.get(i);
-
-            if (temphandler.getName().equals(afterName)) {
-                if (phaselastset && (i == handlers.size() - 1)) {
-                    throw new PhaseException("Can't insert handler after handler '"
-                            + temphandler.getName()
-                            + "', which is marked phaseLast");
-                }
-
-                handlers.add(i + 1, handler);
-
-                return;
-            }
-        }
+    private void insertHandler(HandlerDescription handlerDesc) throws PhaseException {
+        Handler handler = handlerDesc.getHandler();
+        PhaseRule rules = handler.getHandlerDesc().getRules();
+        String beforeName = rules.getBefore();
+        String afterName = rules.getAfter();
 
-        if (handlers.size() > 0) {
-            handlers.add(0, handler);
-        } else {
+        // If we don't care where it goes, tack it on at the end
+        if (beforeName == null && afterName == null) {
             handlers.add(handler);
+            return;
         }
-    }
-
-    /**
-     * Method insertBefore.
-     *
-     * @param handler
-     */
-    private void insertBefore(Handler handler) throws PhaseException {
-        String beforename = handler.getHandlerDesc().getRules().getBefore();
-
-        //we keep going foward, till the before handler is found, if we do not find him just
add the handler
-        //once we found the before handler
 
-        int beforeHandlerIndex = -1;
+        // Otherwise walk the list and find the right place to put it
+        int beforeIndex = -1, afterIndex = -1;
 
         for (int i = 0; i < handlers.size(); i++) {
-            Handler temphandler = (Handler) handlers.get(i);
+            Handler tempHandler = (Handler) handlers.get(i);
 
-            if (temphandler.getName().equals(beforename)) {
-                if (i == 0) {
-                    if (phasefirstset) {
-                        throw new PhaseException("Can't insert handler before handler '"
-                                + temphandler.getName()
-                                + "', which is marked phaseFirst");
-                    }
+            if ((beforeName != null) && (beforeIndex == -1)) {
+                if (tempHandler.getName().equals(beforeName)) {
+                    // Found the "before" handler
+                    beforeIndex = i;
                 }
-                beforeHandlerIndex = i;
-                break;
             }
-        }
 
-        if (beforeHandlerIndex >= 0) {
-            //java arraylist does the shift for us
-            handlers.add(beforeHandlerIndex, handler);
-        } else {
-            handlers.add(handler);
-        }
-    }
-
-    /**
-     * This method assume that both the before and after cant be a same hander
-     * that does not check inside this , it should check befor calling this method
-     *
-     * @param handler
-     * @throws PhaseException
-     */
-    private void insertBeforeandAfter(Handler handler) throws PhaseException {
-        int before = -1;
-        int after = -1;
-        String beforeName = handler.getHandlerDesc().getRules().getBefore();
-        String afterName = handler.getHandlerDesc().getRules().getAfter();
-
-        for (int i = 0; i < handlers.size(); i++) {
-            Handler temphandler = (Handler) handlers.get(i);
-
-            if (afterName.equals(temphandler.getName())) {
-                after = i;
-            } else {
-                if (beforeName.equals(temphandler.getName())) {
-                    before = i;
+            if ((afterName != null) && (afterIndex == -1)) {
+                if (tempHandler.getName().equals(afterName)) {
+                    // Found the "before" handler
+                    afterIndex = i;
                 }
             }
-
-            if ((after >= 0) && (before >= 0)) {
-                break;
-            }
         }
 
-        // no point of continue since both the before and after index has found
-        if (after > before) {
-
-            // TODO fix me Deepal , (have to check this)
-            throw new PhaseException("incorrect handler order for "
-                    + handler.getHandlerDesc().getName());
+        if (phaseFirstSet && beforeIndex == 0) {
+            throw new PhaseException("Can't insert handler before handler '"
+                    + beforeName
+                    + "', which is marked phaseFirst");
         }
 
-        if ((before == -1) && (after == -1)) {
-            addHandler(handler);
-
-            return;
+        if (phaseLastSet && afterIndex == (handlers.size() - 1)) {
+            throw new PhaseException("Can't insert handler after handler '"
+                    + afterName
+                    + "', which is marked phaseLast");
         }
 
-        if (before == -1) {
-            addHandler(handler);
-
-            return;
-        }
-
-        if (after == -1) {
-            if (phasefirstset && (before == 0)) {
-                throw new PhaseException("Can't insert handler before handler '"
-                        + ((Handler) handlers.get(0)).getName()
-                        + "', which is marked phaseFirst");
-            }
-        }
-
-        handlers.add(before, handler);
-    }
-
-    private void insertHandler(HandlerDescription handlerDesc) throws PhaseException {
-        Handler handler = handlerDesc.getHandler();
-        int type = getBeforeAfter(handler);
-
-        switch (type) {
-            case BOTH_BEFORE_AFTER : {
-                insertBeforeandAfter(handler);
-                break;
-            }
-            case BEFORE : {
-                insertBefore(handler);
-                break;
-            }
-            case AFTER : {
-                insertAfter(handler);
-                break;
-            }
-            case ANYWHERE : {
-                addHandler(handler);
-                break;
-            }
+        if (beforeIndex > -1) {
+            handlers.add(beforeIndex, handler);
+        } else {
+            handlers.add(handler);
         }
     }
 
     /**
-     * invokes all the handlers in this Phase
+     * Invoke all the handlers in this Phase
      *
-     * @param msgctx
+     * @param msgctx the current MessageContext
      * @return An InvocationResponse that indicates what
      *         the next step in the message processing should be.
      * @throws org.apache.axis2.AxisFault
@@ -406,8 +306,8 @@
                     phaseName + "\"");
         }
 
-        /*This will be non-zero if we failed during execution of one of the
-     *handlers in this phase*/
+        // This will be non-zero if we failed during execution of one of the
+        // handlers in this phase
         int currentHandlerIndex = msgContext.getCurrentPhaseIndex();
         if (currentHandlerIndex == 0) {
             currentHandlerIndex = handlers.size();
@@ -433,37 +333,6 @@
         return this.getPhaseName();
     }
 
-    /**
-     * Method getBeforeAfter.
-     *
-     * @param handler
-     * @return Returns AFTER or ANYWHERE or BOTH_BEFORE_AFTER
-     * @throws org.apache.axis2.phaseresolver.PhaseException
-     *
-     */
-    private int getBeforeAfter(Handler handler) throws PhaseException {
-        PhaseRule rules = handler.getHandlerDesc().getRules();
-        String beforeRules = rules.getBefore();
-        String afterRules = rules.getAfter();
-        if ((!"".equals(beforeRules))
-                && (!"".equals(afterRules))) {
-            if (beforeRules.equals(
-                    afterRules)) {
-                throw new PhaseException(
-                        "Both before and after cannot be the same for this handler"
-                                + handler.getName());
-            }
-
-            return BOTH_BEFORE_AFTER;
-        } else if (!"".equals(beforeRules)) {
-            return BEFORE;
-        } else if (!"".equals(afterRules)) {
-            return AFTER;
-        } else {
-            return ANYWHERE;
-        }
-    }
-
     public int getHandlerCount() {
         return handlers.size();
     }
@@ -501,78 +370,66 @@
     }
 
     /**
-     * Method setPhaseFirst.
+     * Add a Handler to the Phase in the very first position, and ensure no other Handler
+     * will come before it.
      *
-     * @param phaseFirst
-     * @throws PhaseException
+     * @param handler the Handler to add
+     * @throws PhaseException if another Handler is already set as phaseFirst
      */
-    public void setPhaseFirst(Handler phaseFirst) throws PhaseException {
-        if (phasefirstset) {
+    public void setPhaseFirst(Handler handler) throws PhaseException {
+        if (phaseFirstSet) {
             throw new PhaseException("PhaseFirst has been set already, cannot have two"
-                    + " phaseFirst Handler for same phase " + this.getPhaseName());
+                    + " phaseFirst Handlers for Phase '" + this.getPhaseName() + "'");
         } else {
-            handlers.add(0, phaseFirst);
-            phasefirstset = true;
-
-            // TODO: move this error check to where we read the rules
-            if (getBeforeAfter(phaseFirst) != ANYWHERE) {
-                throw new PhaseException("Handler with PhaseFirst can not have "
-                        + "any before or after proprty error in "
-                        + phaseFirst.getName());
-            }
+            handlers.add(0, handler);
+            phaseFirstSet = true;
         }
     }
 
     /**
-     * Method setPhaseLast.
+     * Add a Handler to the Phase in the very last position, and ensure no other Handler
+     * will come after it.
      *
-     * @param phaseLast
-     * @throws PhaseException
+     * @param handler the Handler to add
+     * @throws PhaseException if another Handler is already set as phaseLast
      */
-    public void setPhaseLast(Handler phaseLast) throws PhaseException {
-        if (phaselastset) {
+    public void setPhaseLast(Handler handler) throws PhaseException {
+        if (phaseLastSet) {
             throw new PhaseException("PhaseLast already has been set,"
                     + " cannot have two PhaseLast Handler for same phase "
                     + this.getPhaseName());
         }
 
         if (handlers.size() == 0) {
-            handlers.add(phaseLast);
+            handlers.add(handler);
         } else {
-            handlers.add(handlers.size() - 1, phaseLast);
+            handlers.add(handlers.size() - 1, handler);
         }
 
-        phaselastset = true;
-
-        // TODO: Move this check to where we read the rules
-        if (getBeforeAfter(phaseLast) != ANYWHERE) {
-            throw new PhaseException("Handler with PhaseLast property "
-                    + "can not have any before or after property error in "
-                    + phaseLast.getName());
-        }
+        phaseLastSet = true;
     }
 
     /**
-     * To remove a given hnadler from a phase
+     * Remove a given Handler from a phase using a HandlerDescription
      *
-     * @param handler
+     * @param handlerDesc the HandlerDescription to remove
      */
-    public void removeHandler(HandlerDescription handler) {
-        if (handlers.remove(handler.getHandler())) {
-            PhaseRule rule = handler.getRules();
+    public void removeHandler(HandlerDescription handlerDesc) {
+        if (handlers.remove(handlerDesc.getHandler())) {
+            PhaseRule rule = handlerDesc.getRules();
             if (rule.isPhaseFirst()) {
-                phasefirstset = false;
+                phaseFirstSet = false;
             }
             if (rule.isPhaseLast()) {
-                phaselastset = false;
+                phaseLastSet = false;
             }
             if (rule.isPhaseFirst() && rule.isPhaseLast()) {
                 isOneHandler = false;
             }
-            log.debug("removed handler " + handler.getName()
+            log.debug("removed handler " + handlerDesc.getName()
                     + " from the phase " + phaseName);
         } else {
-            log.debug("unable to remove handler " + handler.getName()
+            log.debug("unable to remove handler " + handlerDesc.getName()
                     + " from the phase " + phaseName);
         }
     }

Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/phaseresolver/PhaseHolder.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/phaseresolver/PhaseHolder.java?view=diff&rev=533506&r1=533505&r2=533506
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/phaseresolver/PhaseHolder.java
(original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/phaseresolver/PhaseHolder.java
Sun Apr 29 07:02:29 2007
@@ -19,6 +19,7 @@
 
 import org.apache.axis2.deployment.DeploymentErrorMsgs;
 import org.apache.axis2.description.HandlerDescription;
+import org.apache.axis2.description.PhaseRule;
 import org.apache.axis2.engine.Phase;
 import org.apache.axis2.i18n.Messages;
 
@@ -51,7 +52,12 @@
      * @throws PhaseException
      */
     public void addHandler(HandlerDescription handlerDesc) throws PhaseException {
-        String phaseName = handlerDesc.getRules().getPhaseName();
+        PhaseRule rule = handlerDesc.getRules();
+
+        // Make sure this rule makes sense (throws PhaseException if not)
+        rule.validate();
+
+        String phaseName = rule.getPhaseName();
         if (Phase.ALL_PHASES.equals(phaseName)) {
             handlerDesc.getRules().setBefore("");
             handlerDesc.getRules().setAfter("");

Modified: webservices/axis2/trunk/java/modules/kernel/test/org/apache/axis2/phaserule/AddingHandlerToEachPhaseTest.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/test/org/apache/axis2/phaserule/AddingHandlerToEachPhaseTest.java?view=diff&rev=533506&r1=533505&r2=533506
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/test/org/apache/axis2/phaserule/AddingHandlerToEachPhaseTest.java
(original)
+++ webservices/axis2/trunk/java/modules/kernel/test/org/apache/axis2/phaserule/AddingHandlerToEachPhaseTest.java
Sun Apr 29 07:02:29 2007
@@ -28,20 +28,16 @@
 */
 
 public class AddingHandlerToEachPhaseTest extends AbstractTestCase {
-
-    AddingHandlerToEachPhaseTest phaserul;
-    AxisConfiguration axisSytem;
+    AxisConfiguration axisConfig;
 
     public AddingHandlerToEachPhaseTest(String testName) {
         super(testName);
     }
 
     public void testPhaseRules() throws Exception {
-        super.setUp();
         //TODO fix me
-        phaserul = new AddingHandlerToEachPhaseTest("");
-        axisSytem = new AxisConfiguration();
-        ArrayList inPhase = axisSytem.getGlobalInFlow();
+        axisConfig = new AxisConfiguration();
+        ArrayList inPhase = axisConfig.getGlobalInFlow();
         Phase transportIN = new Phase("TransportIn");
         Phase preDispatch = new Phase("PreDispatch");
         DispatchPhase dispatchPhase = new DispatchPhase();
@@ -80,9 +76,8 @@
     public void testPhaseRulesWithPhaseFirst() throws Exception {
         super.setUp();
         //TODO fix me
-        phaserul = new AddingHandlerToEachPhaseTest("");
-        axisSytem = new AxisConfiguration();
-        ArrayList inPhase = axisSytem.getGlobalInFlow();
+        axisConfig = new AxisConfiguration();
+        ArrayList inPhase = axisConfig.getGlobalInFlow();
         Phase transportIN = new Phase("TransportIn");
         Phase preDispatch = new Phase("PreDispatch");
         DispatchPhase dispatchPhase = new DispatchPhase();
@@ -114,11 +109,9 @@
     }
 
     public void testPhaseRulesWithAfter() throws Exception {
-        super.setUp();
         //TODO fix me
-        phaserul = new AddingHandlerToEachPhaseTest("");
-        axisSytem = new AxisConfiguration();
-        ArrayList inPhase = axisSytem.getGlobalInFlow();
+        axisConfig = new AxisConfiguration();
+        ArrayList inPhase = axisConfig.getGlobalInFlow();
         Phase transportIN = new Phase("TransportIn");
         Phase preDispatch = new Phase("PreDispatch");
         DispatchPhase dispatchPhase = new DispatchPhase();
@@ -134,7 +127,6 @@
         hm.setHandler(h1);
         hm.getRules().setPhaseName("*");
         hm.getRules().setPhaseFirst(true);
-        hm.getRules().setAfter("nothing");
 
         PhaseHolder ph = new PhaseHolder(inPhase);
         ph.addHandler(hm);
@@ -142,7 +134,7 @@
             Phase phase = (Phase) inPhase.get(i);
             ArrayList hnadles = phase.getHandlers();
             Handler handler = (Handler) hnadles.get(0);
-            assertEquals("", handler.getHandlerDesc().getRules().getAfter());
+            assertNull(handler.getHandlerDesc().getRules().getAfter());
         }
     }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org


Mime
View raw message