aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
authorChristof Rabensteiner <christof.rabensteiner@iaik.tugraz.at>2019-04-15 14:08:12 +0200
committerChristof Rabensteiner <christof.rabensteiner@iaik.tugraz.at>2019-04-15 14:08:12 +0200
commitc8271e5684e26b57880de7f1b8a3b0195ad6f68e (patch)
tree13c950f7a32ff000b90ba1e0bc89b54913ec60d8 /src/main/java
parent106a12c2ab80ccac70910f5b6e337ac24e04da65 (diff)
downloadmoa-zs-c8271e5684e26b57880de7f1b8a3b0195ad6f68e.tar.gz
moa-zs-c8271e5684e26b57880de7f1b8a3b0195ad6f68e.tar.bz2
moa-zs-c8271e5684e26b57880de7f1b8a3b0195ad6f68e.zip
Add Marshaller for autogenerated Schema Types
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/at/gv/egiz/moazs/MyMarshaller.java51
-rw-r--r--src/main/java/at/gv/egiz/moazs/MyMarshallerConfig.java22
2 files changed, 73 insertions, 0 deletions
diff --git a/src/main/java/at/gv/egiz/moazs/MyMarshaller.java b/src/main/java/at/gv/egiz/moazs/MyMarshaller.java
new file mode 100644
index 0000000..609a3c8
--- /dev/null
+++ b/src/main/java/at/gv/egiz/moazs/MyMarshaller.java
@@ -0,0 +1,51 @@
+package at.gv.egiz.moazs;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import javax.xml.bind.*;
+import java.io.ByteArrayInputStream;
+import java.io.StringWriter;
+
+@Component
+public class MyMarshaller {
+
+// @Value("classpath:mzs/app2mzs.xsd")
+// private Resource mzsSchema;
+//
+// @Value("classpath:mzs/mzs_mypersondata_en.xsd")
+// private Resource mzsPersonSchema;
+//
+// @Value("classpath:zusemsg/zuse_p2.xsd")
+// private Resource msgSchema;
+//
+// @Value("classpath:zusemsg/zuse_mypersondata_en_p2.xsd")
+// private Resource msgPersonSchema;
+
+
+ @Autowired
+ private JAXBContext context;
+
+ public byte[] toBytes(JAXBElement element) {
+ try {
+ Marshaller marshaller = context.createMarshaller();
+ StringWriter sw = new StringWriter();
+ marshaller.marshal(element, sw);
+ return sw.toString().getBytes();
+ } catch (JAXBException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public JAXBElement toJAXBElement(byte[] bytes) {
+ try {
+ Unmarshaller unmarshaller = context.createUnmarshaller();
+
+ var stream = new ByteArrayInputStream(bytes);
+ return (JAXBElement) unmarshaller.unmarshal(stream);
+
+ } catch (JAXBException e) {
+ throw new RuntimeException(e);
+ }
+ }
+}
diff --git a/src/main/java/at/gv/egiz/moazs/MyMarshallerConfig.java b/src/main/java/at/gv/egiz/moazs/MyMarshallerConfig.java
new file mode 100644
index 0000000..9842d49
--- /dev/null
+++ b/src/main/java/at/gv/egiz/moazs/MyMarshallerConfig.java
@@ -0,0 +1,22 @@
+package at.gv.egiz.moazs;
+
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBException;
+
+@Configuration
+public class MyMarshallerConfig {
+
+ @Bean
+ public JAXBContext jaxbcontext() throws JAXBException {
+ return JAXBContext.newInstance(
+ at.gv.e_government.reference.namespace.zustellung.mzs.persondata_.ObjectFactory.class,
+ at.gv.e_government.reference.namespace.zustellung.mzs.app2mzs_.ObjectFactory.class,
+ at.gv.e_government.reference.namespace.zustellung.msg.phase2._20181206_.ObjectFactory.class,
+ at.gv.e_government.reference.namespace.persondata.phase2._20181206_.ObjectFactory.class);
+
+ }
+
+}