package com.example; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBElement; import javax.xml.bind.Unmarshaller; import javax.xml.bind.util.JAXBSource; import javax.xml.namespace.QName; public class Demo { public static void main(String[] args) throws Exception { com.home.Student studentA = new com.home.Student(); studentA.setName("Jane Doe"); studentA.setStatus(com.home.Status.FULL_TIME); JAXBContext contextA = JAXBContext.newInstance(com.home.Student.class); JAXBElement<com.home.Student> jaxbElementA = new JAXBElement(new QName("student"), com.home.Student.class, studentA); JAXBSource sourceA = new JAXBSource(contextA, jaxbElementA); JAXBContext contextB = JAXBContext.newInstance(com.school.Student.class); Unmarshaller unmarshallerB = contextB.createUnmarshaller(); JAXBElement<com.school.Student> jaxbElementB = unmarshallerB.unmarshal(sourceA, com.school.Student.class); com.school.Student studentB = jaxbElementB.getValue(); System.out.println(studentB.getName()); System.out.println(studentB.getStatus().getCode()); } }
qname, clazz, wrapped); JAXBSource source = new JAXBSource(jc, contentObject); elem = jc.createUnmarshaller().unmarshal(source, clazz); Class<T> clazz = (Class<T>) value.getClass(); JAXBElement<T> contentObject = new JAXBElement<T>(new QName(clazz.getSimpleName()), clazz, value); JAXBSource source = new JAXBSource(jc, contentObject); elem = jc.createUnmarshaller().unmarshal(source, clazz);
public Source toSource() { JAXBContext context; try { context = JAXBContext.newInstance(getClass()); return new JAXBSource(context, this); } catch (JAXBException e) { throw new RuntimeException("Unable to marshal JAXB object to source", e); } }
public static <T> void xmlToXhtml(T catalog, StreamSource xslt, StreamResult result) { try { TransformerFactory.newInstance().newTransformer(xslt) .transform(new JAXBSource(JAXBContext.newInstance(catalog.getClass()), catalog), result); } catch (JAXBException | TransformerException e) { throw new IllegalStateException(e); } }
static public <T> T deepCopy(T object) { if (object == null) return null; try { @SuppressWarnings("unchecked") Class<T> clazz = (Class<T>)object.getClass(); JAXBContext context = JAXBContext.newInstance(clazz); JAXBElement<T> contentObject = new JAXBElement<T>(new QName(clazz.getSimpleName()), clazz, object); JAXBSource source = new JAXBSource(context, contentObject); return context.createUnmarshaller().unmarshal(source, clazz).getValue(); } catch (JAXBException e) { throw new RuntimeException(e); } }
public JAXBSource getAsJAXBSource() throws JAXBException { return new JAXBSource(createMarshaller(), this); }
public static Cell copyCell(Cell cell, Unmarshaller unmarshaller, Marshaller marshaller) { try { JAXBElement<Cell> contentObject = new JAXBElement<>(new QName(cellName), Cell.class, cell); JAXBSource source = new JAXBSource(marshaller, contentObject); source.setXMLReader(new PseudoXMLReader(marshaller, contentObject)); JAXBElement<Cell> elem = unmarshaller.unmarshal(source, Cell.class); return elem.getValue(); } catch (JAXBException e) { throw new IllegalStateException(e); } }
public static Cell copyCell(Cell cell, Unmarshaller unmarshaller, Marshaller marshaller) { try { JAXBElement<Cell> contentObject = new JAXBElement<>(new QName(cellName), Cell.class, cell); JAXBSource source = new JAXBSource(marshaller, contentObject); source.setXMLReader(new PseudoXMLReader(marshaller, contentObject)); JAXBElement<Cell> elem = unmarshaller.unmarshal(source, Cell.class); return elem.getValue(); } catch (JAXBException e) { throw new IllegalStateException(e); } }
private JAXBSource dppToJaxbSource(DppType dpp) { try { JAXBElement<DppType> dppJaxb = new ObjectFactory().createDpp(dpp); return new JAXBSource(JAXBContext.newInstance(METADATA_PACKAGE), dppJaxb); } catch (JAXBException e) { throw new RuntimeException(e); } } }
public static void transform(JAXBContext context, JAXBElement<?> jaxb, Result result) throws ParsingException { try { Transformer transformer = getTransformer(); JAXBSource jaxbSource = new JAXBSource(context, jaxb); transformer.transform(jaxbSource, result); } catch (Exception e) { throw logger.parserError(e); } }
public static void transform(JAXBContext context, JAXBElement<?> jaxb, Result result) throws ParsingException { try { Transformer transformer = getTransformer(); JAXBSource jaxbSource = new JAXBSource(context, jaxb); transformer.transform(jaxbSource, result); } catch (Exception e) { throw logger.parserError(e); } }
public static void transform(JAXBContext context, JAXBElement<?> jaxb, Result result) throws ParsingException { try { Transformer transformer = getTransformer(); JAXBSource jaxbSource = new JAXBSource(context, jaxb); transformer.transform(jaxbSource, result); } catch (Exception e) { throw logger.parserError(e); } }
public static void transform(JAXBContext context, JAXBElement<?> jaxb, Result result) throws ParsingException { try { Transformer transformer = getTransformer(); JAXBSource jaxbSource = new JAXBSource(context, jaxb); transformer.transform(jaxbSource, result); } catch (Exception e) { throw logger.parserError(e); } }
public static void transform(JAXBContext context, JAXBElement<?> jaxb, Result result) throws ParsingException { try { Transformer transformer = getTransformer(); JAXBSource jaxbSource = new JAXBSource(context, jaxb); transformer.transform(jaxbSource, result); } catch (Exception e) { throw new ParsingException(e); } }
public static void transform(JAXBContext context, JAXBElement<?> jaxb, Result result) throws ParsingException { try { Transformer transformer = getTransformer(); JAXBSource jaxbSource = new JAXBSource(context, jaxb); transformer.transform(jaxbSource, result); } catch (Exception e) { throw new ParsingException(e); } }
@Override public Source getPayload() { JAXBContext context = ctxt; if (context == null) { context = defaultJaxbContext.getJAXBContext(); } try { return new JAXBSource(context, o); } catch (JAXBException e) { throw new WebServiceException(e); } }
@Override public Source getPayload() { JAXBContext context = ctxt; if (context == null) { context = defaultJaxbContext.getJAXBContext(); } try { return new JAXBSource(context, o); } catch (JAXBException e) { throw new WebServiceException(e); } }
@Override public Source getPayload() { JAXBContext context = ctxt; if (context == null) { context = defaultJaxbContext.getJAXBContext(); } try { return new JAXBSource(context, o); } catch (JAXBException e) { throw new WebServiceException(e); } }
private Source getOwnedUsers(String userName) throws JAXBException { MCRUser owner = MCRUserManager.getUser(userName); List<MCRUser> listUsers = MCRUserManager.listUsers(owner); MCROwns mcrOwns = new MCROwns(); int userCount = listUsers.size(); mcrOwns.users = new MCRUser[userCount]; for (int i = 0; i < userCount; i++) { mcrOwns.users[i] = listUsers.get(i).getBasicCopy(); } return new JAXBSource(MCRUserTransformer.JAXB_CONTEXT, mcrOwns); }
private static void validateWithXsd(Object object, String schemaName) { try { Source source = new JAXBSource(JAXB_CONTEXT, object); XSD_VALIDATOR.validate(source, schemaName); } catch (ValidationException e) { throw new HpdException(e, ErrorType.MALFORMED_REQUEST); } catch (Exception e) { throw new HpdException(e, ErrorType.OTHER); } }