001: package org.objectweb.celtix.bindings;
002:
003: import java.io.IOException;
004:
005: import javax.xml.ws.handler.MessageContext;
006:
007: import org.objectweb.celtix.context.ObjectMessageContext;
008: import org.objectweb.celtix.context.OutputStreamMessageContext;
009: import org.objectweb.celtix.handlers.HandlerInvoker;
010: import org.objectweb.celtix.transports.Transport;
011:
012: public class Request {
013:
014: private final AbstractBindingBase binding;
015: private Transport transport;
016: private final ObjectMessageContext objectCtx;
017: private MessageContext bindingCtx;
018: private final HandlerInvoker handlerInvoker;
019: private boolean expectRelatedRequest;
020:
021: public Request(AbstractBindingBase b, Transport t,
022: ObjectMessageContext o) {
023: binding = b;
024: objectCtx = o;
025:
026: transport = t;
027: if (transport == null) {
028: transport = b.retrieveTransport();
029: }
030:
031: handlerInvoker = binding.createHandlerInvoker();
032:
033: objectCtx
034: .put(ObjectMessageContext.MESSAGE_INPUT, Boolean.FALSE);
035: setOneway(false);
036: }
037:
038: public String getCorrelationId() {
039: return (String) objectCtx
040: .get(ObjectMessageContext.CORRELATION_OUT);
041: }
042:
043: public AbstractBindingBase getBinding() {
044: return binding;
045: }
046:
047: public Transport getTransport() {
048: return transport;
049: }
050:
051: public HandlerInvoker getHandlerInvoker() {
052: return handlerInvoker;
053: }
054:
055: public ObjectMessageContext getObjectMessageContext() {
056: return objectCtx;
057: }
058:
059: public MessageContext getBindingContext() {
060: return bindingCtx;
061: }
062:
063: public final void setOneway(boolean oneWay) {
064: objectCtx.put(OutputStreamMessageContext.ONEWAY_MESSAGE_TF,
065: oneWay);
066: }
067:
068: public final boolean isOneway() {
069: return ((Boolean) objectCtx
070: .get(OutputStreamMessageContext.ONEWAY_MESSAGE_TF))
071: .booleanValue();
072: }
073:
074: public OutputStreamMessageContext process(
075: OutputStreamMessageContext ostreamCtx) throws IOException {
076: return process(ostreamCtx, false);
077: }
078:
079: public OutputStreamMessageContext process(
080: OutputStreamMessageContext ostreamCtx,
081: boolean logicalChainTraversed) throws IOException {
082: return process(ostreamCtx, logicalChainTraversed, false);
083: }
084:
085: public OutputStreamMessageContext process(
086: OutputStreamMessageContext ostreamCtx,
087: boolean logicalChainTraversed,
088: boolean protocolChainTraversed) throws IOException {
089: if (logicalChainTraversed
090: || handlerInvoker
091: .invokeLogicalHandlers(true, objectCtx)) {
092: bindingCtx = binding.getBindingImpl()
093: .createBindingMessageContext(objectCtx);
094: bindingCtx.put(ObjectMessageContext.MESSAGE_INPUT,
095: Boolean.FALSE);
096:
097: if (null == bindingCtx) {
098: bindingCtx = objectCtx;
099: } else if (!protocolChainTraversed) {
100: DataBindingCallback callback = BindingContextUtils
101: .retrieveDataBindingCallback(objectCtx);
102: binding.getBindingImpl().marshal(objectCtx, bindingCtx,
103: callback);
104: }
105:
106: if (protocolChainTraversed
107: || handlerInvoker.invokeProtocolHandlers(true,
108: bindingCtx)) {
109: binding.getBindingImpl().updateMessageContext(
110: bindingCtx);
111: if (ostreamCtx == null) {
112: ostreamCtx = transport
113: .createOutputStreamContext(bindingCtx);
114: }
115:
116: handlerInvoker.invokeStreamHandlers(ostreamCtx);
117:
118: transport.finalPrepareOutputStreamContext(ostreamCtx);
119:
120: binding.getBindingImpl().write(bindingCtx, ostreamCtx);
121:
122: return ostreamCtx;
123: } else if (!isOneway()) {
124: handlerInvoker.invokeProtocolHandlers(true, bindingCtx);
125: bindingCtx.put(ObjectMessageContext.MESSAGE_INPUT,
126: Boolean.TRUE);
127: }
128: } else if (!isOneway()) {
129: objectCtx.put(ObjectMessageContext.MESSAGE_INPUT,
130: Boolean.TRUE);
131: handlerInvoker.invokeLogicalHandlers(true, objectCtx);
132: }
133: return null;
134: }
135:
136: public void complete() {
137: handlerInvoker.mepComplete(objectCtx);
138: }
139:
140: public void expectRelatedRequest() {
141: expectRelatedRequest = true;
142: }
143:
144: public boolean isRelatedRequestExpected() {
145: return expectRelatedRequest;
146: }
147: }
|