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