01: package org.objectweb.celtix.bindings;
02:
03: import java.io.IOException;
04:
05: import javax.xml.ws.Binding;
06:
07: import org.objectweb.celtix.Bus;
08: import org.objectweb.celtix.configuration.Configuration;
09: import org.objectweb.celtix.context.InputStreamMessageContext;
10: import org.objectweb.celtix.context.ObjectMessageContext;
11: import org.objectweb.celtix.context.ObjectMessageContextImpl;
12: import org.objectweb.celtix.context.OutputStreamMessageContext;
13: import org.objectweb.celtix.handlers.HandlerInvoker;
14: import org.objectweb.celtix.transports.ServerTransport;
15: import org.objectweb.celtix.transports.Transport;
16: import org.objectweb.celtix.ws.addressing.EndpointReferenceType;
17:
18: public abstract class AbstractBindingBase implements BindingBase {
19:
20: protected final Bus bus;
21: protected final EndpointReferenceType reference;
22: protected Transport transport;
23:
24: protected AbstractBindingBase(Bus b, EndpointReferenceType r) {
25: bus = b;
26: reference = r;
27: }
28:
29: public Bus getBus() {
30: return bus;
31: }
32:
33: public EndpointReferenceType getEndpointReference() {
34: return reference;
35: }
36:
37: public Binding getBinding() {
38: return getBindingImpl();
39: }
40:
41: public Transport retrieveTransport() {
42: return transport;
43: }
44:
45: public ObjectMessageContext createObjectContext() {
46: return new ObjectMessageContextImpl();
47: }
48:
49: public HandlerInvoker createHandlerInvoker() {
50: return getBindingImpl().createHandlerInvoker();
51: }
52:
53: public void configureSystemHandlers(
54: Configuration endpointConfiguration) {
55: getBindingImpl().configureSystemHandlers(endpointConfiguration);
56: }
57:
58: public void send(Request request, DataBindingCallback callback)
59: throws IOException {
60: ObjectMessageContext objectCtx = request
61: .getObjectMessageContext();
62: BindingContextUtils.storeDataBindingCallback(objectCtx,
63: callback);
64:
65: try {
66: OutputStreamMessageContext ostreamCtx = request
67: .process(null);
68:
69: if (null != ostreamCtx) {
70: if (BindingContextUtils.isOnewayTransport(ostreamCtx)
71: || transport instanceof ServerTransport) {
72: // REVISIT: replace with Transport.send()
73: ostreamCtx.getOutputStream().close();
74: ostreamCtx.getCorrespondingInputStreamContext()
75: .getInputStream().close();
76: } else {
77: ostreamCtx.getOutputStream().close();
78: // handle partial reponse
79: InputStreamMessageContext istreamCtx = ostreamCtx
80: .getCorrespondingInputStreamContext();
81: Response response = new Response(request);
82: response.processProtocol(istreamCtx);
83: response.processLogical(null);
84: }
85: }
86:
87: } finally {
88: request.complete();
89: }
90: }
91:
92: public abstract AbstractBindingImpl getBindingImpl();
93:
94: }
|