SPR-8349 - Ability to specify ResourceResolver property for SchemaFactory in Jaxb2Marshaller

This commit is contained in:
Arjen Poutsma 2011-12-07 00:56:03 +00:00
parent 7428b57052
commit 29e969039d
1 changed files with 25 additions and 9 deletions

View File

@ -16,7 +16,7 @@
package org.springframework.oxm.jaxb;
import java.awt.*;
import java.awt.Image;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
@ -65,13 +65,6 @@ import javax.xml.transform.sax.SAXSource;
import javax.xml.validation.Schema;
import javax.xml.validation.SchemaFactory;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;
import org.xml.sax.helpers.XMLReaderFactory;
import org.springframework.beans.factory.BeanClassLoaderAware;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.core.annotation.AnnotationUtils;
@ -94,6 +87,14 @@ import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
import org.springframework.util.xml.StaxUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.w3c.dom.ls.LSResourceResolver;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;
import org.xml.sax.helpers.XMLReaderFactory;
/**
* Implementation of the <code>Marshaller</code> interface for JAXB 2.0.
*
@ -160,6 +161,8 @@ public class Jaxb2Marshaller
private boolean supportJaxbElementClass = false;
private LSResourceResolver schemaResourceResolver;
/**
* Set multiple JAXB context paths. The given array of context paths is converted to a
@ -286,7 +289,17 @@ public class Jaxb2Marshaller
this.schemaLanguage = schemaLanguage;
}
/**
/**
* Sets the resource resolver, as used to load the schema resources.
* @see SchemaFactory#setResourceResolver(org.w3c.dom.ls.LSResourceResolver)
* @see #setSchema(Resource)
* @see #setSchemas(Resource[])
*/
public void setSchemaResourceResolver(LSResourceResolver schemaResourceResolver) {
this.schemaResourceResolver = schemaResourceResolver;
}
/**
* Specify whether MTOM support should be enabled or not.
* Default is <code>false</code>: marshalling using XOP/MTOM not being enabled.
*/
@ -407,6 +420,9 @@ public class Jaxb2Marshaller
schemaSources[i] = new SAXSource(xmlReader, inputSource);
}
SchemaFactory schemaFactory = SchemaFactory.newInstance(schemaLanguage);
if (schemaResourceResolver != null) {
schemaFactory.setResourceResolver(schemaResourceResolver);
}
return schemaFactory.newSchema(schemaSources);
}