From 161ecbfb9386978704bfc62fbf0dea5321a59aff Mon Sep 17 00:00:00 2001 From: Dave Hladky Date: Thu, 24 Jul 2014 09:41:01 -0500 Subject: [PATCH] Omaha #3441 Fixed OGC JaxbManager Former-commit-id: 43605bd21aae474317eb8df53d2690286134d894 [formerly b347066174364cd1b1bbe0aced94f78549f95a29] [formerly 58c2ad05a1c995851d1afebaa86557ae7d221a76] [formerly 43605bd21aae474317eb8df53d2690286134d894 [formerly b347066174364cd1b1bbe0aced94f78549f95a29] [formerly 58c2ad05a1c995851d1afebaa86557ae7d221a76] [formerly b65767edaaead34965255c79802be8568f7d4e6c [formerly 58c2ad05a1c995851d1afebaa86557ae7d221a76 [formerly d9bc5f4b929c44107f936b25255d2f39464bb21e]]]] Former-commit-id: b65767edaaead34965255c79802be8568f7d4e6c Former-commit-id: 368149c6924bb82f54b1a04bdba7f65979aee79e [formerly 3a44b01fedb530f7d5b4c9bfbeaa6ab640f5a922] [formerly 57d07775d8ce0756a78c273496dc714c4d82dab3 [formerly 3bd299d5115138d3d4cdd14139c2845b2501f428]] Former-commit-id: 1e2c7d003783d8703a9b70a59d77ee9e26a1fab7 [formerly b2b93e4899d0f91b80c95869811383a2670e37d1] Former-commit-id: e5056d01cbcca875b8eed04884ca0dd9b311d279 --- .../edex/ogc/common/jaxb/OgcJaxbManager.java | 49 ++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/edexOsgi/com.raytheon.uf.edex.ogc.common/src/com/raytheon/uf/edex/ogc/common/jaxb/OgcJaxbManager.java b/edexOsgi/com.raytheon.uf.edex.ogc.common/src/com/raytheon/uf/edex/ogc/common/jaxb/OgcJaxbManager.java index bbbf4029e6..f1b81f2639 100644 --- a/edexOsgi/com.raytheon.uf.edex.ogc.common/src/com/raytheon/uf/edex/ogc/common/jaxb/OgcJaxbManager.java +++ b/edexOsgi/com.raytheon.uf.edex.ogc.common/src/com/raytheon/uf/edex/ogc/common/jaxb/OgcJaxbManager.java @@ -19,10 +19,13 @@ */ package com.raytheon.uf.edex.ogc.common.jaxb; +import java.io.File; +import java.io.InputStream; import java.util.HashMap; import java.util.Map; import javax.xml.bind.JAXBContext; +import javax.xml.bind.JAXBElement; import javax.xml.bind.JAXBException; import javax.xml.bind.Marshaller; import javax.xml.parsers.ParserConfigurationException; @@ -30,6 +33,7 @@ import javax.xml.parsers.ParserConfigurationException; import org.w3c.dom.Node; import com.raytheon.uf.common.serialization.JAXBManager; +import com.raytheon.uf.common.serialization.SerializationException; import com.sun.xml.bind.api.JAXBRIContext; import com.sun.xml.bind.marshaller.NamespacePrefixMapper; @@ -45,6 +49,7 @@ import com.sun.xml.bind.marshaller.NamespacePrefixMapper; * Mar 30, 2011 bclement Initial creation * Aug 18, 2013 #2097 dhladky extended JAXBManager * Jul 15, 2014 3373 bclement rewritten to use JAXBManager + * Jul 23, 2014 dhladky restored JAXBElement unwrapping lost in re-write. * * * @@ -141,7 +146,7 @@ public class OgcJaxbManager extends JAXBManager { */ public Object unmarshal(Node node) throws JAXBException { JAXBContext ctx = getJaxbContext(); - return marshStrategy.unmarshal(ctx, node); + return extractJaxbElement(marshStrategy.unmarshal(ctx, node)); } /** @@ -156,5 +161,47 @@ public class OgcJaxbManager extends JAXBManager { JAXBContext ctx = getJaxbContext(); return marshStrategy.marshalToNode(ctx, obj); } + + /** + * Override of JAXB manager, pulls Objects out of JAXBElement + * @param xml + * @return + * @throws JAXBException + */ + public Object unmarshalFromXml(String xml) throws JAXBException { + return extractJaxbElement(super.unmarshalFromXml(xml)); + } + + /** + * Override of JAXB manager, pulls Objects out of JAXBElement + * @param InputStream + * @return + * @throws SerializationException + */ + public Object unmarshalFromInputStream(InputStream is) throws SerializationException { + return extractJaxbElement(super.unmarshalFromInputStream(is)); + } + + /** + * OGC override of internalUnmarshalFromXmlFile + * @param file + * the file to unmarshal and object from. + * @return the object from the file + * @throws SerializationException + */ + protected Object internalUnmarshalFromXmlFile(File file) + throws SerializationException { + return extractJaxbElement(super.internalUnmarshalFromXmlFile(file)); + } + + /** + * Extracts the Object from the JAXBElement wrapper + */ + private Object extractJaxbElement(Object o) { + if (o instanceof JAXBElement) { + o = ((JAXBElement) o).getValue(); + } + return o; + } }