KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > celtix > bus > bindings > TestServerBinding


1 package org.objectweb.celtix.bus.bindings;
2
3 import java.io.ByteArrayOutputStream JavaDoc;
4 import java.io.IOException JavaDoc;
5 import java.io.InputStream JavaDoc;
6 import java.io.OutputStream JavaDoc;
7
8 import javax.wsdl.WSDLException;
9 import javax.xml.namespace.QName JavaDoc;
10 import javax.xml.ws.ServiceMode;
11 import javax.xml.ws.handler.MessageContext;
12
13 import org.objectweb.celtix.Bus;
14 import org.objectweb.celtix.BusException;
15 import org.objectweb.celtix.bindings.AbstractBindingImpl;
16 import org.objectweb.celtix.bindings.AbstractServerBinding;
17 import org.objectweb.celtix.bindings.ServerBindingEndpointCallback;
18 import org.objectweb.celtix.context.InputStreamMessageContext;
19 import org.objectweb.celtix.context.MessageContextWrapper;
20 import org.objectweb.celtix.context.ObjectMessageContext;
21 import org.objectweb.celtix.context.OutputStreamMessageContext;
22 import org.objectweb.celtix.transports.ServerTransport;
23 import org.objectweb.celtix.transports.TransportFactory;
24 import org.objectweb.celtix.transports.TransportFactoryManager;
25 import org.objectweb.celtix.ws.addressing.EndpointReferenceType;
26
27 public class TestServerBinding extends AbstractServerBinding {
28
29     protected final AbstractBindingImpl binding;
30     String JavaDoc currentOperation = "undeclared";
31     String JavaDoc schemeName = "test";
32
33     public TestServerBinding(Bus b, EndpointReferenceType ref,
34                              ServerBindingEndpointCallback cbFactory) {
35         super(b, ref, cbFactory);
36         binding = new TestBinding(this);
37     }
38     
39     protected ServerTransport createTransport(EndpointReferenceType ref)
40         throws WSDLException, IOException JavaDoc {
41         TransportFactoryManager tfm = bus.getTransportFactoryManager();
42         String JavaDoc name = "http://celtix.objectweb.org/transports/test";
43         TransportFactory tf = null;
44         try {
45             tf = tfm.getTransportFactory(name);
46         } catch (BusException ex) {
47             // ignore
48
}
49         if (tf == null) {
50             tf = new TestTransportFactory();
51             try {
52                 tfm.registerTransportFactory(name, tf);
53             } catch (BusException ex) {
54                 System.out.println(ex.getMessage());
55                 return null;
56             }
57         }
58         return tf.createServerTransport(ref);
59     }
60
61     protected void unmarshal(MessageContext context, ObjectMessageContext objContext) {
62         // populate object context with test data depending on current operation
63
// name
64
if ("greetMe".equals(currentOperation)) {
65             String JavaDoc name = System.getProperty("user.name");
66             objContext.setMessageObjects(name);
67         }
68     }
69
70     protected void marshal(ObjectMessageContext objContext, MessageContext context) {
71     }
72
73     protected void marshalFault(ObjectMessageContext objContext, MessageContext context) {
74     }
75     
76     protected void read(InputStreamMessageContext inCtx, MessageContext context) throws IOException JavaDoc {
77         context.put(MessageContext.WSDL_OPERATION, new QName JavaDoc(currentOperation));
78     }
79
80     protected void write(MessageContext context, OutputStreamMessageContext outCtx) throws IOException JavaDoc {
81     }
82
83     public AbstractBindingImpl getBindingImpl() {
84         return binding;
85     }
86
87     public boolean isCompatibleWithAddress(String JavaDoc address) {
88         return null != address && address.startsWith(schemeName);
89     }
90     
91     protected MessageContext invokeOnProvider(MessageContext requestCtx, ServiceMode mode) {
92         return null;
93     }
94
95     ServerTransport getTransport() {
96         return serverTransport();
97     }
98
99     public void triggerTransport() {
100         if (transport instanceof TestServerTransport) {
101             TestServerTransport tsb = (TestServerTransport)transport;
102             tsb.fire();
103         }
104     }
105     public QName JavaDoc getOperationName(MessageContext ctx) {
106         return new QName JavaDoc("", currentOperation);
107     }
108
109
110     static class ToyInputStreamMessageContext extends MessageContextWrapper
111         implements InputStreamMessageContext {
112         private static final long serialVersionUID = 1;
113         
114         ToyInputStreamMessageContext(MessageContext wrapped) {
115             super(wrapped);
116         }
117
118         public InputStream JavaDoc getInputStream() {
119             return null;
120         }
121     
122         public void setInputStream(InputStream JavaDoc ins) {
123         }
124
125         public boolean isFault() {
126             return false;
127         }
128
129         public void setFault(boolean isfault) {
130         }
131     }
132
133     static class ToyOutputStreamMessageContext extends MessageContextWrapper
134         implements OutputStreamMessageContext {
135         private static final long serialVersionUID = 1;
136         private OutputStream JavaDoc outputStream;
137         
138         ToyOutputStreamMessageContext(MessageContext wrapped) {
139             super(wrapped);
140         }
141
142         public OutputStream JavaDoc getOutputStream() {
143             if (null == outputStream) {
144                 outputStream = new ByteArrayOutputStream JavaDoc();
145             }
146             return outputStream;
147         }
148     
149         public void setOutputStream(OutputStream JavaDoc os) {
150             outputStream = os;
151         }
152
153         public boolean isFault() {
154             return false;
155         }
156
157         public void setFault(boolean b) {
158         }
159         
160         public void setOneWay(boolean isOneWay) {
161             put(ONEWAY_MESSAGE_TF, isOneWay);
162         }
163         
164         public boolean isOneWay() {
165             return ((Boolean JavaDoc)get(ONEWAY_MESSAGE_TF)).booleanValue();
166         }
167
168         public InputStreamMessageContext getCorrespondingInputStreamContext()
169             throws IOException JavaDoc {
170             return null;
171         }
172     }
173
174     public boolean isBindingCompatible(String JavaDoc address) {
175         return address.contains("http:");
176     }
177
178 }
179
Popular Tags