001: package org.objectweb.celtix.bindings;
002:
003: import javax.xml.ws.handler.MessageContext;
004:
005: import org.objectweb.celtix.context.OutputStreamMessageContext;
006:
007: import static org.objectweb.celtix.bindings.JAXWSConstants.DATABINDING_CALLBACK_PROPERTY;
008: import static org.objectweb.celtix.bindings.JAXWSConstants.DISPATCH_PROPERTY;
009: import static org.objectweb.celtix.bindings.JAXWSConstants.SERVER_BINDING_ENDPOINT_CALLBACK_PROPERTY;
010: import static org.objectweb.celtix.context.InputStreamMessageContext.ASYNC_ONEWAY_DISPATCH;
011: import static org.objectweb.celtix.context.InputStreamMessageContext.DECOUPLED_RESPONSE;
012: import static org.objectweb.celtix.context.ObjectMessageContext.CORRELATION_IN;
013:
014: /**
015: * Holder for utility methods relating to contexts.
016: */
017:
018: public final class BindingContextUtils {
019:
020: /**
021: * Prevents instantiation.
022: */
023: private BindingContextUtils() {
024: }
025:
026: /**
027: * Store data binding callback in message context.
028: *
029: * @param context the message context
030: * @param callback the data binding callback
031: */
032: public static void storeDataBindingCallback(MessageContext context,
033: DataBindingCallback callback) {
034: context.put(DATABINDING_CALLBACK_PROPERTY, callback);
035: context.setScope(DATABINDING_CALLBACK_PROPERTY,
036: MessageContext.Scope.HANDLER);
037: }
038:
039: /**
040: * Retrieve data binding callback from message context.
041: *
042: * @param context the message context
043: * @returned the data binding callback
044: */
045: public static DataBindingCallback retrieveDataBindingCallback(
046: MessageContext context) {
047: return (DataBindingCallback) context
048: .get(DATABINDING_CALLBACK_PROPERTY);
049: }
050:
051: /**
052: * Store server binding endpoint callback in message context.
053: *
054: * @param context the message context
055: * @param sbec the server binding endpoint callback
056: */
057: public static void storeServerBindingEndpointCallback(
058: MessageContext context, ServerBindingEndpointCallback sbec) {
059: context.put(SERVER_BINDING_ENDPOINT_CALLBACK_PROPERTY, sbec);
060: context.setScope(SERVER_BINDING_ENDPOINT_CALLBACK_PROPERTY,
061: MessageContext.Scope.HANDLER);
062: }
063:
064: /**
065: * Retrieve server binding endpoint callback from message context.
066: *
067: * @param context the message context
068: * @returned the server binding endpoint callback
069: */
070: public static ServerBindingEndpointCallback retrieveServerBindingEndpointCallback(
071: MessageContext context) {
072: return (ServerBindingEndpointCallback) context
073: .get(SERVER_BINDING_ENDPOINT_CALLBACK_PROPERTY);
074: }
075:
076: /**
077: * Checks if a method object is stored in the context and if it is annotated
078: * with a Oneway annotation.
079: *
080: * @param context
081: * @return true if a method object is stored in the context and it has a Oneway annotation.
082: */
083: public static boolean isOnewayMethod(MessageContext context) {
084: DataBindingCallback cb = retrieveDataBindingCallback(context);
085: if (cb == null) {
086: if (!context
087: .containsKey(OutputStreamMessageContext.ONEWAY_MESSAGE_TF)) {
088: return false;
089: }
090: return ((Boolean) context
091: .get(OutputStreamMessageContext.ONEWAY_MESSAGE_TF))
092: .booleanValue();
093: }
094: return cb.isOneWay();
095: }
096:
097: /**
098: * Checks if a the oneway property is set in the context if its value is true
099: * (indicating that no response is expected from the transport).
100: *
101: * @param context
102: * @return true if a method object is stored in the context and it has a Oneway annotation.
103: */
104: public static boolean isOnewayTransport(MessageContext context) {
105: Boolean b = (Boolean) context
106: .get(OutputStreamMessageContext.ONEWAY_MESSAGE_TF);
107: if (null != b) {
108: return b.booleanValue();
109: }
110: return false;
111: }
112:
113: /**
114: * Retrieve correlation id from message context.
115: *
116: * @param context the message context
117: * @returned the correlation id
118: */
119: public static String retrieveCorrelationID(MessageContext context) {
120: return (String) context.get(CORRELATION_IN);
121: }
122:
123: /**
124: * Store dispatch property in message context.
125: *
126: * @param context the message context
127: * @param dispatch value of the dispatch property
128: */
129: public static void storeDispatch(MessageContext context,
130: boolean dispatch) {
131: context.put(DISPATCH_PROPERTY, dispatch ? Boolean.TRUE
132: : Boolean.FALSE);
133: context.setScope(DISPATCH_PROPERTY,
134: MessageContext.Scope.HANDLER);
135: }
136:
137: /**
138: * Retrieve value of dispatch property from message context.
139: *
140: * @param context the message context
141: * @returned the value of dispatch property
142: */
143: public static boolean retrieveDispatch(MessageContext context) {
144: Boolean b = (Boolean) context.get(DISPATCH_PROPERTY);
145: return null == b || b.booleanValue();
146: }
147:
148: /**
149: * Store async oneway dispatch property in message context.
150: *
151: * @param context the message context
152: * @param async value of the dispatch property
153: */
154: public static void storeAsyncOnewayDispatch(MessageContext context,
155: boolean async) {
156: context.put(ASYNC_ONEWAY_DISPATCH, async ? Boolean.TRUE
157: : Boolean.FALSE);
158: context.setScope(ASYNC_ONEWAY_DISPATCH,
159: MessageContext.Scope.HANDLER);
160: }
161:
162: /**
163: * Retrieve value of async oneway dispatch property from message context.
164: *
165: * @param context the message context
166: * @returned the value of async oneway dispatch property
167: */
168: public static boolean retrieveAsyncOnewayDispatch(
169: MessageContext context) {
170: Boolean b = (Boolean) context.get(ASYNC_ONEWAY_DISPATCH);
171: return b != null && b.booleanValue();
172: }
173:
174: /**
175: * Store decoupled response property in message context.
176: *
177: * @param context the message context
178: * @param decoupled value of the decoupled response property
179: */
180: public static void storeDecoupledResponse(MessageContext context,
181: boolean decoupled) {
182: context.put(DECOUPLED_RESPONSE, decoupled ? Boolean.TRUE
183: : Boolean.FALSE);
184: context.setScope(DECOUPLED_RESPONSE,
185: MessageContext.Scope.HANDLER);
186: }
187:
188: /**
189: * Retrieve value of decoupled response property from message context.
190: *
191: * @param context the message context
192: * @returned the value of decoupled response property
193: */
194: public static boolean retrieveDecoupledResponse(
195: MessageContext context) {
196: Boolean b = (Boolean) context.get(DECOUPLED_RESPONSE);
197: return b != null && b.booleanValue();
198: }
199:
200: }
|