01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing,
13: * software distributed under the License is distributed on an
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15: * KIND, either express or implied. See the License for the
16: * specific language governing permissions and limitations
17: * under the License.
18: */
19: package org.apache.axis2.jaxws.sample.addnumbershandler;
20:
21: import java.util.ArrayList;
22: import java.util.HashMap;
23: import java.util.List;
24: import java.util.Map;
25:
26: import javax.xml.ws.handler.MessageContext;
27:
28: public class HandlerTracker {
29:
30: static Map<String, HandlerTracker> trackers = new HashMap<String, HandlerTracker>();
31:
32: List<Methods> calledMethods = new ArrayList<Methods>();
33:
34: enum Methods {
35: CLOSE, GET_HEADERS, HANDLE_FAULT, HANDLE_MESSAGE
36: };
37:
38: public HandlerTracker(String name) {
39: }
40:
41: public void close(MessageContext context) {
42: calledMethods.add(Methods.CLOSE);
43: }
44:
45: public void getHeaders() {
46: calledMethods.add(Methods.GET_HEADERS);
47: }
48:
49: public void handleFault(MessageContext context) {
50: calledMethods.add(Methods.HANDLE_FAULT);
51: }
52:
53: public void handleMessage(MessageContext context) {
54: calledMethods.add(Methods.HANDLE_MESSAGE);
55: }
56:
57: public boolean isCalled(Methods method) {
58: return calledMethods.contains(method);
59: }
60:
61: public static HandlerTracker getHandlerTracker(Class clazz) {
62: HandlerTracker tracker = trackers.get(clazz.getName());
63: if (tracker == null) {
64: tracker = new HandlerTracker(clazz.getName());
65: trackers.put(clazz.getName(), tracker);
66: }
67: return tracker;
68: }
69:
70: public String toString() {
71: return this.calledMethods.toString();
72: }
73:
74: }
|