Author: julien(a)jboss.com
Date: 2007-10-08 16:52:02 -0400 (Mon, 08 Oct 2007)
New Revision: 8569
Modified:
modules/test/trunk/unit/src/main/org/jboss/unit/runner/model/ModelBuilder.java
Log:
avoid to parse and build the jboss unit schema everytime a parse action is done
Modified: modules/test/trunk/unit/src/main/org/jboss/unit/runner/model/ModelBuilder.java
===================================================================
---
modules/test/trunk/unit/src/main/org/jboss/unit/runner/model/ModelBuilder.java 2007-10-08
20:49:44 UTC (rev 8568)
+++
modules/test/trunk/unit/src/main/org/jboss/unit/runner/model/ModelBuilder.java 2007-10-08
20:52:02 UTC (rev 8569)
@@ -35,7 +35,6 @@
import org.jboss.unit.runner.model.composite.CompositeTestSuiteDef;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
-import org.xml.sax.EntityResolver;
import org.xml.sax.SAXParseException;
import javax.xml.parsers.DocumentBuilderFactory;
@@ -63,21 +62,22 @@
private final Element rootElt;
/** . */
- private static final EntityResolver resolver = new EntityResolver()
+ private static final Schema schema;
+
+ static
{
- public InputSource resolveEntity(String publicId, String systemId) throws
SAXException, IOException
+ try
{
- if (Constants.JBOSS_UNIT_SYSTEM_ID.equals(systemId))
- {
- InputStream in =
ModelBuilder.class.getResourceAsStream(Constants.RELATIVE_RESOURCE_NAME);
- if (in != null)
- {
- return new InputSource(in);
- }
- }
- return null;
+ SchemaFactory schemaFactory =
SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
+ InputStream in =
ModelBuilder.class.getResourceAsStream(Constants.RELATIVE_RESOURCE_NAME);
+ StreamSource ss = new StreamSource(in);
+ schema = schemaFactory.newSchema(ss);
}
- };
+ catch (SAXException e)
+ {
+ throw new Error("Could not load jboss unit schema for validation",
e);
+ }
+ }
public ModelBuilder(InputSource source) throws ParserConfigurationException,
IOException, SAXException
{
@@ -90,21 +90,9 @@
try
{
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
-
factory.setNamespaceAware(true);
-
- SchemaFactory schemaFactory =
SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
- InputStream in =
ModelBuilder.class.getResourceAsStream(Constants.RELATIVE_RESOURCE_NAME);
- StreamSource ss = new StreamSource(in);
- Schema schema = schemaFactory.newSchema(ss);
-
-
-
factory.setSchema(schema);
-
-
DocumentBuilder builder = factory.newDocumentBuilder();
-// builder.setEntityResolver(resolver);
Document doc = builder.parse(source);
//