1 package org.objectweb.celtix.systest.handlers; 2 3 4 import java.util.ArrayList ; 5 import java.util.HashMap ; 6 import java.util.List ; 7 import java.util.Map ; 8 import java.util.logging.Logger ; 9 10 import javax.xml.ws.handler.MessageContext; 11 12 21 public abstract class TestHandlerBase { 22 23 private static final Logger LOG = Logger.getLogger(TestHandlerBase.class.getName()); 24 25 private static int sid; 26 27 protected boolean handleMessageRet = true; 28 Map <String , Integer > methodCallCount = new HashMap <String , Integer >(); 29 private final int id; 30 private final boolean isServerSideHandler; 31 32 public TestHandlerBase(boolean serverSide) { 33 id = ++sid; 34 isServerSideHandler = serverSide; 35 } 36 37 protected void methodCalled(String methodName) { 38 int val = 0; 39 if (methodCallCount.keySet().contains(methodName)) { 40 val = methodCallCount.get(methodName); 41 } 42 val++; 43 methodCallCount.put(methodName, val); 44 } 45 46 47 public int getId() { 48 return id; 49 } 50 51 public abstract String getHandlerId(); 52 53 public boolean isCloseInvoked() { 54 55 return methodCallCount.containsKey("close"); 56 } 57 58 public boolean isDestroyInvoked() { 59 return methodCallCount.containsKey("destroy"); 60 } 61 62 public boolean isHandleFaultInvoked() { 63 return methodCallCount.containsKey("handleFault"); 64 } 65 66 public int getHandleFaultInvoked() { 67 return getMethodCallCount("handleFault"); 68 } 69 70 public boolean isHandleMessageInvoked() { 71 return methodCallCount.containsKey("handleMessage"); 72 } 73 74 public int getHandleMessageInvoked() { 75 return getMethodCallCount("handleMessage"); 76 } 77 78 public boolean isInitInvoked() { 79 return methodCallCount.containsKey("init"); 80 } 81 82 public void setHandleMessageRet(boolean ret) { 83 handleMessageRet = ret; 84 } 85 86 public boolean isServerSideHandler() { 87 return isServerSideHandler; 88 } 89 90 protected void printHandlerInfo(String methodName, boolean outbound) { 91 String info = getHandlerId() + " " 92 + (outbound ? "outbound" : "inbound") + " " 93 + methodName; 94 LOG.info(info); 95 } 96 97 98 @SuppressWarnings ("unchecked") 99 protected List <String > getHandlerInfoList(MessageContext ctx) { 100 List <String > handlerInfoList = null; 101 if (ctx.containsKey("handler.info")) { 102 handlerInfoList = (List <String >)ctx.get("handler.info"); 103 } else { 104 handlerInfoList = new ArrayList <String >(); 105 ctx.put("handler.info", handlerInfoList); 106 ctx.setScope("handler.info", MessageContext.Scope.APPLICATION); 107 } 108 return handlerInfoList; 109 } 110 111 protected boolean isOutbound(MessageContext ctx) { 112 return (Boolean )ctx.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 } 124 | Popular Tags |