List of usage examples for javax.xml.bind JAXBElement getValue
public T getValue()
Return the content model and attribute values for this element.
See #isNil() for a description of a property constraint when this value is null
From source file:Main.java
public static Object xmlToJaxb(Class<?> xmlClass, String xml) throws JAXBException { JAXBContext jaxbContext = JAXBContext.newInstance(xmlClass); Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); JAXBElement<?> element; try (StringReader reader = new StringReader(xml)) { element = (JAXBElement<?>) unmarshaller.unmarshal(reader); }/*w ww . ja v a2 s.c om*/ return element.getValue(); }
From source file:net.sf.dynamicreports.report.defaults.Defaults.java
private static XmlDynamicReports load() { String resource = "dynamicreports-defaults.xml"; InputStream is = null;/*from w w w. j a v a 2 s . c o m*/ ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); if (classLoader != null) { is = classLoader.getResourceAsStream(resource); } if (is == null) { classLoader = Defaults.class.getClassLoader(); if (classLoader != null) { is = classLoader.getResourceAsStream(resource); } if (is == null) { is = Defaults.class.getResourceAsStream("/" + resource); } } if (is == null) { return null; } try { Unmarshaller unmarshaller = JAXBContext.newInstance(XmlDynamicReports.class).createUnmarshaller(); JAXBElement<XmlDynamicReports> root = unmarshaller.unmarshal(new StreamSource(is), XmlDynamicReports.class); return root.getValue(); } catch (JAXBException e) { log.error("Could not load dynamic reports defaults", e); return null; } }
From source file:com.labs64.utils.swid.support.JAXBUtils.java
public static <T> T readObjectFromInputStream(final InputStream inputStream, final Class<T> expectedType) { try {/* w ww. j av a2 s .c o m*/ JAXBContext jaxbContext = JAXBContext.newInstance(expectedType); Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); JAXBElement<T> element = unmarshaller.unmarshal(new StreamSource(inputStream), expectedType); return element.getValue(); } catch (final JAXBException e) { throw new SwidException("Cannot process resource.", e); } }
From source file:fr.mael.microrss.util.XMLUtil.java
public static String readLinkType(String name, List<Object> objects) { for (Object o : objects) { if (o instanceof JAXBElement) { JAXBElement element = (JAXBElement) o; if (name.equals(element.getName().getLocalPart()) && element.getValue() instanceof LinkType) { LinkType textType = (LinkType) element.getValue(); return textType.getHref(); }/* w w w.j ava2 s .c o m*/ } } return null; }
From source file:fr.mael.microrss.util.XMLUtil.java
public static XMLGregorianCalendar readDateTimeType(String name, List<Object> objects) { for (Object o : objects) { if (o instanceof JAXBElement) { JAXBElement element = (JAXBElement) o; if (name.equals(element.getName().getLocalPart()) && element.getValue() instanceof DateTimeType) { DateTimeType dateTimeType = (DateTimeType) element.getValue(); return dateTimeType.getValue(); }//from w w w . j a v a 2 s .c o m } } return null; }
From source file:fr.mael.microrss.util.XMLUtil.java
public static String readTextType(String name, List<Object> objects) { for (Object o : objects) { if (o instanceof JAXBElement) { JAXBElement element = (JAXBElement) o; if (name.equals(element.getName().getLocalPart()) && element.getValue() instanceof TextType) { StringBuffer result = new StringBuffer(); TextType textType = (TextType) element.getValue(); for (Object content : textType.getContent()) { result.append(content); }/*from w ww . j a va2 s.c o m*/ return result.toString(); } } } return null; }
From source file:fr.mael.microrss.util.XMLUtil.java
public static String readContentType(String name, List<Object> objects) { for (Object o : objects) { if (o instanceof JAXBElement) { JAXBElement element = (JAXBElement) o; if (name.equals(element.getName().getLocalPart()) && element.getValue() instanceof ContentType) { StringBuffer result = new StringBuffer(); ContentType contentType = (ContentType) element.getValue(); for (Object content : contentType.getContent()) { result.append(content); }/*from w w w. j ava2 s . c o m*/ return result.toString(); } } } return null; }
From source file:cz.lbenda.dataman.rc.DbConfigFactory.java
public static void load(final String document) { if (StringUtils.isBlank(document)) { return;/*ww w. jav a 2 s .c o m*/ } try { JAXBContext jc = JAXBContext.newInstance(cz.lbenda.dataman.schema.dataman.ObjectFactory.class); Unmarshaller u = jc.createUnmarshaller(); JAXBElement o = (JAXBElement) u.unmarshal(new StringReader(document)); if (o.getValue() instanceof DatamanType) { DatamanType dc = (DatamanType) o.getValue(); if (dc.getSessions() == null || dc.getSessions().getSession().isEmpty()) { LOG.info("No configuration for loading"); } else { configurations.clear(); for (SessionType session : dc.getSessions().getSession()) { DbConfig sc = new DbConfig(); configurations.add(sc); sc.fromSessionType(session, true); } } } else { LOG.error("The string didn't contains dataman configuration: " + o.getClass().getName()); } } catch (JAXBException e) { LOG.error("Problem with reading dataman configuration\nXML:" + document + "\n" + e.toString(), e); } }
From source file:edu.harvard.i2b2.crc.loader.datavo.I2B2MessageResponseFactory.java
/** * Function to unmarshall i2b2 request message type * /* w w w .ja v a2 s.c om*/ * @param requestXml * @return RequestMessageType * @throws JAXBUtilException */ private static RequestMessageType getI2B2RequestMessageType(String requestXml) throws JAXBUtilException { JAXBUtil jaxbUtil = CRCLoaderJAXBUtil.getJAXBUtil(); JAXBElement jaxbElement = jaxbUtil.unMashallFromString(requestXml); RequestMessageType requestMessageType = (RequestMessageType) jaxbElement.getValue(); return requestMessageType; }
From source file:edu.harvard.i2b2.crc.datavo.I2B2MessageResponseFactory.java
/** * Function to unmarshall i2b2 request message type * //from ww w. j a va 2 s. c o m * @param requestXml * @return RequestMessageType * @throws JAXBUtilException */ private static RequestMessageType getI2B2RequestMessageType(String requestXml) throws JAXBUtilException { JAXBUtil jaxbUtil = CRCJAXBUtil.getJAXBUtil(); JAXBElement jaxbElement = jaxbUtil.unMashallFromString(requestXml); RequestMessageType requestMessageType = (RequestMessageType) jaxbElement.getValue(); return requestMessageType; }