]> git.argeo.org Git - gpl/argeo-slc.git/blob - runtime/org.argeo.slc.lib.detached/src/main/java/org/argeo/slc/lib/detached/DetachedXmlConverterSpring.java
SystemCall, JvmProcess, DetachedLauncher enhancements
[gpl/argeo-slc.git] / runtime / org.argeo.slc.lib.detached / src / main / java / org / argeo / slc / lib / detached / DetachedXmlConverterSpring.java
1 package org.argeo.slc.lib.detached;
2
3 import javax.xml.transform.Result;
4 import javax.xml.transform.Source;
5
6 import org.argeo.slc.SlcException;
7 import org.argeo.slc.detached.DetachedAnswer;
8 import org.argeo.slc.detached.DetachedCommunication;
9 import org.argeo.slc.detached.DetachedException;
10 import org.argeo.slc.detached.DetachedRequest;
11 import org.argeo.slc.detached.DetachedXmlConverter;
12 import org.springframework.oxm.Marshaller;
13 import org.springframework.oxm.Unmarshaller;
14
15 public class DetachedXmlConverterSpring implements DetachedXmlConverter {
16 private Marshaller marshaller;
17 private Unmarshaller unmarshaller;
18
19 public void marshallCommunication(DetachedCommunication detCom,
20 Result result) {
21 if (detCom instanceof DetachedRequest) {
22 marshallRequest((DetachedRequest) detCom, result);
23 } else if (detCom instanceof DetachedAnswer) {
24 marshallAnswer((DetachedAnswer) detCom, result);
25 } else {
26 throw new DetachedException("Unkown communication type "
27 + detCom.getClass());
28 }
29 }
30
31 public DetachedCommunication unmarshallCommunication(Source source) {
32 try {
33 return (DetachedCommunication) unmarshaller.unmarshal(source);
34 } catch (Exception e) {
35 throw new SlcException("Could not unmarshall", e);
36 }
37 }
38
39 public void marshallRequest(DetachedRequest request, Result result) {
40 try {
41 marshaller.marshal(request, result);
42 } catch (Exception e) {
43 throw new SlcException("Could not marshall", e);
44 }
45 }
46
47 public void marshallAnswer(DetachedAnswer answer, Result result) {
48 try {
49 marshaller.marshal(answer, result);
50 } catch (Exception e) {
51 throw new SlcException("Could not marshall", e);
52 }
53 }
54
55 public void setMarshaller(Marshaller marshaller) {
56 this.marshaller = marshaller;
57 }
58
59 public void setUnmarshaller(Unmarshaller unmarshaller) {
60 this.unmarshaller = unmarshaller;
61 }
62
63 }