1
2
3
4
5
6 package net.kwfgrid.gworkflowdl.protocol.xupdate;
7
8 import net.kwfgrid.gworkflowdl.protocol.calls.IMethodCall;
9 import net.kwfgrid.gworkflowdl.protocol.IMethodCallEncoder;
10 import net.kwfgrid.jxupdate.xupdate.XUpdateSerializer;
11
12 import java.io.IOException;
13 import java.io.StringWriter;
14
15 /***
16 Implementation of <code>IMethodCallEncoder</code> using XUpdate syntax.
17 */
18 public class XUMethodCallEncoder implements IMethodCallEncoder {
19 private XUMethodCallMarshaller _marshaller;
20
21 public XUMethodCallEncoder() {
22 _marshaller = new XUMethodCallMarshaller();
23 }
24
25 public String encode(IMethodCall call) throws IOException {
26 try {
27 XUpdateSerializer serializer = XUpdateSerializerPool.getInstance().getSerializer();
28 StringWriter out = new StringWriter();
29 serializer.setOutput(out);
30 serializer.startModifications();
31 call.marshal(_marshaller, serializer);
32 serializer.endModifications();
33 out.flush();
34 String enc = out.toString();
35 serializer.setOutput(null);
36 XUpdateSerializerPool.getInstance().returnObject(serializer);
37 return enc;
38 } catch (InterruptedException x) {
39 IOException iox = new IOException("Could not encode method call.");
40 iox.initCause(x);
41 throw iox;
42 }
43 }
44 }