]> git.argeo.org Git - gpl/argeo-slc.git/blob - eclipse/plugins/runtime/org.argeo.slc.client.oxm/src/main/java/org/argeo/slc/client/oxm/OxmBean.java
+ refactor to separate runtime and module project under eclipse plugin.
[gpl/argeo-slc.git] / eclipse / plugins / runtime / org.argeo.slc.client.oxm / src / main / java / org / argeo / slc / client / oxm / OxmBean.java
1 package org.argeo.slc.client.oxm;
2
3 import org.argeo.slc.SlcException;
4 import org.springframework.oxm.Marshaller;
5 import org.springframework.oxm.Unmarshaller;
6 import org.springframework.xml.transform.StringResult;
7 import org.springframework.xml.transform.StringSource;
8
9 public class OxmBean implements OxmInterface {
10
11 private Marshaller marshaller;
12 private Unmarshaller unmarshaller;
13
14 public void init() {
15 }
16
17 public Object unmarshal(String result) {
18 Object res;
19 if (result == null)
20 throw new SlcException("Cannot unmarshall empty string ");
21 try {
22 res = unmarshaller.unmarshal(new StringSource(result));
23 } catch (Exception e) {
24 throw new SlcException("Could not unmarshall " + result, e);
25 }
26 return res;
27 }
28
29 public String marshal(Object graph) {
30 StringResult result = new StringResult();
31 try {
32 marshaller.marshal(graph, result);
33 } catch (Exception e) {
34 throw new SlcException("Cannot Marshal object " + graph.toString()
35 + " - " + e);
36 }
37 return result.toString();
38 }
39
40 // IoC
41 public void setMarshaller(Marshaller marshaller) {
42 this.marshaller = marshaller;
43 }
44
45 public void setUnmarshaller(Unmarshaller unmarshaller) {
46 this.unmarshaller = unmarshaller;
47 }
48 }