001: package org.objectweb.celtix.systest.handlers;
002:
003: import java.util.ArrayList;
004: import java.util.HashMap;
005: import java.util.List;
006: import java.util.Map;
007: import java.util.logging.Logger;
008:
009: import javax.xml.ws.handler.MessageContext;
010:
011: /**
012: * Describe class TestHandlerBase here.
013: *
014: *
015: * Created: Fri Oct 21 14:02:50 2005
016: *
017: * @author <a href="mailto:codea@iona.com">codea</a>
018: * @version 1.0
019: */
020: public abstract class TestHandlerBase {
021:
022: private static final Logger LOG = Logger
023: .getLogger(TestHandlerBase.class.getName());
024:
025: private static int sid;
026:
027: protected boolean handleMessageRet = true;
028: Map<String, Integer> methodCallCount = new HashMap<String, Integer>();
029: private final int id;
030: private final boolean isServerSideHandler;
031:
032: public TestHandlerBase(boolean serverSide) {
033: id = ++sid;
034: isServerSideHandler = serverSide;
035: }
036:
037: protected void methodCalled(String methodName) {
038: int val = 0;
039: if (methodCallCount.keySet().contains(methodName)) {
040: val = methodCallCount.get(methodName);
041: }
042: val++;
043: methodCallCount.put(methodName, val);
044: }
045:
046: public int getId() {
047: return id;
048: }
049:
050: public abstract String getHandlerId();
051:
052: public boolean isCloseInvoked() {
053:
054: return methodCallCount.containsKey("close");
055: }
056:
057: public boolean isDestroyInvoked() {
058: return methodCallCount.containsKey("destroy");
059: }
060:
061: public boolean isHandleFaultInvoked() {
062: return methodCallCount.containsKey("handleFault");
063: }
064:
065: public int getHandleFaultInvoked() {
066: return getMethodCallCount("handleFault");
067: }
068:
069: public boolean isHandleMessageInvoked() {
070: return methodCallCount.containsKey("handleMessage");
071: }
072:
073: public int getHandleMessageInvoked() {
074: return getMethodCallCount("handleMessage");
075: }
076:
077: public boolean isInitInvoked() {
078: return methodCallCount.containsKey("init");
079: }
080:
081: public void setHandleMessageRet(boolean ret) {
082: handleMessageRet = ret;
083: }
084:
085: public boolean isServerSideHandler() {
086: return isServerSideHandler;
087: }
088:
089: protected void printHandlerInfo(String methodName, boolean outbound) {
090: String info = getHandlerId() + " "
091: + (outbound ? "outbound" : "inbound") + " "
092: + methodName;
093: LOG.info(info);
094: }
095:
096: @SuppressWarnings("unchecked")
097: protected List<String> getHandlerInfoList(MessageContext ctx) {
098: List<String> handlerInfoList = null;
099: if (ctx.containsKey("handler.info")) {
100: handlerInfoList = (List<String>) ctx.get("handler.info");
101: } else {
102: handlerInfoList = new ArrayList<String>();
103: ctx.put("handler.info", handlerInfoList);
104: ctx.setScope("handler.info",
105: MessageContext.Scope.APPLICATION);
106: }
107: return handlerInfoList;
108: }
109:
110: protected boolean isOutbound(MessageContext ctx) {
111: return (Boolean) ctx
112: .get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
113: }
114:
115: private int getMethodCallCount(String methodName) {
116: int ret = 0;
117: if (methodCallCount.containsKey(methodName)) {
118: ret = methodCallCount.get(methodName);
119: }
120: return ret;
121: }
122:
123: }
|