Fixed test
This commit is contained in:
@@ -30,6 +30,8 @@ import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.xml.namespace.QNameUtils;
|
||||
import org.springframework.xml.sax.SaxUtils;
|
||||
import org.springframework.xml.validation.XmlValidator;
|
||||
import org.springframework.xml.validation.XmlValidatorFactory;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.Node;
|
||||
@@ -61,6 +63,8 @@ public class SimpleXsdSchema implements XsdSchema, InitializingBean {
|
||||
|
||||
private Element schemaElement;
|
||||
|
||||
private XmlValidator validator;
|
||||
|
||||
/**
|
||||
* Create a new instance of the {@link SimpleXsdSchema} class.
|
||||
* <p/>
|
||||
@@ -88,6 +92,10 @@ public class SimpleXsdSchema implements XsdSchema, InitializingBean {
|
||||
return schemaDocuments;
|
||||
}
|
||||
|
||||
public XmlValidator getValidator() {
|
||||
return validator;
|
||||
}
|
||||
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
Assert.notNull(schemaResource, "'schema' is required");
|
||||
Assert.isTrue(schemaResource.exists(), "schema '" + schemaResource + "' does not exit");
|
||||
@@ -100,6 +108,7 @@ public class SimpleXsdSchema implements XsdSchema, InitializingBean {
|
||||
Assert.isTrue(SCHEMA_NAME.equals(name),
|
||||
"schema document has invalid qualified name: " + name + ". " + "Epected " + SCHEMA_NAME);
|
||||
Assert.hasLength(schemaElement.getAttribute("targetNamespace"), "schema does not define targetNamespace");
|
||||
validator = XmlValidatorFactory.createValidator(schemaResource, XmlValidatorFactory.SCHEMA_W3C_XML);
|
||||
}
|
||||
|
||||
/** Inner definition of {@link SimpleXsdSchemaDocument}. */
|
||||
|
||||
@@ -34,6 +34,8 @@ import org.springframework.core.io.Resource;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.xml.sax.SaxUtils;
|
||||
import org.springframework.xml.validation.XmlValidator;
|
||||
import org.springframework.xml.validation.XmlValidatorFactory;
|
||||
|
||||
/**
|
||||
* Implementation of the {@link XsdSchema} interface that uses <a href="http://ws.apache.org/commons/XmlSchema/">Apache
|
||||
@@ -53,6 +55,8 @@ public class WsCommonsXsdSchema implements XsdSchema, InitializingBean {
|
||||
|
||||
private XsdSchemaDocument[] schemaDocuments;
|
||||
|
||||
private XmlValidator validator;
|
||||
|
||||
/**
|
||||
* Create a new instance of the {@link WsCommonsXsdSchema} class.
|
||||
* <p/>
|
||||
@@ -91,6 +95,10 @@ public class WsCommonsXsdSchema implements XsdSchema, InitializingBean {
|
||||
this.schemaResources = schemaResources;
|
||||
}
|
||||
|
||||
public XmlValidator getValidator() {
|
||||
return validator;
|
||||
}
|
||||
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
Assert.notEmpty(schemaResources, "'schemaResources' must not be empty");
|
||||
XmlSchemaCollection schemaCollection = new XmlSchemaCollection();
|
||||
@@ -108,6 +116,7 @@ public class WsCommonsXsdSchema implements XsdSchema, InitializingBean {
|
||||
}
|
||||
}
|
||||
this.schemaDocuments = (XsdSchemaDocument[]) schemaList.toArray(new XsdSchemaDocument[schemaList.size()]);
|
||||
validator = XmlValidatorFactory.createValidator(schemaResources, XmlValidatorFactory.SCHEMA_W3C_XML);
|
||||
}
|
||||
|
||||
public XsdSchemaDocument[] getSchemaDocuments() {
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
|
||||
package org.springframework.xml.xsd;
|
||||
|
||||
import org.springframework.xml.validation.XmlValidator;
|
||||
|
||||
/**
|
||||
* Represents an abstraction for an XSD schema document. A schema is made up of one or more schema documents.
|
||||
*
|
||||
@@ -28,4 +30,7 @@ public interface XsdSchema {
|
||||
/** Returns the {@link XsdSchemaDocument} objects this schema consists of. */
|
||||
XsdSchemaDocument[] getSchemaDocuments();
|
||||
|
||||
/** Returns the {@link XmlValidator} based on this schema. */
|
||||
XmlValidator getValidator();
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user