KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > celtix > bindings > BindingContextUtils


1 package org.objectweb.celtix.bindings;
2
3
4 import javax.xml.ws.handler.MessageContext;
5
6 import org.objectweb.celtix.context.OutputStreamMessageContext;
7
8 import static org.objectweb.celtix.bindings.JAXWSConstants.DATABINDING_CALLBACK_PROPERTY;
9 import static org.objectweb.celtix.bindings.JAXWSConstants.DISPATCH_PROPERTY;
10 import static org.objectweb.celtix.bindings.JAXWSConstants.SERVER_BINDING_ENDPOINT_CALLBACK_PROPERTY;
11 import static org.objectweb.celtix.context.InputStreamMessageContext.ASYNC_ONEWAY_DISPATCH;
12 import static org.objectweb.celtix.context.InputStreamMessageContext.DECOUPLED_RESPONSE;
13 import static org.objectweb.celtix.context.ObjectMessageContext.CORRELATION_IN;
14
15
16 /**
17  * Holder for utility methods relating to contexts.
18  */

19
20 public final class BindingContextUtils {
21
22     /**
23      * Prevents instantiation.
24      */

25     private BindingContextUtils() {
26     }
27     
28     /**
29      * Store data binding callback in message context.
30      *
31      * @param context the message context
32      * @param callback the data binding callback
33      */

34     public static void storeDataBindingCallback(MessageContext context, DataBindingCallback callback) {
35         context.put(DATABINDING_CALLBACK_PROPERTY, callback);
36         context.setScope(DATABINDING_CALLBACK_PROPERTY, MessageContext.Scope.HANDLER);
37     }
38     
39     /**
40      * Retrieve data binding callback from message context.
41      *
42      * @param context the message context
43      * @returned the data binding callback
44      */

45     public static DataBindingCallback retrieveDataBindingCallback(MessageContext context) {
46         return (DataBindingCallback)context.get(DATABINDING_CALLBACK_PROPERTY);
47     }
48         
49     /**
50      * Store server binding endpoint callback in message context.
51      *
52      * @param context the message context
53      * @param sbec the server binding endpoint callback
54      */

55     public static void storeServerBindingEndpointCallback(MessageContext context,
56                                                           ServerBindingEndpointCallback sbec) {
57         context.put(SERVER_BINDING_ENDPOINT_CALLBACK_PROPERTY, sbec);
58         context.setScope(SERVER_BINDING_ENDPOINT_CALLBACK_PROPERTY, MessageContext.Scope.HANDLER);
59     }
60     
61     /**
62      * Retrieve server binding endpoint callback from message context.
63      *
64      * @param context the message context
65      * @returned the server binding endpoint callback
66      */

67     public static ServerBindingEndpointCallback retrieveServerBindingEndpointCallback(
68         MessageContext context) {
69         return (ServerBindingEndpointCallback)context.get(SERVER_BINDING_ENDPOINT_CALLBACK_PROPERTY);
70     }
71         
72     /**
73      * Checks if a method object is stored in the context and if it is annotated
74      * with a Oneway annotation.
75      *
76      * @param context
77      * @return true if a method object is stored in the context and it has a Oneway annotation.
78      */

79     public static boolean isOnewayMethod(MessageContext context) {
80         DataBindingCallback cb = retrieveDataBindingCallback(context);
81         if (cb == null) {
82             if (!context.containsKey(OutputStreamMessageContext.ONEWAY_MESSAGE_TF)) {
83                 return false;
84             }
85             return ((Boolean JavaDoc)context.get(OutputStreamMessageContext.ONEWAY_MESSAGE_TF)).booleanValue();
86         }
87         return cb.isOneWay();
88     }
89     
90     /**
91      * Checks if a the oneway property is set in the context if its value is true
92      * (indicating that no response is expected from the transport).
93      *
94      * @param context
95      * @return true if a method object is stored in the context and it has a Oneway annotation.
96      */

97     public static boolean isOnewayTransport(MessageContext context) {
98         Boolean JavaDoc b = (Boolean JavaDoc)context.get(OutputStreamMessageContext.ONEWAY_MESSAGE_TF);
99         if (null != b) {
100             return b.booleanValue();
101         }
102         return false;
103     }
104         
105     /**
106      * Retrieve correlation id from message context.
107      *
108      * @param context the message context
109      * @returned the correlation id
110      */

111     public static String JavaDoc retrieveCorrelationID(MessageContext context) {
112         return (String JavaDoc)context.get(CORRELATION_IN);
113     }
114     
115     /**
116      * Store dispatch property in message context.
117      *
118      * @param context the message context
119      * @param dispatch value of the dispatch property
120      */

121     public static void storeDispatch(MessageContext context, boolean dispatch) {
122         context.put(DISPATCH_PROPERTY, dispatch ? Boolean.TRUE : Boolean.FALSE);
123         context.setScope(DISPATCH_PROPERTY, MessageContext.Scope.HANDLER);
124     }
125    
126     /**
127      * Retrieve value of dispatch property from message context.
128      *
129      * @param context the message context
130      * @returned the value of dispatch property
131      */

132     public static boolean retrieveDispatch(MessageContext context) {
133         Boolean JavaDoc b = (Boolean JavaDoc)context.get(DISPATCH_PROPERTY);
134         return null == b || b.booleanValue();
135     }
136     
137     /**
138      * Store async oneway dispatch property in message context.
139      *
140      * @param context the message context
141      * @param async value of the dispatch property
142      */

143     public static void storeAsyncOnewayDispatch(MessageContext context, boolean async) {
144         context.put(ASYNC_ONEWAY_DISPATCH, async ? Boolean.TRUE : Boolean.FALSE);
145         context.setScope(ASYNC_ONEWAY_DISPATCH, MessageContext.Scope.HANDLER);
146     }
147    
148     /**
149      * Retrieve value of async oneway dispatch property from message context.
150      *
151      * @param context the message context
152      * @returned the value of async oneway dispatch property
153      */

154     public static boolean retrieveAsyncOnewayDispatch(MessageContext context) {
155         Boolean JavaDoc b = (Boolean JavaDoc)context.get(ASYNC_ONEWAY_DISPATCH);
156         return b != null && b.booleanValue();
157     }
158
159     /**
160      * Store decoupled response property in message context.
161      *
162      * @param context the message context
163      * @param decoupled value of the decoupled response property
164      */

165     public static void storeDecoupledResponse(MessageContext context, boolean decoupled) {
166         context.put(DECOUPLED_RESPONSE, decoupled ? Boolean.TRUE : Boolean.FALSE);
167         context.setScope(DECOUPLED_RESPONSE, MessageContext.Scope.HANDLER);
168     }
169    
170     /**
171      * Retrieve value of decoupled response property from message context.
172      *
173      * @param context the message context
174      * @returned the value of decoupled response property
175      */

176     public static boolean retrieveDecoupledResponse(MessageContext context) {
177         Boolean JavaDoc b = (Boolean JavaDoc)context.get(DECOUPLED_RESPONSE);
178         return b != null && b.booleanValue();
179     }
180     
181 }
182
Popular Tags