|
|
|
@ -140,6 +140,8 @@ public class Jaxb2Marshaller implements MimeMarshaller, MimeUnmarshaller, BeanCl |
|
|
|
|
|
|
|
|
|
|
|
private Schema schema; |
|
|
|
private Schema schema; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private boolean lazyInit = false; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Set a JAXB context path. |
|
|
|
* Set a JAXB context path. |
|
|
|
@ -259,33 +261,55 @@ public class Jaxb2Marshaller implements MimeMarshaller, MimeUnmarshaller, BeanCl |
|
|
|
this.mtomEnabled = mtomEnabled; |
|
|
|
this.mtomEnabled = mtomEnabled; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Set whether to lazily initialize the {@link JAXBContext} for this marshaller. |
|
|
|
|
|
|
|
* Default is {@code false} to initialize on startup; can be switched to |
|
|
|
|
|
|
|
* {@code true}. |
|
|
|
|
|
|
|
* <p>Early initialization just applies if <code>afterPropertiesSet()</code> is called. |
|
|
|
|
|
|
|
* @see #afterPropertiesSet() |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public void setLazyInit(boolean lazyInit) { |
|
|
|
|
|
|
|
this.lazyInit = lazyInit; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void setBeanClassLoader(ClassLoader classLoader) { |
|
|
|
public void setBeanClassLoader(ClassLoader classLoader) { |
|
|
|
this.beanClassLoader = classLoader; |
|
|
|
this.beanClassLoader = classLoader; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public final void afterPropertiesSet() throws Exception { |
|
|
|
public final void afterPropertiesSet() throws Exception { |
|
|
|
this.jaxbContext = createJaxbContext(); |
|
|
|
|
|
|
|
if (!ObjectUtils.isEmpty(this.schemaResources)) { |
|
|
|
|
|
|
|
this.schema = loadSchema(this.schemaResources, this.schemaLanguage); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected JAXBContext createJaxbContext() throws Exception { |
|
|
|
|
|
|
|
if (StringUtils.hasLength(this.contextPath) && !ObjectUtils.isEmpty(this.classesToBeBound)) { |
|
|
|
if (StringUtils.hasLength(this.contextPath) && !ObjectUtils.isEmpty(this.classesToBeBound)) { |
|
|
|
throw new IllegalArgumentException("Specify either 'contextPath' or 'classesToBeBound property'; not both"); |
|
|
|
throw new IllegalArgumentException("Specify either 'contextPath' or 'classesToBeBound property'; not both"); |
|
|
|
} |
|
|
|
} |
|
|
|
if (StringUtils.hasLength(this.contextPath)) { |
|
|
|
else if (!StringUtils.hasLength(this.contextPath) && ObjectUtils.isEmpty(this.classesToBeBound)) { |
|
|
|
return createJaxbContextFromContextPath(); |
|
|
|
throw new IllegalArgumentException("Setting either 'contextPath' or 'classesToBeBound' is required"); |
|
|
|
} |
|
|
|
} |
|
|
|
else if (!ObjectUtils.isEmpty(this.classesToBeBound)) { |
|
|
|
if (!lazyInit) { |
|
|
|
return createJaxbContextFromClasses(); |
|
|
|
getJaxbContext(); |
|
|
|
} |
|
|
|
} |
|
|
|
else { |
|
|
|
if (!ObjectUtils.isEmpty(this.schemaResources)) { |
|
|
|
throw new IllegalArgumentException("setting either contextPath or classesToBeBound is required"); |
|
|
|
this.schema = loadSchema(this.schemaResources, this.schemaLanguage); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected synchronized JAXBContext getJaxbContext() { |
|
|
|
|
|
|
|
if (this.jaxbContext == null) { |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
if (StringUtils.hasLength(this.contextPath)) { |
|
|
|
|
|
|
|
this.jaxbContext = createJaxbContextFromContextPath(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else if (!ObjectUtils.isEmpty(this.classesToBeBound)) { |
|
|
|
|
|
|
|
this.jaxbContext = createJaxbContextFromClasses(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
catch (JAXBException ex) { |
|
|
|
|
|
|
|
throw convertJaxbException(ex); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return jaxbContext; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private JAXBContext createJaxbContextFromContextPath() throws JAXBException { |
|
|
|
private JAXBContext createJaxbContextFromContextPath() throws JAXBException { |
|
|
|
if (logger.isInfoEnabled()) { |
|
|
|
if (logger.isInfoEnabled()) { |
|
|
|
logger.info("Creating JAXBContext with context path [" + this.contextPath + "]"); |
|
|
|
logger.info("Creating JAXBContext with context path [" + this.contextPath + "]"); |
|
|
|
@ -364,7 +388,6 @@ public class Jaxb2Marshaller implements MimeMarshaller, MimeUnmarshaller, BeanCl |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Marshalling
|
|
|
|
// Marshalling
|
|
|
|
|
|
|
|
|
|
|
|
public void marshal(Object graph, Result result) throws XmlMappingException { |
|
|
|
public void marshal(Object graph, Result result) throws XmlMappingException { |
|
|
|
@ -410,7 +433,7 @@ public class Jaxb2Marshaller implements MimeMarshaller, MimeUnmarshaller, BeanCl |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
protected Marshaller createMarshaller() { |
|
|
|
protected Marshaller createMarshaller() { |
|
|
|
try { |
|
|
|
try { |
|
|
|
Marshaller marshaller = this.jaxbContext.createMarshaller(); |
|
|
|
Marshaller marshaller = getJaxbContext().createMarshaller(); |
|
|
|
initJaxbMarshaller(marshaller); |
|
|
|
initJaxbMarshaller(marshaller); |
|
|
|
return marshaller; |
|
|
|
return marshaller; |
|
|
|
} |
|
|
|
} |
|
|
|
@ -495,7 +518,7 @@ public class Jaxb2Marshaller implements MimeMarshaller, MimeUnmarshaller, BeanCl |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
protected Unmarshaller createUnmarshaller() { |
|
|
|
protected Unmarshaller createUnmarshaller() { |
|
|
|
try { |
|
|
|
try { |
|
|
|
Unmarshaller unmarshaller = this.jaxbContext.createUnmarshaller(); |
|
|
|
Unmarshaller unmarshaller = getJaxbContext().createUnmarshaller(); |
|
|
|
initJaxbUnmarshaller(unmarshaller); |
|
|
|
initJaxbUnmarshaller(unmarshaller); |
|
|
|
return unmarshaller; |
|
|
|
return unmarshaller; |
|
|
|
} |
|
|
|
} |
|
|
|
@ -557,7 +580,6 @@ public class Jaxb2Marshaller implements MimeMarshaller, MimeUnmarshaller, BeanCl |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static class Jaxb2AttachmentMarshaller extends AttachmentMarshaller { |
|
|
|
private static class Jaxb2AttachmentMarshaller extends AttachmentMarshaller { |
|
|
|
|
|
|
|
|
|
|
|
private final MimeContainer mimeContainer; |
|
|
|
private final MimeContainer mimeContainer; |
|
|
|
|