Permalink
Browse files

AS7-1263, add the deployment descriptor schemas and DTDs in docs/sche…

…ma and use a local resource to validate xsd files, based on 7.0.5.Final metadata.
  • Loading branch information...
soul2zimate authored and bstansberry committed Jul 19, 2012
1 parent 90bbbb0 commit 0cc6f77b981fa26f5684059b2475bf53a8dc8216
View
@@ -96,12 +96,51 @@
<!-- Copy the EJB specific schemas to the JBOSS_HOME/docs/schema folder -->
<unzip src="${org.jboss.metadata:jboss-metadata-ejb:jar}" dest="${output.dir}/docs/schema/">
<patternset>
- <include name="schema/ejb-jar*.xsd"/>
- <include name="schema/jboss-ejb3*.xsd"/>
+ <include name="schema/*.xsd"/>
<include name="dtd/ejb-jar*.dtd"/>
</patternset>
<mapper type="flatten"/>
</unzip>
+
+ <!-- Copy the jboss-metadata-appclient specific schemas to the JBOSS_HOME/docs/schema folder -->
+ <unzip src="${org.jboss.metadata:jboss-metadata-appclient:jar}" dest="${output.dir}/docs/schema/">
+ <patternset>
+ <include name="schema/*.xsd"/>
+ </patternset>
+ <mapper type="flatten"/>
+ </unzip>
+
+ <!-- Copy the jboss-metadata-ear specific schemas to the JBOSS_HOME/docs/schema folder -->
+ <unzip src="${org.jboss.metadata:jboss-metadata-ear:jar}" dest="${output.dir}/docs/schema/">
+ <patternset>
+ <include name="dtd/*.dtd"/>
+ <include name="schema/*.xsd"/>
+ <exclude name="schema/jboss-app_6_0.xsd"/>
+ </patternset>
+ <mapper type="flatten"/>
+ </unzip>
+
+ <!-- Copy the jboss-metadata-common specific schemas to the JBOSS_HOME/docs/schema folder -->
+ <unzip src="${org.jboss.metadata:jboss-metadata-common:jar}" dest="${output.dir}/docs/schema/">
+ <patternset>
+ <include name="dtd/*.dtd"/>
+ <include name="schema/*.xsd"/>
+ <exclude name="dtd/XMLSchema.dtd"/>
+ <exclude name="dtd/datatypes.dtd"/>
+ <exclude name="schema/xml.xsd"/>
+ </patternset>
+ <mapper type="flatten"/>
+ </unzip>
+
+ <!-- Copy the jboss-metadata-web specific schemas to the JBOSS_HOME/docs/schema folder -->
+ <unzip src="${org.jboss.metadata:jboss-metadata-web:jar}" dest="${output.dir}/docs/schema/">
+ <patternset>
+ <include name="dtd/*.dtd"/>
+ <include name="schema/*.xsd"/>
+ </patternset>
+ <mapper type="flatten"/>
+ </unzip>
+
<!-- Copy the JBoss AS7 EJB specific schemas to the JBOSS_HOME/docs/schema folder -->
<unzip src="${org.jboss.as:jboss-as-ejb3:jar}" dest="${output.dir}/docs/schema/">
<patternset>
View
@@ -175,7 +175,7 @@
<version.org.jboss.logmanager.log4j-jboss-logmanager>1.0.1.Final</version.org.jboss.logmanager.log4j-jboss-logmanager>
<version.org.jboss.marshalling.jboss-marshalling>1.3.15.GA</version.org.jboss.marshalling.jboss-marshalling>
<version.org.jboss.marshalling.jboss-marshalling-river>1.3.15.GA</version.org.jboss.marshalling.jboss-marshalling-river>
- <version.org.jboss.metadata>7.0.4.Final</version.org.jboss.metadata>
+ <version.org.jboss.metadata>7.0.5.Final</version.org.jboss.metadata>
<version.org.jboss.mod_cluster>1.2.1.Final</version.org.jboss.mod_cluster>
<version.org.jboss.modules.jboss-modules>1.1.3.GA</version.org.jboss.modules.jboss-modules>
<version.org.jboss.msc.jboss-msc>1.0.2.GA</version.org.jboss.msc.jboss-msc>
@@ -24,8 +24,17 @@
import org.junit.Test;
import javax.xml.XMLConstants;
+import javax.xml.validation.Schema;
import javax.xml.validation.SchemaFactory;
import java.io.File;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.DocumentBuilder;
+import org.w3c.dom.Document;
+import org.jboss.metadata.parser.util.XMLResourceResolver;
+import javax.xml.validation.Validator;
+import javax.xml.transform.dom.DOMSource;
+import java.net.URL;
+import static junit.framework.Assert.assertNotNull;
/**
* A XSDValidationUnitTestCase.
@@ -42,9 +51,24 @@ public void testJBossXsds() throws Exception {
}
private void validateXsd(final File xsdFile) throws Exception {
+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+ factory.setNamespaceAware(true);
+ DocumentBuilder parser = factory.newDocumentBuilder();
+ Document document = parser.parse(xsdFile);
+
SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
schemaFactory.setErrorHandler(new ErrorHandlerImpl());
- schemaFactory.setResourceResolver(DEFAULT_RESOURCE_RESOLVER);
- schemaFactory.newSchema(xsdFile.toURI().toURL());
+ schemaFactory.setResourceResolver(new XMLResourceResolver());
+
+ Schema schema = schemaFactory.newSchema(resource("schema/XMLSchema.xsd"));
+ Validator validator = schema.newValidator();
+ validator.validate(new DOMSource(document));
+ }
+
+ private URL resource(final String name) {
+ final ClassLoader classLoader = getClass().getClassLoader();
+ final URL resource = classLoader.getResource(name);
+ assertNotNull("Can't locate resource " + name + " on " + classLoader, resource);
+ return resource;
}
}
Oops, something went wrong.

0 comments on commit 0cc6f77

Please sign in to comment.