| Method from org.apache.axis2.engine.Phase Detail: |
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 (handlers.size() == 1) {
handlers.add(0, handler);
} else {
handlers.add(handlers.size() - 2, handler);
}
} else {
handlers.add(handler);
}
}
Add a handler to the Phase. |
public void addHandler(HandlerDescription handlerDesc) throws PhaseException {
Iterator< Handler > handlers_itr = getHandlers().iterator();
while (handlers_itr.hasNext()) {
Handler hand = (Handler) handlers_itr.next();
HandlerDescription thisDesc = hand.getHandlerDesc();
if (handlerDesc.getName().equals(thisDesc.getName())) {
return;
}
}
if (isOneHandler) {
throw new PhaseException("Phase '" + this.getPhaseName()
+ "' can only have one handler, since there is a "
+ "handler with both phaseFirst and phaseLast true ");
}
if (handlerDesc.getRules().isPhaseFirst() && handlerDesc.getRules().isPhaseLast()) {
if (!handlers.isEmpty()) {
throw new PhaseException(this.getPhaseName()
+ " already contains Handlers, and "
+ handlerDesc.getName()
+ " cannot therefore be both phaseFirst and phaseLast.");
} else {
handlers.add(handlerDesc.getHandler());
isOneHandler = true;
}
} else if (handlerDesc.getRules().isPhaseFirst()) {
setPhaseFirst(handlerDesc.getHandler());
} else if (handlerDesc.getRules().isPhaseLast()) {
setPhaseLast(handlerDesc.getHandler());
} else {
insertHandler(handlerDesc);
}
}
Add a HandlerDescription to the Phase |
public void addHandler(Handler handler,
int index) {
if (log.isDebugEnabled()) {
log.debug("Handler " + handler.getName() + " inserted at position " + index +
" of Phase " + phaseName);
}
handlers.add(index, handler);
}
Add a Handler at a particular index within the Phase.
If we have a Phase with (H1, H2), calling addHandler(H3, 1) will result in (H1, H3, H2) |
public void checkPostConditions(MessageContext msgContext) throws AxisFault {
// Default version does nothing
}
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. |
public void checkPreconditions(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. |
public void cleanup() {
// Default version does nothing
}
|
public void flowComplete(MessageContext msgContext) {
if (isDebugEnabled) {
log.debug(msgContext.getLogIDString() + " Invoking flowComplete() in Phase \"" +
phaseName + "\"");
}
// 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();
} else {
/*We need to set it to 0 so that any previous phases will execute all
* of their handlers.*/
msgContext.setCurrentPhaseIndex(0);
}
for (; currentHandlerIndex > 0; currentHandlerIndex--) {
Handler handler = (Handler) handlers.get(currentHandlerIndex - 1);
if (isDebugEnabled) {
log.debug(msgContext.getLogIDString() + " Invoking flowComplete() for Handler '" +
handler.getName() + "' in Phase '" + phaseName + "'");
}
handler.flowComplete(msgContext);
}
}
|
public int getHandlerCount() {
return handlers.size();
}
|
public HandlerDescription getHandlerDesc() {
return null;
}
|
public List getHandlers() {
return handlers;
}
Gets all the handlers in the phase. |
public String getName() {
return phaseName;
}
|
public Parameter getParameter(String name) {
return null;
}
|
public String getPhaseName() {
return phaseName;
}
|
public void init(HandlerDescription handlerdesc) {
// Default version does nothing
}
|
public final InvocationResponse invoke(MessageContext msgctx) throws AxisFault {
if (isDebugEnabled) {
log.debug(msgctx.getLogIDString() + " Checking pre-condition for Phase \"" + phaseName +
"\"");
}
InvocationResponse pi = InvocationResponse.CONTINUE;
int currentIndex = msgctx.getCurrentPhaseIndex();
if (currentIndex == 0) {
checkPreconditions(msgctx);
}
if (isDebugEnabled) {
log.debug(msgctx.getLogIDString() + " Invoking phase \"" + phaseName + "\"");
}
int handlersSize = handlers.size();
while (currentIndex < handlersSize) {
Handler handler = (Handler) handlers.get(currentIndex);
if (isDebugEnabled) {
log.debug(msgctx.getLogIDString() + " Invoking Handler '" + handler.getName() +
"' in Phase '" + phaseName + "'");
}
pi = handler.invoke(msgctx);
if (!pi.equals(InvocationResponse.CONTINUE)) {
return pi;
}
currentIndex++;
msgctx.setCurrentPhaseIndex(currentIndex);
}
if (isDebugEnabled) {
log.debug(msgctx.getLogIDString() + " Checking post-conditions for phase \"" +
phaseName + "\"");
}
msgctx.setCurrentPhaseIndex(0);
checkPostConditions(msgctx);
return pi;
}
Invoke all the handlers in this Phase |
public void removeHandler(HandlerDescription handlerDesc) {
if (handlers.remove(handlerDesc.getHandler())) {
PhaseRule rule = handlerDesc.getRules();
if (rule.isPhaseFirst()) {
phaseFirstSet = false;
}
if (rule.isPhaseLast()) {
phaseLastSet = false;
}
if (rule.isPhaseFirst() && rule.isPhaseLast()) {
isOneHandler = false;
}
log.debug("removed handler " + handlerDesc.getName()
+ " from the phase " + phaseName);
} else {
log.debug("unable to remove handler " + handlerDesc.getName()
+ " from the phase " + phaseName);
}
}
Remove a given Handler from a phase using a HandlerDescription |
public void setName(String phaseName) {
this.phaseName = phaseName;
}
|
public void setPhaseFirst(Handler handler) throws PhaseException {
if (phaseFirstSet) {
throw new PhaseException("PhaseFirst has been set already, cannot have two"
+ " phaseFirst Handlers for Phase '" + this.getPhaseName() + "'");
}
handlers.add(0, handler);
phaseFirstSet = true;
}
Add a Handler to the Phase in the very first position, and ensure no other Handler
will come before it. |
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());
}
handlers.add(handler);
phaseLastSet = true;
}
Add a Handler to the Phase in the very last position, and ensure no other Handler
will come after it. |
public String toString() {
return this.getPhaseName();
}
|