You are viewing a plain text version of this content. The canonical link for it is here.
Posted to axis-cvs@ws.apache.org by sa...@apache.org on 2005/11/12 01:47:05 UTC

svn commit: r332686 - in /webservices/axis2/trunk/c: include/axis2_handler_desc.h include/axis2_msg_ctx.h include/axis2_phase.h modules/core/engine/src/Makefile.am modules/core/engine/src/Makefile.in modules/core/engine/src/phase.c

Author: samisa
Date: Fri Nov 11 16:46:50 2005
New Revision: 332686

URL: http://svn.apache.org/viewcvs?rev=332686&view=rev
Log:
Initial compiling version of phase

Added:
    webservices/axis2/trunk/c/include/axis2_phase.h
    webservices/axis2/trunk/c/modules/core/engine/src/phase.c
Modified:
    webservices/axis2/trunk/c/include/axis2_handler_desc.h
    webservices/axis2/trunk/c/include/axis2_msg_ctx.h
    webservices/axis2/trunk/c/modules/core/engine/src/Makefile.am
    webservices/axis2/trunk/c/modules/core/engine/src/Makefile.in

Modified: webservices/axis2/trunk/c/include/axis2_handler_desc.h
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/c/include/axis2_handler_desc.h?rev=332686&r1=332685&r2=332686&view=diff
==============================================================================
--- webservices/axis2/trunk/c/include/axis2_handler_desc.h (original)
+++ webservices/axis2/trunk/c/include/axis2_handler_desc.h Fri Nov 11 16:46:50 2005
@@ -101,7 +101,9 @@
  * @param qname qname, can be NULL
  */
 AXIS2_DECLARE(axis2_handler_desc_t*) axis2_handler_desc_create(axis2_env_t **env, axis2_qname_t *qname);
-    
+
+#define AXIS2_HANDLER_DESC_GET_HANDLER(handler_desc, env) ((handler_desc)->ops->get_handler(handler_desc, env))
+#define AXIS2_HANDLER_DESC_SET_HANDLER(handler_desc, env, handler) ((handler_desc)->ops->set_handler(handler_desc, env, handler))
 #define AXIS2_HANDLER_DESC_GET_RULES(handler_desc, env) ((handler_desc)->ops->get_rules(handler_desc, env))
 #define AXIS2_HANDLER_DESC_SET_RULES(handler_desc, env, rules) ((handler_desc)->ops->set_rules(handler_desc, env, rules))
 #define AXIS2_HANDLER_DESC_GET_QNAME(handler_desc, env) ((handler_desc)->ops->get_qname(handler_desc, env))

Modified: webservices/axis2/trunk/c/include/axis2_msg_ctx.h
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/c/include/axis2_msg_ctx.h?rev=332686&r1=332685&r2=332686&view=diff
==============================================================================
--- webservices/axis2/trunk/c/include/axis2_msg_ctx.h (original)
+++ webservices/axis2/trunk/c/include/axis2_msg_ctx.h Fri Nov 11 16:46:50 2005
@@ -35,14 +35,14 @@
  * @{
  */
     
-typedef struct axis2_msg_ctx_ops_s axis2_msg_ctx_ops_t;
-typedef struct axis2_msg_ctx_s axis2_msg_ctx_t;    
+typedef struct axis2_msg_ctx_ops axis2_msg_ctx_ops_t;
+typedef struct axis2_msg_ctx axis2_msg_ctx_t;    
     
 /** 
  * @brief Message Context operations struct
  * Encapsulator struct for operations of axis2_msg_ctx
  */  
-struct axis2_msg_ctx_ops_s
+struct axis2_msg_ctx_ops
 {
     /** 
      * Deallocate memory
@@ -50,13 +50,23 @@
      */
     axis2_status_t (AXIS2_CALL *free)(axis2_msg_ctx_t *msg_ctx,
                                         axis2_env_t **env); 
+   /**
+    *
+    */
+    axis2_status_t (AXIS2_CALL *set_paused_phase_name)(axis2_msg_ctx_t *msg_ctx,
+                                        axis2_env_t **env, axis2_char_t *name); 
+   /**
+    *
+    */    
+    axis2_bool_t (AXIS2_CALL *is_paused)(axis2_msg_ctx_t *msg_ctx,
+                                         axis2_env_t **env); 
 };
 
 /** 
  * @brief Message Context struct
   *	Axis2 Message Context
  */
-struct axis2_msg_ctx_s
+struct axis2_msg_ctx
 {
     axis2_msg_ctx_ops_t *ops;    
 };
@@ -66,7 +76,9 @@
     
 /************************** Start of function macros **************************/
 
-#define AXIS2_MSG_CTX_FREE(env, msg_ctx) (msg_ctx->ops->free (env, msg_ctx));
+#define AXIS2_MSG_CTX_FREE(msg_ctx, env) ((msg_ctx)->ops->free (msg_ctx, env))
+#define AXIS2_MSG_CTX_SET_PAUSED_PHASE_NAME(msg_ctx, env, name) ((msg_ctx)->ops->set_paused_phase_name(msg_ctx, env, name))
+#define AXIS2_MSG_CTX_IS_PAUSED(msg_ctx, env) ((msg_ctx)->ops->is_paused (msg_ctx, env))
 
 /************************** End of function macros ****************************/    
 

Added: webservices/axis2/trunk/c/include/axis2_phase.h
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/c/include/axis2_phase.h?rev=332686&view=auto
==============================================================================
--- webservices/axis2/trunk/c/include/axis2_phase.h (added)
+++ webservices/axis2/trunk/c/include/axis2_phase.h Fri Nov 11 16:46:50 2005
@@ -0,0 +1,194 @@
+/*
+ * Copyright 2004,2005 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.
+ */
+
+#ifndef AXIS2_PHASE_H
+#define AXIS2_PHASE_H
+
+/**
+ * @file axis2_phase.h
+ * @brief Axis2 phase interface
+ */
+
+#include <axis2_defines.h>
+#include <axis2_env.h>
+#include <axis2_handler.h>
+#include <axis2_handler_desc.h>
+#include <axis2_array_list.h>
+#include <axis2_qname.h>
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+    /** Both Before and After */
+    static const int AXIS2_BOTH_BEFORE_AFTER = 0;    
+    /** Before */
+    static const int AXIS2_BEFORE = 1;    
+    /** After */
+    static const int AXIS2_AFTER = 2;    
+    /** Anywhere */
+    static const int AXIS2_ANYWHERE = 3;
+    
+    struct axis2_phase_ops;
+    struct axis2_phase;
+    struct axis2_msg_ctx;
+
+/**
+ * @defgroup axis2_phase Phases
+ * @ingroup axis2_core_phases
+ * @{
+ */
+
+/**
+ *   \brief Phase operations struct
+ */
+ AXIS2_DECLARE_DATA   typedef struct axis2_phase_ops
+    {
+        /**
+         * adds given handler to the specified position in the phase array lisst
+         *
+         * @param hander
+         * @param index
+         */
+         axis2_status_t (AXIS2_CALL *add_handler_at)(struct axis2_phase *phase, 
+                                      axis2_env_t **env,
+                                      int index, 
+                                      axis2_handler_t *hander);
+        /**
+        * add to next empty phase
+        *
+        * @param phase
+        */
+        axis2_status_t (AXIS2_CALL *add_handler)(struct axis2_phase *phase, 
+                                     axis2_env_t **env,
+                                     axis2_handler_t *handler);
+        /**
+         * If need to see how this works look at the stack!
+         *
+         * @param msg_ctx
+         * @throws org.apache.axis2.AxisFault
+         */
+        axis2_status_t (AXIS2_CALL *invoke)(struct axis2_phase *phase, 
+                                          axis2_env_t **env,
+                                          struct axis2_msg_ctx *msg_ctx);
+        /**
+         * phase name accessor
+         * @return returns the phase name.
+         */
+        axis2_char_t* (AXIS2_CALL *get_name)(struct axis2_phase *phase, 
+                                      axis2_env_t **env);
+         
+        int (AXIS2_CALL *get_handler_count)(struct axis2_phase *phase, 
+                                      axis2_env_t **env);
+        
+        /**
+         * Method setPhaseFirst
+         *
+         * @param first_handler
+         * @throws PhaseException
+         */
+        axis2_status_t (AXIS2_CALL *set_first_handler)(struct axis2_phase *phase, 
+                                      axis2_env_t **env, axis2_handler_t * handler);
+        /**
+         * Method setPhaseLast
+         *
+         * @param last_handler
+         * @throws PhaseException
+         */
+        axis2_status_t (AXIS2_CALL *set_last_handler)(struct axis2_phase *phase, 
+                                      axis2_env_t **env, axis2_handler_t * handler);
+        /**
+         * Method add_handler
+         *
+         * @param handler
+         * @throws PhaseException
+         */
+        axis2_status_t (AXIS2_CALL *add_handler_desc)(struct axis2_phase *phase, 
+                                      axis2_env_t **env, axis2_handler_desc_t * handler_desc);
+        /**
+         * Method axis2_phase_insert_before
+         *
+         * @param handler
+         */
+        axis2_status_t (AXIS2_CALL *insert_before)(struct axis2_phase *phase, axis2_env_t **env, axis2_handler_t * handler);
+        
+        /**
+         * Method axis2_phase_insert_after
+         *
+         * @param handler
+         */
+        axis2_status_t (AXIS2_CALL *insert_after)(struct axis2_phase *phase, axis2_env_t **env, axis2_handler_t * handler);
+        
+        /**
+         * This method assume that both the before and after cant be a same hander
+         * That condition is not checked by this function. It should be checked befor calling this function
+         *
+         * @param handler
+         * @throws PhaseException
+         */
+        axis2_status_t (AXIS2_CALL *insert_before_and_after)(struct axis2_phase *phase, axis2_env_t **env, axis2_handler_t * handler);
+        
+        axis2_status_t (AXIS2_CALL *insert_handler_desc)(struct axis2_phase *phase, axis2_env_t **env, axis2_handler_desc_t * handler_desc);
+        
+        /**
+         * To get the all the handlers in the phase
+         *
+         * @return
+         */
+        axis2_array_list_t* (AXIS2_CALL *get_handlers)(struct axis2_phase *phase, axis2_env_t **env);
+        axis2_status_t (AXIS2_CALL *invoke_start_from_handler)(struct axis2_phase *phase, axis2_env_t **env, axis2_qname_t *qname, struct axis2_msg_ctx *msg_ctx);
+        axis2_status_t (AXIS2_CALL *free)(struct axis2_phase *phase, 
+                                                       axis2_env_t **env);
+    } axis2_phase_ops_t;
+	
+   /** 
+    * \brief Phase struct
+    */
+    typedef struct axis2_phase
+    {
+        /** Phase related operations */
+        axis2_phase_ops_t *ops;
+    } axis2_phase_t;
+
+
+/**
+ * creates phase struct
+ */
+AXIS2_DECLARE(axis2_phase_t*) axis2_phase_create(axis2_env_t **env, axis2_char_t *phase_name);
+
+#define AXIS2_PHASE_ADD_HANDLER_AT(phase, env, handler) ((phase)->ops->add_handler_at(phase, env, handler))
+#define AXIS2_PHASE_ADD_HANDLER(phase, env, handler) ((phase)->ops->add_handler(phase, env, handler))
+#define AXIS2_PHASE_ADD_HANDLER_DESC(phase, env, handler_desc) ((phase)->ops->add_handler_desc(phase, env, handler_desc))
+#define AXIS2_PHASE_INVOKE(phase, env, msg_ctx) ((phase)->ops->invoke(phase, env, msg_ctx))
+#define AXIS2_PHASE_GET_NAME(phase, env) ((phase)->ops->get_name(phase, env))
+#define AXIS2_PHASE_GET_HANDLER_COUNT(phase, env) ((phase)->ops->get_handler_count(phase, env))
+#define AXIS2_PHASE_SET_FIRST_HANDLER(phase, env, handler) ((phase)->ops->set_first_handler(phase, env, handler))
+#define AXIS2_PHASE_SET_LAST_HANDLER(phase, env, handler) ((phase)->ops->set_last_handler(phase, env, handler))
+#define AXIS2_PHASE_INSERT_BEFORE(phase, env, handler) ((phase)->ops->insert_before(phase, env, handler))
+#define AXIS2_PHASE_INSERT_AFTER(phase, env, handler) ((phase)->ops->insert_after(phase, env, handler))
+#define AXIS2_PHASE_INSERT_BEFORE_AND_AFTER(phase, env, handler) ((phase)->ops->insert_before_and_after(phase, env, handler))
+#define AXIS2_PHASE_INSERT_HANDLER_DESC(phase, env, handler_desc) ((phase)->ops->insert_handler_desc(phase, env, handler_desc))
+#define AXIS2_PHASE_GET_HANDLERS(phase, env) ((phase)->ops->get_handlers(phase, env))
+#define AXIS2_PHASE_INVOKE_START_FROM_HANDLER(phase, env, qname, msg_ctx) ((phase)->ops->invoke_start_from_handler(phase, env, qname, msg_ctx))
+#define AXIS2_PHASE_FREE(phase, env) ((phase)->ops->free(phase, env))
+       
+/** @} */
+    
+#ifdef __cplusplus
+}
+#endif
+
+#endif    /* AXIS2_PHASE_H */

Modified: webservices/axis2/trunk/c/modules/core/engine/src/Makefile.am
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/c/modules/core/engine/src/Makefile.am?rev=332686&r1=332685&r2=332686&view=diff
==============================================================================
--- webservices/axis2/trunk/c/modules/core/engine/src/Makefile.am (original)
+++ webservices/axis2/trunk/c/modules/core/engine/src/Makefile.am Fri Nov 11 16:46:50 2005
@@ -1,6 +1,6 @@
 lib_LTLIBRARIES = libaxis2_engine.la
 AM_CPPFLAGS = $(CPPFLAGS)
-libaxis2_engine_la_SOURCES = handler.c msg_recv.c engine_config.c
+libaxis2_engine_la_SOURCES = handler.c msg_recv.c engine_config.c phase.c
 
 libaxis2_engine_la_LIBADD = $(LDFLAGS)
 INCLUDES = -I${CUTEST_HOME}/include \

Modified: webservices/axis2/trunk/c/modules/core/engine/src/Makefile.in
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/c/modules/core/engine/src/Makefile.in?rev=332686&r1=332685&r2=332686&view=diff
==============================================================================
--- webservices/axis2/trunk/c/modules/core/engine/src/Makefile.in (original)
+++ webservices/axis2/trunk/c/modules/core/engine/src/Makefile.in Fri Nov 11 16:46:50 2005
@@ -64,7 +64,7 @@
 am__DEPENDENCIES_1 =
 libaxis2_engine_la_DEPENDENCIES = $(am__DEPENDENCIES_1)
 am_libaxis2_engine_la_OBJECTS = handler.lo msg_recv.lo \
-	engine_config.lo
+	engine_config.lo phase.lo
 libaxis2_engine_la_OBJECTS = $(am_libaxis2_engine_la_OBJECTS)
 DEFAULT_INCLUDES = -I. -I$(srcdir) -I$(top_builddir)
 depcomp = $(SHELL) $(top_srcdir)/conftools/depcomp
@@ -191,7 +191,7 @@
 target_vendor = @target_vendor@
 lib_LTLIBRARIES = libaxis2_engine.la
 AM_CPPFLAGS = $(CPPFLAGS)
-libaxis2_engine_la_SOURCES = handler.c msg_recv.c engine_config.c
+libaxis2_engine_la_SOURCES = handler.c msg_recv.c engine_config.c phase.c
 libaxis2_engine_la_LIBADD = $(LDFLAGS)
 INCLUDES = -I${CUTEST_HOME}/include \
             -I$(top_builddir)/modules/xml/guththila/src \
@@ -270,6 +270,7 @@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/engine_config.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/handler.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/msg_recv.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/phase.Plo@am__quote@
 
 .c.o:
 @am__fastdepCC_TRUE@	if $(COMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" -c -o $@ $<; \

Added: webservices/axis2/trunk/c/modules/core/engine/src/phase.c
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/c/modules/core/engine/src/phase.c?rev=332686&view=auto
==============================================================================
--- webservices/axis2/trunk/c/modules/core/engine/src/phase.c (added)
+++ webservices/axis2/trunk/c/modules/core/engine/src/phase.c Fri Nov 11 16:46:50 2005
@@ -0,0 +1,1035 @@
+/*
+ * Copyright 2004,2005 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.
+ */
+
+#include <axis2_string.h>
+#include <axis2_phase.h>
+#include <axis2_array_list.h>
+#include <axis2_msg_ctx.h>
+#include <axis2.h>
+
+
+typedef struct axis2_phase_impl 
+{
+    /** phase */
+	axis2_phase_t phase;
+    /** phase name */
+    axis2_char_t *name;    
+    /** array list of phases */
+    axis2_array_list_t* handlers;    
+    /** first handler of phase */
+    axis2_handler_t *first_handler;    
+    /** first handler of phase set? */
+    axis2_bool_t first_handler_set;
+    /** last handler of phase */
+    axis2_handler_t *last_handler;    
+    /** last handler of phase set? */
+    axis2_bool_t last_handler_set;    
+    /** 
+     * hanlder_first and handler_last are the same hanlder
+     * that is for this phase there is only one handler
+     */
+    axis2_bool_t is_one_handler;
+} axis2_phase_impl_t;
+ 
+
+/** Interface to implementation conversion macro */
+#define AXIS2_INTF_TO_IMPL(phase) ((axis2_phase_impl_t *)phase)
+
+
+axis2_status_t AXIS2_CALL axis2_phase_add_handler_at(struct axis2_phase *phase, 
+                              axis2_env_t **env,
+                              int index, 
+                              axis2_handler_t *handler);
+axis2_status_t AXIS2_CALL axis2_phase_add_handler(struct axis2_phase *phase, 
+                             axis2_env_t **env,
+                             axis2_handler_t *handler);
+axis2_status_t AXIS2_CALL axis2_phase_invoke(struct axis2_phase *phase, 
+                                  axis2_env_t **env,
+                                  axis2_msg_ctx_t *msg_ctx);
+axis2_char_t* AXIS2_CALL axis2_phase_get_name(struct axis2_phase *phase, 
+                              axis2_env_t **env);
+int AXIS2_CALL axis2_phase_get_handler_count(struct axis2_phase *phase, 
+                              axis2_env_t **env); 
+int AXIS2_CALL _axis2_phase_get_before_after(axis2_handler_t *handler, axis2_env_t **env);
+axis2_status_t AXIS2_CALL axis2_phase_set_first_handler(struct axis2_phase *phase, 
+                              axis2_env_t **env, axis2_handler_t * handler);
+axis2_status_t AXIS2_CALL axis2_phase_set_last_handler(struct axis2_phase *phase, 
+                              axis2_env_t **env, axis2_handler_t * handler);
+axis2_status_t AXIS2_CALL axis2_phase_add_handler_desc(struct axis2_phase *phase, 
+                              axis2_env_t **env, axis2_handler_desc_t * handler_desc);
+axis2_bool_t AXIS2_CALL _axis2_phase_is_valid_before(axis2_phase_t *phase, axis2_env_t **env, axis2_handler_t * handler);
+axis2_bool_t AXIS2_CALL _axis2_phase_is_valid_after(axis2_phase_t *phase, axis2_env_t **env, axis2_handler_t * handler);
+axis2_status_t AXIS2_CALL axis2_phase_insert_before(axis2_phase_t *phase, axis2_env_t **env, axis2_handler_t * handler);
+axis2_status_t AXIS2_CALL axis2_phase_insert_after(axis2_phase_t *phase, axis2_env_t **env, axis2_handler_t * handler) ;
+axis2_status_t AXIS2_CALL axis2_phase_insert_before_and_after(axis2_phase_t *phase, axis2_env_t **env, axis2_handler_t * handler);
+axis2_status_t AXIS2_CALL axis2_phase_insert_handler_desc(axis2_phase_t *phase, axis2_env_t **env, axis2_handler_desc_t * handler_desc);
+axis2_array_list_t* AXIS2_CALL axis2_phase_get_handlers(axis2_phase_t *phase, axis2_env_t **env);
+axis2_status_t AXIS2_CALL axis2_phase_invoke_start_from_handler(axis2_phase_t *phase, axis2_env_t **env, axis2_qname_t *qname, axis2_msg_ctx_t *msg_ctx) ;
+axis2_status_t AXIS2_CALL axis2_phase_free (struct axis2_phase *phase, 
+                                               axis2_env_t **env);
+
+
+axis2_phase_t* AXIS2_CALL axis2_phase_create(axis2_env_t **env, axis2_char_t *phase_name) 
+{
+    axis2_phase_impl_t *phase_impl = NULL;
+    
+    AXIS2_ENV_CHECK(env, NULL);
+    
+    phase_impl = AXIS2_MALLOC( (*env)->allocator, sizeof(axis2_phase_impl_t) );
+    if (!phase_impl)
+    { 
+        AXIS2_ERROR_SET((*env)->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
+        return NULL;        
+    }
+
+    phase_impl->name = NULL;
+    phase_impl->handlers = NULL;
+    phase_impl->first_handler = NULL;    
+    phase_impl->first_handler_set = AXIS2_FALSE;
+    phase_impl->last_handler = NULL;    
+    phase_impl->last_handler_set = AXIS2_FALSE;    
+    phase_impl->is_one_handler = AXIS2_FALSE;
+    
+	phase_impl->handlers = axis2_array_list_create(env, 10);
+    if (!(phase_impl->handlers))
+    {
+        /** error is already set by last method array list container create */
+        axis2_phase_free(&(phase_impl->phase), env);
+        return NULL;        
+    }    
+    
+    if (phase_name)
+    {
+        phase_impl->name = AXIS2_STRDUP(phase_name, env);
+        if (!(phase_impl->name))
+        {
+            AXIS2_ERROR_SET((*env)->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
+            axis2_phase_free(&(phase_impl->phase), env);
+            return NULL;        
+        }
+    }
+
+    /* initialize operations */
+    phase_impl->phase.ops = NULL;
+    phase_impl->phase.ops  = AXIS2_MALLOC( (*env)->allocator, sizeof(axis2_phase_ops_t) );
+    if (!phase_impl->phase.ops)
+    {
+        AXIS2_ERROR_SET((*env)->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
+        axis2_phase_free(&(phase_impl->phase), env);
+        return NULL;        
+    }
+
+    phase_impl->phase.ops->add_handler_at = axis2_phase_add_handler_at;
+    phase_impl->phase.ops->add_handler = axis2_phase_add_handler;
+    phase_impl->phase.ops->invoke = axis2_phase_invoke;
+    phase_impl->phase.ops->get_name = axis2_phase_get_name;
+    phase_impl->phase.ops->get_handler_count = axis2_phase_get_handler_count;
+    phase_impl->phase.ops->set_first_handler = axis2_phase_set_first_handler;
+    phase_impl->phase.ops->set_last_handler = axis2_phase_set_last_handler;
+    phase_impl->phase.ops->add_handler_desc = axis2_phase_add_handler_desc;
+    phase_impl->phase.ops->insert_before = axis2_phase_insert_before;
+    phase_impl->phase.ops->insert_after = axis2_phase_insert_after;
+    phase_impl->phase.ops->insert_before_and_after = axis2_phase_insert_before_and_after;
+    phase_impl->phase.ops->insert_handler_desc = axis2_phase_insert_handler_desc;
+    phase_impl->phase.ops->get_handlers = axis2_phase_get_handlers;
+    phase_impl->phase.ops->invoke_start_from_handler = axis2_phase_invoke_start_from_handler;
+    phase_impl->phase.ops->free = axis2_phase_free;
+
+    return &(phase_impl->phase);
+}
+
+axis2_status_t AXIS2_CALL axis2_phase_add_handler_at(struct axis2_phase *phase, 
+                              axis2_env_t **env,
+                              int index, 
+                              axis2_handler_t *handler) 
+{
+    axis2_phase_impl_t *phase_impl = NULL;
+    char message[1024];
+    
+    AXIS2_FUNC_PARAM_CHECK(phase, env, AXIS2_FAILURE);
+    
+    phase_impl = AXIS2_INTF_TO_IMPL(phase);
+    
+    sprintf(message, "axis2_handler_t *%s added to the index %d of the phase %s",
+                     AXIS2_QNAME_GET_LOCALPART(AXIS2_HANDLER_GET_NAME(handler, env), env), 
+                     index, 
+                     phase_impl->name);
+    
+    AXIS2_LOG(env, message);
+    
+    return AXIS2_ARRAY_LIST_ADD_AT(phase_impl->handlers, env, index, handler);
+}
+
+axis2_status_t AXIS2_CALL axis2_phase_add_handler(struct axis2_phase *phase, 
+                             axis2_env_t **env,
+                             axis2_handler_t *handler) 
+{
+    axis2_phase_impl_t *phase_impl = NULL;
+    char message[1024];
+    
+    AXIS2_FUNC_PARAM_CHECK(phase, env, AXIS2_FAILURE);
+    
+    phase_impl = AXIS2_INTF_TO_IMPL(phase);
+    
+    sprintf(message, "Handler %s added to phase %s",
+                     AXIS2_QNAME_GET_LOCALPART(AXIS2_HANDLER_GET_NAME(handler, env), env), 
+                     phase_impl->name);
+    
+    AXIS2_LOG(env, message);
+    
+    return AXIS2_ARRAY_LIST_ADD(phase_impl->handlers, env, handler);
+}
+
+axis2_status_t AXIS2_CALL axis2_phase_invoke(struct axis2_phase *phase, 
+                                  axis2_env_t **env,
+                                  axis2_msg_ctx_t *msg_ctx)
+{
+    axis2_phase_impl_t *phase_impl = NULL;
+    char message[1024];
+    int index = 0, size = 0;
+    axis2_status_t status = AXIS2_SUCCESS;
+    
+    AXIS2_FUNC_PARAM_CHECK(phase, env, AXIS2_FAILURE);
+    
+    phase_impl = AXIS2_INTF_TO_IMPL(phase);
+    
+    AXIS2_MSG_CTX_SET_PAUSED_PHASE_NAME(msg_ctx, env, phase_impl->name);
+    /* If phase first handler is there then it should run first */
+    
+    if (phase_impl->first_handler)
+    {
+        if (AXIS2_MSG_CTX_IS_PAUSED(msg_ctx, env))
+        {
+            return AXIS2_SUCCESS;
+        } 
+        else 
+        {
+            sprintf(message, "Invoke the first handler %s within the phase %s",
+                     AXIS2_QNAME_GET_LOCALPART(AXIS2_HANDLER_GET_NAME(phase_impl->first_handler, env), env), 
+                     phase_impl->name);
+            AXIS2_LOG(env, message);
+            status = AXIS2_HANDLER_INVOKE(phase_impl->first_handler, env, msg_ctx);
+            if (status != AXIS2_SUCCESS)
+                return status;
+        }
+    }
+    /*Invoking the rest of handlers except first_handler and last_handler */
+    size = AXIS2_ARRAY_LIST_SIZE(phase_impl->handlers, env);
+    
+    while (index < size ) 
+    {
+        if (AXIS2_MSG_CTX_IS_PAUSED(msg_ctx, env)) 
+        {
+            break;
+        } 
+        else 
+        {
+            axis2_handler_t *handler = (axis2_handler_t*) AXIS2_ARRAY_LIST_GET(phase_impl->handlers, env, index);
+            if (handler) 
+            {
+                sprintf(message, "Invoke the handler %s within the phase %s",
+                         AXIS2_QNAME_GET_LOCALPART(AXIS2_HANDLER_GET_NAME(handler, env), env), 
+                         phase_impl->name);
+                AXIS2_LOG(env, message);
+                status = AXIS2_HANDLER_INVOKE(handler, env, msg_ctx);
+                if (status != AXIS2_SUCCESS)
+                    return status;                
+                /* index increment should be after the invoke as if the invocation 
+                   failed this handler is taken care of and no need to revoke agien */
+                index++;
+            }
+        }
+    }
+    
+    /*If phase last handler is there invoke it here*/
+    if (phase_impl->last_handler) 
+    {
+        if (AXIS2_MSG_CTX_IS_PAUSED(msg_ctx, env))
+        {
+            return AXIS2_SUCCESS;
+        } 
+        else 
+        {
+            sprintf(message, "Invoke the last handler %s within the phase %s",
+                     AXIS2_QNAME_GET_LOCALPART(AXIS2_HANDLER_GET_NAME(phase_impl->last_handler, env), env), 
+                     phase_impl->name);
+            AXIS2_LOG(env, message);
+            status = AXIS2_HANDLER_INVOKE(phase_impl->last_handler, env, msg_ctx);
+            if (status != AXIS2_SUCCESS)
+                return status;
+        }
+    }
+    
+    return AXIS2_SUCCESS;
+}
+
+
+axis2_char_t* AXIS2_CALL axis2_phase_get_name(struct axis2_phase *phase, 
+                              axis2_env_t **env) 
+{
+    AXIS2_FUNC_PARAM_CHECK(phase, env, NULL);    
+    return AXIS2_INTF_TO_IMPL(phase)->name;
+}
+
+int AXIS2_CALL axis2_phase_get_handler_count(struct axis2_phase *phase, 
+                              axis2_env_t **env) 
+{
+    AXIS2_FUNC_PARAM_CHECK(phase, env, AXIS2_FAILURE);    
+    return AXIS2_ARRAY_LIST_SIZE(AXIS2_INTF_TO_IMPL(phase)->handlers, env );
+}
+
+
+/*/////////////////////////////////////////////////////////////// FROM PhaseMetaData /////////*/
+
+int AXIS2_CALL _axis2_phase_get_before_after(axis2_handler_t *handler, axis2_env_t **env)
+{
+    axis2_char_t *before = NULL, *after = NULL;
+    axis2_handler_desc_t *handler_desc = NULL;
+    axis2_phase_rule_t *rules = NULL;
+    
+    AXIS2_FUNC_PARAM_CHECK(handler, env, AXIS2_FAILURE);
+    
+    handler_desc = AXIS2_HANDLER_GET_HANDLER_DESC(handler, env);
+    if (!handler_desc)
+    {
+        AXIS2_ERROR_SET((*env)->error, AXIS2_ERROR_INVALID_NULL_PARAM, AXIS2_FAILURE);
+        return AXIS2_FAILURE;
+    }
+    
+    rules = AXIS2_HANDLER_DESC_GET_RULES(handler_desc, env);
+    if (!rules)
+    {
+        AXIS2_ERROR_SET((*env)->error, AXIS2_ERROR_INVALID_NULL_PARAM, AXIS2_FAILURE);
+        return AXIS2_FAILURE;
+    }
+    
+    before = AXIS2_PHASE_RULE_GET_BEFORE(rules, env);
+    after = AXIS2_PHASE_RULE_GET_AFTER(rules, env);
+    
+    if (before && after)
+    {
+        if (AXIS2_STRCMP(before, after) == 0 )
+        {
+            AXIS2_ERROR_SET((*env)->error, AXIS2_ERROR_BEFORE_AFTER_HANDLERS_SAME, AXIS2_FAILURE);
+            return AXIS2_FAILURE;
+        }
+        return AXIS2_BOTH_BEFORE_AFTER;
+    }
+    else if (before) 
+    {
+        return AXIS2_BEFORE;
+    } 
+    else if (after) 
+    {
+        return AXIS2_AFTER;
+    } 
+    else 
+    {
+        return AXIS2_ANYWHERE;
+    }
+}
+
+axis2_status_t AXIS2_CALL axis2_phase_set_first_handler(struct axis2_phase *phase, 
+                              axis2_env_t **env, axis2_handler_t * handler)
+{
+    axis2_phase_impl_t *phase_impl = NULL;
+    
+    AXIS2_FUNC_PARAM_CHECK(phase, env, AXIS2_FAILURE);
+    
+    phase_impl = AXIS2_INTF_TO_IMPL(phase);
+    
+    if (phase_impl->first_handler_set)
+    {
+        AXIS2_ERROR_SET((*env)->error, AXIS2_ERROR_PHASE_FIRST_HANDLER_ALREADY_SET, AXIS2_FAILURE);
+        return AXIS2_FAILURE;
+    }
+    else
+    {
+        if (_axis2_phase_get_before_after(handler, env) != AXIS2_ANYWHERE)
+        {
+            AXIS2_ERROR_SET((*env)->error, AXIS2_ERROR_INVALID_PHASE_FIRST_HANDLER, AXIS2_FAILURE);
+            return AXIS2_FAILURE;            
+        }
+        phase_impl->first_handler = handler;
+        phase_impl->first_handler_set = AXIS2_TRUE;
+    }
+    
+    return AXIS2_SUCCESS;
+}
+
+axis2_status_t AXIS2_CALL axis2_phase_set_last_handler(struct axis2_phase *phase, 
+                              axis2_env_t **env, axis2_handler_t * handler)
+{
+    axis2_phase_impl_t *phase_impl = NULL;
+    
+    AXIS2_FUNC_PARAM_CHECK(phase, env, AXIS2_FAILURE);
+    
+    phase_impl = AXIS2_INTF_TO_IMPL(phase);
+
+    if (phase_impl->last_handler_set)
+    {
+        AXIS2_ERROR_SET((*env)->error, AXIS2_ERROR_PHASE_LAST_HANDLER_ALREADY_SET, AXIS2_FAILURE);
+        return AXIS2_FAILURE;
+    }
+    else
+    {
+        if (_axis2_phase_get_before_after(handler, env) != AXIS2_ANYWHERE)
+        {
+            AXIS2_ERROR_SET((*env)->error, AXIS2_ERROR_INVALID_PHASE_LAST_HANDLER, AXIS2_FAILURE);
+            return AXIS2_FAILURE;            
+        }
+        phase_impl->last_handler = handler;
+        phase_impl->last_handler_set = AXIS2_TRUE;
+    }
+    
+    return AXIS2_SUCCESS;
+}
+
+axis2_status_t AXIS2_CALL axis2_phase_add_handler_desc(struct axis2_phase *phase, 
+                              axis2_env_t **env, axis2_handler_desc_t * handler_desc)
+{
+    axis2_phase_impl_t *phase_impl = NULL;
+    axis2_phase_rule_t *rules = NULL;
+    axis2_handler_t *handler = NULL;
+    axis2_status_t status = AXIS2_SUCCESS;
+    axis2_bool_t first = AXIS2_FALSE, last = AXIS2_FALSE;
+    
+    AXIS2_FUNC_PARAM_CHECK(phase, env, AXIS2_FAILURE);
+    
+    phase_impl = AXIS2_INTF_TO_IMPL(phase); 
+
+    if (phase_impl->is_one_handler) 
+    {
+        AXIS2_ERROR_SET((*env)->error, AXIS2_ERROR_PHASE_ADD_HANDLER_INVALID, AXIS2_FAILURE);
+        return AXIS2_FAILURE;
+    } 
+    else 
+    {
+        rules = AXIS2_HANDLER_DESC_GET_RULES(handler_desc, env);
+        if (!rules)
+        {
+            AXIS2_ERROR_SET((*env)->error, AXIS2_ERROR_INVALID_NULL_PARAM, AXIS2_FAILURE);
+            return AXIS2_FAILURE;
+        }
+        
+        first = AXIS2_PHASE_RULE_IS_PHASE_FIRST(rules, env);
+        last = AXIS2_PHASE_RULE_IS_PHASE_LAST(rules, env);
+        
+        if (first && last)
+        {
+            if (AXIS2_ARRAY_LIST_SIZE(phase_impl->handlers, env) > 0 )
+            {
+                AXIS2_ERROR_SET((*env)->error, AXIS2_ERROR_INVALID_HANDLER_RULES, AXIS2_FAILURE);
+                return AXIS2_FAILURE;
+            }
+            
+            handler = AXIS2_HANDLER_DESC_GET_HANDLER(handler_desc, env);
+            if (!handler)
+            {
+                AXIS2_ERROR_SET((*env)->error, AXIS2_ERROR_INVALID_NULL_PARAM, AXIS2_FAILURE);
+                return AXIS2_FAILURE;
+            }    
+            
+            status = AXIS2_ARRAY_LIST_ADD(phase_impl->handlers, env, handler);
+            if (status == AXIS2_SUCCESS)
+                phase_impl->is_one_handler = AXIS2_TRUE;
+            return status;            
+        }
+        else if (first)
+        {
+            handler = AXIS2_HANDLER_DESC_GET_HANDLER(handler_desc, env);
+            if (!handler)
+            {
+                AXIS2_ERROR_SET((*env)->error, AXIS2_ERROR_INVALID_NULL_PARAM, AXIS2_FAILURE);
+                return AXIS2_FAILURE;
+            }    
+            return axis2_phase_set_first_handler(phase, env, handler);
+        }
+        else if (last)
+        {
+            handler = AXIS2_HANDLER_DESC_GET_HANDLER(handler_desc, env);
+            if (!handler)
+            {
+                AXIS2_ERROR_SET((*env)->error, AXIS2_ERROR_INVALID_NULL_PARAM, AXIS2_FAILURE);
+                return AXIS2_FAILURE;
+            }    
+            return axis2_phase_set_last_handler(phase, env, handler);
+        }
+        else
+        {
+            handler = AXIS2_HANDLER_DESC_GET_HANDLER(handler_desc, env);
+            if (!handler)
+            {
+                AXIS2_ERROR_SET((*env)->error, AXIS2_ERROR_INVALID_NULL_PARAM, AXIS2_FAILURE);
+                return AXIS2_FAILURE;
+            }    
+            return axis2_phase_insert_handler_desc(phase, env, handler_desc);
+        }
+    }
+}
+
+axis2_bool_t AXIS2_CALL _axis2_phase_is_valid_before(axis2_phase_t *phase, axis2_env_t **env, axis2_handler_t * handler)
+{
+    axis2_phase_impl_t *phase_impl = NULL;
+    axis2_phase_rule_t *rules = NULL;
+    axis2_handler_desc_t *handler_desc = NULL;    
+    axis2_char_t *first_handler_name = NULL, *before = NULL;
+    
+    AXIS2_FUNC_PARAM_CHECK(phase, env, AXIS2_FAILURE);
+    
+    phase_impl = AXIS2_INTF_TO_IMPL(phase); 
+    
+    if (phase_impl->first_handler)
+    {
+        handler_desc = AXIS2_HANDLER_GET_HANDLER_DESC(phase_impl->first_handler, env);
+        if (!handler_desc)
+            return AXIS2_TRUE;
+        
+        first_handler_name = AXIS2_QNAME_GET_LOCALPART(AXIS2_HANDLER_DESC_GET_QNAME(handler_desc, env), env);
+        
+        if (!first_handler_name)
+            return AXIS2_TRUE;
+        
+        handler_desc = AXIS2_HANDLER_GET_HANDLER_DESC(handler, env);
+        if (!handler_desc)
+            return AXIS2_TRUE;
+        
+        rules = AXIS2_HANDLER_DESC_GET_RULES(handler_desc, env);
+        if (!rules)
+            return AXIS2_TRUE;
+        
+        before = AXIS2_PHASE_RULE_GET_BEFORE(rules, env);
+        if (!before)
+            return AXIS2_TRUE;
+        
+        if (AXIS2_STRCMP(first_handler_name, before) == 0)
+            return AXIS2_FALSE;
+        else
+            return AXIS2_TRUE;
+            
+    }
+    return AXIS2_TRUE;
+}
+
+axis2_bool_t AXIS2_CALL _axis2_phase_is_valid_after(axis2_phase_t *phase, axis2_env_t **env, axis2_handler_t * handler)
+{
+    axis2_phase_impl_t *phase_impl = NULL;
+    axis2_phase_rule_t *rules = NULL;
+    axis2_handler_desc_t *handler_desc = NULL;    
+    axis2_char_t *last_handler_name = NULL, *after = NULL;
+    
+    AXIS2_FUNC_PARAM_CHECK(phase, env, AXIS2_FAILURE);
+    
+    phase_impl = AXIS2_INTF_TO_IMPL(phase); 
+    
+    if (phase_impl->last_handler)
+    {
+        handler_desc = AXIS2_HANDLER_GET_HANDLER_DESC(phase_impl->last_handler, env);
+        if (!handler_desc)
+            return AXIS2_TRUE;
+        
+        last_handler_name = AXIS2_QNAME_GET_LOCALPART(AXIS2_HANDLER_DESC_GET_QNAME(handler_desc, env), env);
+        
+        if (!last_handler_name)
+            return AXIS2_TRUE;
+        
+        handler_desc = AXIS2_HANDLER_GET_HANDLER_DESC(handler, env);
+        if (!handler_desc)
+            return AXIS2_TRUE;
+        
+        rules = AXIS2_HANDLER_DESC_GET_RULES(handler_desc, env);
+        if (!rules)
+            return AXIS2_TRUE;
+        
+        after = AXIS2_PHASE_RULE_GET_AFTER(rules, env);
+        if (!after)
+            return AXIS2_TRUE;
+        
+        if (AXIS2_STRCMP(last_handler_name, after) == 0)
+            return AXIS2_FALSE;
+        else
+            return AXIS2_TRUE;
+            
+    }
+    return AXIS2_TRUE;    
+}
+
+axis2_status_t AXIS2_CALL axis2_phase_insert_before(axis2_phase_t *phase, axis2_env_t **env, axis2_handler_t * handler) 
+{
+    axis2_phase_impl_t *phase_impl = NULL;
+    axis2_phase_rule_t *rules = NULL;
+    axis2_handler_desc_t *handler_desc = NULL;    
+    axis2_char_t *handler_name = NULL, *before = NULL;
+    int i = 0;
+    int size = 0;
+    
+    AXIS2_FUNC_PARAM_CHECK(phase, env, AXIS2_FAILURE);
+    
+    phase_impl = AXIS2_INTF_TO_IMPL(phase); 
+    
+    handler_desc = AXIS2_HANDLER_GET_HANDLER_DESC(handler, env);
+    if (!handler_desc)
+    {
+        AXIS2_ERROR_SET((*env)->error, AXIS2_ERROR_INVALID_NULL_PARAM, AXIS2_FAILURE);
+        return AXIS2_FAILURE;        
+    }
+    
+    rules = AXIS2_HANDLER_DESC_GET_RULES(handler_desc, env);
+    if (!rules)
+    {
+        AXIS2_ERROR_SET((*env)->error, AXIS2_ERROR_INVALID_NULL_PARAM, AXIS2_FAILURE);
+        return AXIS2_FAILURE;
+    }
+   
+    before = AXIS2_PHASE_RULE_GET_BEFORE(rules, env);
+    if (!before)
+    {
+        AXIS2_ERROR_SET((*env)->error, AXIS2_ERROR_INVALID_NULL_PARAM, AXIS2_FAILURE);
+        return AXIS2_FAILURE;
+    }
+    
+    if (phase_impl->last_handler)
+    {
+        handler_desc = AXIS2_HANDLER_GET_HANDLER_DESC(phase_impl->last_handler, env);
+        if (!handler_desc)
+        {
+            AXIS2_ERROR_SET((*env)->error, AXIS2_ERROR_INVALID_HANDLER_STATE, AXIS2_FAILURE);
+            return AXIS2_FAILURE;
+        }
+        
+        handler_name = AXIS2_QNAME_GET_LOCALPART(AXIS2_HANDLER_DESC_GET_QNAME(handler_desc, env), env);
+        if (!handler_name)
+        {
+            AXIS2_ERROR_SET((*env)->error, AXIS2_ERROR_INVALID_HANDLER_STATE, AXIS2_FAILURE);
+            return AXIS2_FAILURE;
+        }
+        
+        if (AXIS2_STRCMP(before, handler_name) == 0 )
+        {
+            return AXIS2_ARRAY_LIST_ADD(phase_impl->handlers, env, handler);
+        }
+    }
+
+    size = AXIS2_ARRAY_LIST_SIZE(phase_impl->handlers, env);
+    
+    for (i = 0; i < size; i++) 
+    {
+        axis2_handler_t * temp_handler = (axis2_handler_t *) AXIS2_ARRAY_LIST_GET(phase_impl->handlers, env, i);
+        if (temp_handler)
+        {
+            handler_desc = AXIS2_HANDLER_GET_HANDLER_DESC(temp_handler, env);
+            if (!handler_desc)
+            {
+                AXIS2_ERROR_SET((*env)->error, AXIS2_ERROR_INVALID_HANDLER_STATE, AXIS2_FAILURE);
+                return AXIS2_FAILURE;
+            }
+            
+            handler_name = AXIS2_QNAME_GET_LOCALPART(AXIS2_HANDLER_DESC_GET_QNAME(handler_desc, env), env);
+            if (!handler_name)
+            {
+                AXIS2_ERROR_SET((*env)->error, AXIS2_ERROR_INVALID_HANDLER_STATE, AXIS2_FAILURE);
+                return AXIS2_FAILURE;
+            }
+            
+            if (AXIS2_STRCMP(before, handler_name) == 0 )
+            {
+                /* The following logic is used in Java code, but for me it looks like there is something wrong
+                if (i == 0)
+                    return AXIS2_ARRAY_LIST_ADD_AT(phase_impl->handlers, env, i, handler);
+                else
+                    return AXIS2_ARRAY_LIST_ADD_AT(phase_impl->handlers, env, i - 1, handler);
+                */
+                return AXIS2_ARRAY_LIST_ADD_AT(phase_impl->handlers, env, i, handler);
+            }
+        }     
+    }
+    /* add as the last handler */
+    return AXIS2_ARRAY_LIST_ADD(phase_impl->handlers, env, handler);
+}
+
+axis2_status_t AXIS2_CALL axis2_phase_insert_after(axis2_phase_t *phase, axis2_env_t **env, axis2_handler_t * handler) 
+{
+    axis2_phase_impl_t *phase_impl = NULL;
+    axis2_phase_rule_t *rules = NULL;
+    axis2_handler_desc_t *handler_desc = NULL;    
+    axis2_char_t *handler_name = NULL, *after = NULL;
+    int i = 0;
+    int size = 0;
+    
+    AXIS2_FUNC_PARAM_CHECK(phase, env, AXIS2_FAILURE);
+    
+    phase_impl = AXIS2_INTF_TO_IMPL(phase); 
+    
+    handler_desc = AXIS2_HANDLER_GET_HANDLER_DESC(handler, env);
+    if (!handler_desc)
+    {
+        AXIS2_ERROR_SET((*env)->error, AXIS2_ERROR_INVALID_NULL_PARAM, AXIS2_FAILURE);
+        return AXIS2_FAILURE;        
+    }
+    
+    rules = AXIS2_HANDLER_DESC_GET_RULES(handler_desc, env);
+    if (!rules)
+    {
+        AXIS2_ERROR_SET((*env)->error, AXIS2_ERROR_INVALID_NULL_PARAM, AXIS2_FAILURE);
+        return AXIS2_FAILURE;
+    }
+   
+    after = AXIS2_PHASE_RULE_GET_AFTER(rules, env);
+    if (!after)
+    {
+        AXIS2_ERROR_SET((*env)->error, AXIS2_ERROR_INVALID_NULL_PARAM, AXIS2_FAILURE);
+        return AXIS2_FAILURE;
+    }
+
+    if (phase_impl->first_handler)
+    {
+        handler_desc = AXIS2_HANDLER_GET_HANDLER_DESC(phase_impl->first_handler, env);
+        if (!handler_desc)
+        {
+            AXIS2_ERROR_SET((*env)->error, AXIS2_ERROR_INVALID_HANDLER_STATE, AXIS2_FAILURE);
+            return AXIS2_FAILURE;
+        }
+        
+        handler_name = AXIS2_QNAME_GET_LOCALPART(AXIS2_HANDLER_DESC_GET_QNAME(handler_desc, env), env);
+        if (!handler_name)
+        {
+            AXIS2_ERROR_SET((*env)->error, AXIS2_ERROR_INVALID_HANDLER_STATE, AXIS2_FAILURE);
+            return AXIS2_FAILURE;
+        }
+        
+        if (AXIS2_STRCMP(after, handler_name) == 0 )
+        {
+            return AXIS2_ARRAY_LIST_ADD_AT(phase_impl->handlers, env, 0, handler);
+        }
+    }
+
+    size = AXIS2_ARRAY_LIST_SIZE(phase_impl->handlers, env);
+    
+    for (i = 0; i < size; i++) 
+    {
+        axis2_handler_t * temp_handler = (axis2_handler_t *) AXIS2_ARRAY_LIST_GET(phase_impl->handlers, env, i);
+        if (temp_handler)
+        {
+            handler_desc = AXIS2_HANDLER_GET_HANDLER_DESC(temp_handler, env);
+            if (!handler_desc)
+            {
+                AXIS2_ERROR_SET((*env)->error, AXIS2_ERROR_INVALID_HANDLER_STATE, AXIS2_FAILURE);
+                return AXIS2_FAILURE;
+            }
+            
+            handler_name = AXIS2_QNAME_GET_LOCALPART(AXIS2_HANDLER_DESC_GET_QNAME(handler_desc, env), env);
+            if (!handler_name)
+            {
+                AXIS2_ERROR_SET((*env)->error, AXIS2_ERROR_INVALID_HANDLER_STATE, AXIS2_FAILURE);
+                return AXIS2_FAILURE;
+            }
+            
+            if (AXIS2_STRCMP(after, handler_name) == 0 )
+            {
+                if (i == (size - 1))
+                    return AXIS2_ARRAY_LIST_ADD(phase_impl->handlers, env, handler);
+                else
+                    return AXIS2_ARRAY_LIST_ADD_AT(phase_impl->handlers, env, i + 1, handler);
+            }
+        }
+    }
+
+    if (size > 0)
+        return AXIS2_ARRAY_LIST_ADD_AT(phase_impl->handlers, env, 0, handler);
+    else
+        return AXIS2_ARRAY_LIST_ADD(phase_impl->handlers, env, handler);
+}
+
+axis2_status_t AXIS2_CALL axis2_phase_insert_before_and_after(axis2_phase_t *phase, axis2_env_t **env, axis2_handler_t * handler)
+{
+    int before = -1;
+    int after = -1;
+    axis2_phase_impl_t *phase_impl = NULL;
+    axis2_phase_rule_t *rules = NULL;
+    axis2_handler_desc_t *handler_desc = NULL;    
+    axis2_char_t *before_handler_name = NULL, *after_handler_name = NULL, 
+                 *after_name = NULL, *before_name = NULL, *handler_name = NULL;
+    int i = 0;
+    int size = 0;
+    
+    AXIS2_FUNC_PARAM_CHECK(phase, env, AXIS2_FAILURE);
+    
+    phase_impl = AXIS2_INTF_TO_IMPL(phase); 
+    
+    handler_desc = AXIS2_HANDLER_GET_HANDLER_DESC(handler, env);
+    if (!handler_desc)
+    {
+        AXIS2_ERROR_SET((*env)->error, AXIS2_ERROR_INVALID_NULL_PARAM, AXIS2_FAILURE);
+        return AXIS2_FAILURE;        
+    }
+    
+    rules = AXIS2_HANDLER_DESC_GET_RULES(handler_desc, env);
+    if (!rules)
+    {
+        AXIS2_ERROR_SET((*env)->error, AXIS2_ERROR_INVALID_NULL_PARAM, AXIS2_FAILURE);
+        return AXIS2_FAILURE;
+    }
+   
+    before_name = AXIS2_PHASE_RULE_GET_BEFORE(rules, env);
+    if (!before_name)
+    {
+        AXIS2_ERROR_SET((*env)->error, AXIS2_ERROR_INVALID_NULL_PARAM, AXIS2_FAILURE);
+        return AXIS2_FAILURE;
+    }
+    
+    after_name = AXIS2_PHASE_RULE_GET_AFTER(rules, env);
+    if (!after_name)
+    {
+        AXIS2_ERROR_SET((*env)->error, AXIS2_ERROR_INVALID_NULL_PARAM, AXIS2_FAILURE);
+        return AXIS2_FAILURE;
+    }
+    
+    if (phase_impl->first_handler)
+    {
+        handler_desc = AXIS2_HANDLER_GET_HANDLER_DESC(phase_impl->first_handler, env);
+        if (!handler_desc)
+        {
+            AXIS2_ERROR_SET((*env)->error, AXIS2_ERROR_INVALID_HANDLER_STATE, AXIS2_FAILURE);
+            return AXIS2_FAILURE;
+        }
+        
+        before_handler_name = AXIS2_QNAME_GET_LOCALPART(AXIS2_HANDLER_DESC_GET_QNAME(handler_desc, env), env);
+        if (!handler_name)
+        {
+            AXIS2_ERROR_SET((*env)->error, AXIS2_ERROR_INVALID_HANDLER_STATE, AXIS2_FAILURE);
+            return AXIS2_FAILURE;
+        }
+    }
+    
+    if (phase_impl->last_handler)
+    {
+        handler_desc = AXIS2_HANDLER_GET_HANDLER_DESC(phase_impl->last_handler, env);
+        if (!handler_desc)
+        {
+            AXIS2_ERROR_SET((*env)->error, AXIS2_ERROR_INVALID_HANDLER_STATE, AXIS2_FAILURE);
+            return AXIS2_FAILURE;
+        }
+        
+        after_handler_name = AXIS2_QNAME_GET_LOCALPART(AXIS2_HANDLER_DESC_GET_QNAME(handler_desc, env), env);
+        if (!handler_name)
+        {
+            AXIS2_ERROR_SET((*env)->error, AXIS2_ERROR_INVALID_HANDLER_STATE, AXIS2_FAILURE);
+            return AXIS2_FAILURE;
+        }
+    }
+    
+    if (before_handler_name && after_handler_name)
+    {
+        if (AXIS2_STRCMP(before_handler_name, before_name) == 0 &&
+            AXIS2_STRCMP(after_handler_name, after_name) == 0 )
+        {
+            return AXIS2_ARRAY_LIST_ADD(phase_impl->handlers, env, handler);
+        }
+    }
+    
+    if (after_handler_name)
+    {
+        if (AXIS2_STRCMP(after_handler_name, after_name) == 0 )
+            after = 0;
+    }
+    
+    size = AXIS2_ARRAY_LIST_SIZE(phase_impl->handlers, env);
+    
+    if (after_handler_name)
+    {
+        if (AXIS2_STRCMP(before_handler_name, before_name) == 0 )
+            before = size;
+    }
+    
+    for (i = 0; i < size; i++)
+    {
+        axis2_handler_t * temp_handler = (axis2_handler_t *) AXIS2_ARRAY_LIST_GET(phase_impl->handlers, env, i);
+        if (temp_handler)
+        {
+            handler_desc = AXIS2_HANDLER_GET_HANDLER_DESC(temp_handler, env);
+            if (!handler_desc)
+            {
+                AXIS2_ERROR_SET((*env)->error, AXIS2_ERROR_INVALID_HANDLER_STATE, AXIS2_FAILURE);
+                return AXIS2_FAILURE;
+            }
+            
+            handler_name = AXIS2_QNAME_GET_LOCALPART(AXIS2_HANDLER_DESC_GET_QNAME(handler_desc, env), env);
+            if (!handler_name)
+            {
+                AXIS2_ERROR_SET((*env)->error, AXIS2_ERROR_INVALID_HANDLER_STATE, AXIS2_FAILURE);
+                return AXIS2_FAILURE;
+            }
+            
+            if (AXIS2_STRCMP(handler_name, after_name) == 0 )
+                after = i;
+            if (AXIS2_STRCMP(handler_name, before_name) == 0 )
+                before = i;            
+        }
+
+        if ((after >= 0) && (before >= 0))
+        {
+            /*both the before and after indexes has been found */
+            if (after > before) 
+            {
+                AXIS2_ERROR_SET((*env)->error, AXIS2_ERROR_INVALID_HANDLER_STATE, AXIS2_FAILURE);
+                return AXIS2_FAILURE;
+            } 
+            else 
+            {
+                if (after + 1 < size) 
+                {
+                    return AXIS2_ARRAY_LIST_ADD_AT(phase_impl->handlers, env, after + 1, handler);
+                } 
+                else 
+                {
+                    return AXIS2_ARRAY_LIST_ADD(phase_impl->handlers, env, handler);                    
+                }
+            }
+        }
+    }
+    return AXIS2_ARRAY_LIST_ADD(phase_impl->handlers, env, handler);    
+}
+
+axis2_status_t AXIS2_CALL axis2_phase_insert_handler_desc(axis2_phase_t *phase, axis2_env_t **env, axis2_handler_desc_t * handler_desc)
+{
+    axis2_phase_impl_t *phase_impl = NULL;
+    int type = 0;
+    axis2_handler_t *handler = NULL;
+    axis2_status_t status = AXIS2_FAILURE;
+    
+    AXIS2_FUNC_PARAM_CHECK(phase, env, AXIS2_FAILURE);
+    
+    phase_impl = AXIS2_INTF_TO_IMPL(phase); 
+    
+    handler = AXIS2_HANDLER_DESC_GET_HANDLER(handler_desc, env);
+
+    if (!handler)
+    {
+        AXIS2_ERROR_SET((*env)->error, AXIS2_ERROR_INVALID_NULL_PARAM, AXIS2_FAILURE);
+        return AXIS2_FAILURE;        
+    }
+    
+    if (!_axis2_phase_is_valid_after(phase, env, handler))
+    {
+        AXIS2_ERROR_SET((*env)->error, AXIS2_ERROR_INVALID_HANDLER_STATE, AXIS2_FAILURE);
+        return AXIS2_FAILURE;        
+    }
+    
+    if (!_axis2_phase_is_valid_before(phase, env, handler))
+    {
+        AXIS2_ERROR_SET((*env)->error, AXIS2_ERROR_INVALID_HANDLER_STATE, AXIS2_FAILURE);
+        return AXIS2_FAILURE;        
+    }
+    
+    type = _axis2_phase_get_before_after(handler, env);
+    
+    switch (type) 
+    {
+        case 0: /*AXIS2_BOTH_BEFORE_AFTER:*/
+                status = axis2_phase_insert_before_and_after(phase, env, handler);
+                break;
+        case 1: /*AXIS2_BEFORE:*/
+                status = axis2_phase_insert_before(phase, env, handler);
+                break;
+        case 2: /*AXIS2_AFTER:*/
+                status = axis2_phase_insert_after(phase, env, handler);
+                break;
+        case 3: /*AXIS2_ANYWHERE:*/
+                status = AXIS2_ARRAY_LIST_ADD(phase_impl->handlers, env, handler);    
+                break;
+        default:
+            status = AXIS2_FAILURE;
+            break;
+    }
+    return status;
+}
+
+axis2_array_list_t* AXIS2_CALL axis2_phase_get_handlers(axis2_phase_t *phase, axis2_env_t **env) 
+{
+    AXIS2_FUNC_PARAM_CHECK(phase, env, NULL);    
+    return AXIS2_INTF_TO_IMPL(phase)->handlers;
+}
+
+axis2_status_t AXIS2_CALL axis2_phase_invoke_start_from_handler(axis2_phase_t *phase, axis2_env_t **env, axis2_qname_t *qname, axis2_msg_ctx_t *msg_ctx) 
+{
+    axis2_phase_impl_t *phase_impl = NULL;
+    int size = 0, i = 0;
+    axis2_bool_t found = AXIS2_FALSE;
+    
+    AXIS2_FUNC_PARAM_CHECK(phase, env, AXIS2_FAILURE);
+    
+    phase_impl = AXIS2_INTF_TO_IMPL(phase); 
+    
+    AXIS2_MSG_CTX_SET_PAUSED_PHASE_NAME(msg_ctx, env, phase_impl->name);    
+    
+    size = AXIS2_ARRAY_LIST_SIZE(phase_impl->handlers, env);
+    
+    for (i = 0; i < size; i++) 
+    {
+        axis2_handler_t * handler = (axis2_handler_t *) AXIS2_ARRAY_LIST_GET(phase_impl->handlers, env, i);
+        if (handler)
+        {
+            axis2_handler_desc_t *handler_desc = AXIS2_HANDLER_GET_HANDLER_DESC(handler, env);
+            if (!handler_desc)
+            {
+                AXIS2_ERROR_SET((*env)->error, AXIS2_ERROR_INVALID_HANDLER_STATE, AXIS2_FAILURE);
+                return AXIS2_FAILURE;
+            }
+            
+            found = AXIS2_QNAME_EQUALS(AXIS2_HANDLER_DESC_GET_QNAME(handler_desc, env), env, qname);
+            
+            if (found)
+            {
+                return AXIS2_HANDLER_INVOKE(handler, env, msg_ctx);
+            }
+        }
+    }
+    
+    return AXIS2_FAILURE;
+}
+
+axis2_status_t AXIS2_CALL axis2_phase_free (struct axis2_phase *phase, 
+                                               axis2_env_t **env)
+{
+    axis2_phase_impl_t *phase_impl = NULL;
+    
+    AXIS2_FUNC_PARAM_CHECK(phase, env, AXIS2_FAILURE);
+    
+    phase_impl = AXIS2_INTF_TO_IMPL(phase);
+    
+    if (phase_impl->phase.ops)
+    {
+        AXIS2_FREE((*env)->allocator, phase_impl->phase.ops);
+        phase_impl->phase.ops = NULL;
+    }
+    
+    if (phase_impl->name)
+    {
+        AXIS2_FREE((*env)->allocator, phase_impl->name);
+        phase_impl->name = NULL;
+    }    
+    
+    if (phase_impl->handlers)
+    {
+        AXIS2_ARRAY_LIST_FREE(phase_impl->handlers, env);
+        phase_impl->handlers = NULL;
+    }    
+
+    AXIS2_FREE((*env)->allocator, phase_impl);
+    phase_impl = NULL;
+    
+    return AXIS2_SUCCESS;
+}