protected static JAXBContext getJaxbContext(Class clazz) { Validate.notNull(clazz, "'clazz' must not be null"); JAXBContext jaxbContext = jaxbContexts.get(clazz); if (jaxbContext == null) { try { jaxbContext = JAXBContext.newInstance(clazz, CollectionWrapper.class); jaxbContexts.putIfAbsent(clazz, jaxbContext); } catch (JAXBException ex) { throw new RuntimeException("Could not instantiate JAXBContext for class [" + clazz + "]: " + ex.getMessage(), ex); } } return jaxbContext; }
/** * Return a {@link JAXBContext} for the given class. * @param clazz the class to return the context for * @return the {@code JAXBContext} * @throws HttpMessageConversionException in case of JAXB errors */ protected final JAXBContext getJaxbContext(Class<?> clazz) { Assert.notNull(clazz, "Class must not be null"); JAXBContext jaxbContext = this.jaxbContexts.get(clazz); if (jaxbContext == null) { try { jaxbContext = JAXBContext.newInstance(clazz); this.jaxbContexts.putIfAbsent(clazz, jaxbContext); } catch (JAXBException ex) { throw new HttpMessageConversionException( "Could not instantiate JAXBContext for class [" + clazz + "]: " + ex.getMessage(), ex); } } return jaxbContext; }
protected static JAXBContext getJaxbContext(Class clazz) { Validate.notNull(clazz, "'clazz' must not be null"); JAXBContext jaxbContext = jaxbContexts.get(clazz); if (jaxbContext == null) { try { jaxbContext = JAXBContext.newInstance(clazz, CollectionWrapper.class); jaxbContexts.putIfAbsent(clazz, jaxbContext); } catch (JAXBException ex) { throw new RuntimeException( "Could not instantiate JAXBContext for class [" + clazz + "]: " + ex.getMessage(), ex); } } return jaxbContext; }
public void updateJaxbElementFromDocument() { try { this.unmarshal(doc.getDocumentElement() ); } catch (JAXBException e) { log.error(e.getMessage(), e); } }
/** * Return a {@link JAXBContext} for the given class. * @param clazz the class to return the context for * @return the {@code JAXBContext} * @throws HttpMessageConversionException in case of JAXB errors */ protected final JAXBContext getJaxbContext(Class<?> clazz) { Assert.notNull(clazz, "Class must not be null"); JAXBContext jaxbContext = this.jaxbContexts.get(clazz); if (jaxbContext == null) { try { jaxbContext = JAXBContext.newInstance(clazz); this.jaxbContexts.putIfAbsent(clazz, jaxbContext); } catch (JAXBException ex) { throw new HttpMessageConversionException( "Could not instantiate JAXBContext for class [" + clazz + "]: " + ex.getMessage(), ex); } } return jaxbContext; }
@Override protected Object readFromSource(Class<?> clazz, HttpHeaders headers, Source source) throws Exception { try { source = processSource(source); Unmarshaller unmarshaller = createUnmarshaller(clazz); if (clazz.isAnnotationPresent(XmlRootElement.class)) { return unmarshaller.unmarshal(source); } else { JAXBElement<?> jaxbElement = unmarshaller.unmarshal(source, clazz); return jaxbElement.getValue(); } } catch (NullPointerException ex) { if (!isSupportDtd()) { throw new IllegalStateException("NPE while unmarshalling. " + "This can happen due to the presence of DTD declarations which are disabled.", ex); } throw ex; } catch (UnmarshalException ex) { throw ex; } catch (JAXBException ex) { throw new HttpMessageConversionException("Invalid JAXB setup: " + ex.getMessage(), ex); } }
/** * Create a new {@link Unmarshaller} for the given class. * @param clazz the class to create the unmarshaller for * @return the {@code Unmarshaller} * @throws HttpMessageConversionException in case of JAXB errors */ protected final Unmarshaller createUnmarshaller(Class<?> clazz) { try { JAXBContext jaxbContext = getJaxbContext(clazz); Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); customizeUnmarshaller(unmarshaller); return unmarshaller; } catch (JAXBException ex) { throw new HttpMessageConversionException( "Could not create Unmarshaller for class [" + clazz + "]: " + ex.getMessage(), ex); } }
/** * Create a new {@link Marshaller} for the given class. * @param clazz the class to create the marshaller for * @return the {@code Marshaller} * @throws HttpMessageConversionException in case of JAXB errors */ protected final Marshaller createMarshaller(Class<?> clazz) { try { JAXBContext jaxbContext = getJaxbContext(clazz); Marshaller marshaller = jaxbContext.createMarshaller(); customizeMarshaller(marshaller); return marshaller; } catch (JAXBException ex) { throw new HttpMessageConversionException( "Could not create Marshaller for class [" + clazz + "]: " + ex.getMessage(), ex); } }
public void marshal(java.io.OutputStream os) throws JAXBException { try { Marshaller marshaller = Context.jcContentTypes.createMarshaller(); NamespacePrefixMapperUtils.setProperty(marshaller, NamespacePrefixMapperUtils.getPrefixMapper() ); log.debug("marshalling " + this.getClass().getName() + " ..." ); marshaller.marshal(buildTypes(), os); } catch (JAXBException e) { //e.printStackTrace(); log.error(e.getMessage(), e); throw e; } }
public void marshal(org.w3c.dom.Node node) throws JAXBException { try { Marshaller marshaller = Context.jcContentTypes.createMarshaller(); NamespacePrefixMapperUtils.setProperty(marshaller, NamespacePrefixMapperUtils.getPrefixMapper() ); log.debug("marshalling " + this.getClass().getName() + " ..." ); marshaller.marshal(buildTypes(), node); log.debug("content types marshalled \n\n" ); } catch (JAXBException e) { //e.printStackTrace(); log.error(e.getMessage(), e); throw e; } }
public static void enteredTbl(BindingTraverserState btState, NodeIterator nodeIterator) { Node n = nodeIterator.nextNode(); //It is never null if (n != null) { try { Unmarshaller u = Context.jc.createUnmarshaller(); u.setEventHandler(new org.docx4j.jaxb.JaxbValidationEventHandler()); Object jaxb = u.unmarshal(n); btState.tblStack.push( (Tbl)jaxb); } catch (ClassCastException e) { log.error("Couldn't cast to Tbl!"); } catch (JAXBException e) { log.error(e.getMessage(), e); } } }
public static void enteredTc(BindingTraverserState btState, NodeIterator nodeIterator) { Node n = nodeIterator.nextNode(); //It is never null if (n!=null) { try { Unmarshaller u = Context.jc.createUnmarshaller(); u.setEventHandler(new org.docx4j.jaxb.JaxbValidationEventHandler()); Object jaxb = u.unmarshal(n); btState.tcStack.push( (Tc)jaxb ); } catch (ClassCastException e) { log.error("Couldn't cast to RPr!"); } catch (JAXBException e) { log.error(e.getMessage(), e); } } }
throw new HttpMessageConversionException("Invalid JAXB setup: " + ex.getMessage(), ex);
@Override protected void writeToResult(Object o, HttpHeaders headers, Result result) throws Exception { try { Class<?> clazz = ClassUtils.getUserClass(o); Marshaller marshaller = createMarshaller(clazz); setCharset(headers.getContentType(), marshaller); marshaller.marshal(o, result); } catch (MarshalException ex) { throw ex; } catch (JAXBException ex) { throw new HttpMessageConversionException("Invalid JAXB setup: " + ex.getMessage(), ex); } }
@Override // need this so that resetIdAllocator() is called public Relationships unmarshal(org.w3c.dom.Element el) throws JAXBException { try { Unmarshaller u = jc.createUnmarshaller(); u.setEventHandler(new org.docx4j.jaxb.JaxbValidationEventHandler()); jaxbElement = (Relationships) u.unmarshal( el ); } catch (JAXBException e) { // e.printStackTrace(); log.error(e.getMessage(), e); throw e; } resetIdAllocator(); return jaxbElement; }
/** * Create a new {@link Unmarshaller} for the given class. * @param clazz the class to create the unmarshaller for * @return the {@code Unmarshaller} * @throws HttpMessageConversionException in case of JAXB errors */ protected final Unmarshaller createUnmarshaller(Class<?> clazz) { try { JAXBContext jaxbContext = getJaxbContext(clazz); Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); customizeUnmarshaller(unmarshaller); return unmarshaller; } catch (JAXBException ex) { throw new HttpMessageConversionException( "Could not create Unmarshaller for class [" + clazz + "]: " + ex.getMessage(), ex); } }
/** * Create a new {@link Marshaller} for the given class. * @param clazz the class to create the marshaller for * @return the {@code Marshaller} * @throws HttpMessageConversionException in case of JAXB errors */ protected final Marshaller createMarshaller(Class<?> clazz) { try { JAXBContext jaxbContext = getJaxbContext(clazz); Marshaller marshaller = jaxbContext.createMarshaller(); customizeMarshaller(marshaller); return marshaller; } catch (JAXBException ex) { throw new HttpMessageConversionException( "Could not create Marshaller for class [" + clazz + "]: " + ex.getMessage(), ex); } }
@Override protected final E readFromSource(Class<? extends E> clazz, HttpHeaders headers, Source source) throws IOException { try { JAXBElement<? extends I> jaxbElement = createUnmarshaller().unmarshal(source, internalClass); return convertToExternal(jaxbElement.getValue()); } catch (UnmarshalException ex) { throw new HttpMessageNotReadableException("Could not unmarshal to [" + clazz + "]: " + ex.getMessage(), ex); } catch (JAXBException ex) { throw new HttpMessageConversionException("Could not instantiate JAXBContext: " + ex.getMessage(), ex); } }
@Override protected final void writeToResult(E accessToken, HttpHeaders headers, Result result) throws IOException { I convertedAccessToken = convertToInternal(accessToken); try { createMarshaller().marshal(convertedAccessToken, result); } catch (MarshalException ex) { throw new HttpMessageNotWritableException("Could not marshal [" + accessToken + "]: " + ex.getMessage(), ex); } catch (JAXBException ex) { throw new HttpMessageConversionException("Could not instantiate JAXBContext: " + ex.getMessage(), ex); } }
@Override protected void writeToResult(Object o, HttpHeaders headers, Result result) throws Exception { try { Class<?> clazz = ClassUtils.getUserClass(o); Marshaller marshaller = createMarshaller(clazz); setCharset(headers.getContentType(), marshaller); marshaller.marshal(o, result); } catch (MarshalException ex) { throw ex; } catch (JAXBException ex) { throw new HttpMessageConversionException("Invalid JAXB setup: " + ex.getMessage(), ex); } }