KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > jaxrpc > AAAHandler


1 package test.jaxrpc;
2
3 import javax.xml.namespace.QName JavaDoc;
4 import javax.xml.rpc.handler.Handler JavaDoc;
5 import javax.xml.rpc.handler.HandlerInfo JavaDoc;
6 import javax.xml.rpc.handler.MessageContext JavaDoc;
7 import java.util.Map JavaDoc;
8
9 public class AAAHandler implements Handler JavaDoc {
10     private int handleRequestInvocations = 0;
11     private int handleResponseInvocations = 0;
12     private int handleFaultInvocations = 0;
13
14     public Object JavaDoc handleRequestReturnValue = null;
15     public Object JavaDoc handleResponseReturnValue = null;
16     public Object JavaDoc handleFaultReturnValue = null;
17
18     public boolean handleRequest(MessageContext JavaDoc context) {
19         handleRequestInvocations++;
20         return returnAppropriateValue(handleRequestReturnValue);
21     }
22
23     public boolean handleResponse(MessageContext JavaDoc context) {
24         handleResponseInvocations++;
25         return returnAppropriateValue(handleResponseReturnValue);
26     }
27
28     public boolean handleFault(MessageContext JavaDoc context) {
29         handleFaultInvocations++;
30         return returnAppropriateValue(handleFaultReturnValue);
31     }
32
33     private boolean returnAppropriateValue(Object JavaDoc returnValue) {
34         if (returnValue == null)
35             return true;
36         else if (returnValue instanceof Boolean JavaDoc)
37             return ((Boolean JavaDoc) returnValue).booleanValue();
38         else if (returnValue instanceof RuntimeException JavaDoc)
39             throw (RuntimeException JavaDoc) returnValue;
40         else {
41             throw new RuntimeException JavaDoc();
42         }
43     }
44
45     public void init(HandlerInfo JavaDoc config) {
46         Map JavaDoc map = config.getHandlerConfig();
47         handleRequestReturnValue = map.get("HANDLE_REQUEST_RETURN_VALUE");
48         handleResponseReturnValue = map.get("HANDLE_RESPONSE_RETURN_VALUE");
49         handleFaultReturnValue = map.get("HANDLE_FAULT_RETURN_VALUE");
50     }
51
52     public void destroy() {
53     }
54
55     public QName JavaDoc[] getHeaders() {
56         return new QName JavaDoc[0];
57     }
58
59     public int getHandleRequestInvocations() {
60         return handleRequestInvocations;
61     }
62
63     public int getHandleResponseInvocations() {
64         return handleResponseInvocations;
65     }
66
67     public int getHandleFaultInvocations() {
68         return handleFaultInvocations;
69     }
70
71     public Object JavaDoc getHandleRequestReturnValue() {
72         return handleRequestReturnValue;
73     }
74
75     public void setHandleRequestReturnValue(Object JavaDoc handleRequestReturnValue) {
76         this.handleRequestReturnValue = handleRequestReturnValue;
77     }
78
79     public Object JavaDoc getHandleResponseReturnValue() {
80         return handleResponseReturnValue;
81     }
82
83     public void setHandleResponseReturnValue(Object JavaDoc handleResponseReturnValue) {
84         this.handleResponseReturnValue = handleResponseReturnValue;
85     }
86
87     public Object JavaDoc getHandleFaultReturnValue() {
88         return handleFaultReturnValue;
89     }
90
91     public void setHandleFaultReturnValue(Object JavaDoc handleFaultReturnValue) {
92         this.handleFaultReturnValue = handleFaultReturnValue;
93     }
94
95 }
Popular Tags