[jbosscache-commits] JBoss Cache SVN: r6499 - core/trunk/src/main/java/org/jboss/cache/config/parsing.

jbosscache-commits at lists.jboss.org jbosscache-commits at lists.jboss.org
Mon Aug 4 11:56:43 EDT 2008


Author: mircea.markus
Date: 2008-08-04 11:56:43 -0400 (Mon, 04 Aug 2008)
New Revision: 6499

Modified:
   core/trunk/src/main/java/org/jboss/cache/config/parsing/XmlConfigurationParser.java
Log:
now It is possible to override the schema with one specified through a custom porperty

Modified: core/trunk/src/main/java/org/jboss/cache/config/parsing/XmlConfigurationParser.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/config/parsing/XmlConfigurationParser.java	2008-08-04 14:42:47 UTC (rev 6498)
+++ core/trunk/src/main/java/org/jboss/cache/config/parsing/XmlConfigurationParser.java	2008-08-04 15:56:43 UTC (rev 6499)
@@ -50,10 +50,12 @@
  * Reads in XMLconfiguration files and spits out a {@link org.jboss.cache.config.Configuration} object.
  * By default this class uses a validating parser (configurable).
  * <p/>
- * In order to make the parser non-validating by default, the follwing system property is expected:
- * <b>-Djbosscache.config.validate=false</b>
- * <p/>
- * Implementation note: this class is stateful and one instance should be used for parsing a single configuration file.
+ * Following system properties can be used for customizing parser behavior:
+ * <ul>
+ *   <li> <b>-Djbosscache.config.validate=false</b> will make the parser non-validating </li>
+ *   <li> <b>-Djbosscache.config.schemaLocation=url</b> allows one to specify a validation schema that would override the one specified in the the xml document </li>
+ * </ul>
+ * This class is stateful and one instance should be used for parsing a single configuration file.
  *
  * @author Mircea.Markus at jboss.com
  * @since 3.0
@@ -63,6 +65,7 @@
    private static final Log log = LogFactory.getLog(XmlConfigurationParser.class);
 
    public static final String VALIDATING_SYSTEM_PROPERTY = "jbosscache.config.validate";
+   public static final String SCHEMA_LOCATION_SYSTEM_PROPERTY = "jbosscache.config.schemaLocation";
 
    /**
     * the resulting configuration.
@@ -71,6 +74,7 @@
    private Element root;
    private ErrorHandler errorHandler;
    private boolean isValidating;
+   private String schemaLocation;
 
    /**
     * If validation is on (default) one can specify an error handler for handling validation errors.
@@ -80,6 +84,7 @@
    {
       this.errorHandler = errorHandler;
       isValidating = System.getProperty(VALIDATING_SYSTEM_PROPERTY) == null || Boolean.getBoolean(VALIDATING_SYSTEM_PROPERTY);
+      schemaLocation = System.getProperty(SCHEMA_LOCATION_SYSTEM_PROPERTY);
    }
 
    /**
@@ -387,6 +392,15 @@
             docBuilderFactory.setValidating(true);
             docBuilderFactory.setNamespaceAware(true);
             docBuilderFactory.setAttribute("http://java.sun.com/xml/jaxp/properties/schemaLanguage", "http://www.w3.org/2001/XMLSchema");
+            if (schemaLocation != null)
+            {
+               if (log.isTraceEnabled()) log.trace("Using the schema location set to: '" + schemaLocation + '\'');
+               docBuilderFactory.setAttribute("http://java.sun.com/xml/jaxp/properties/schemaSource", schemaLocation);
+            }
+            else if (log.isTraceEnabled())
+            {
+               log.trace("Validation is enabled, using the schema decalred in the .xml configuration file");
+            }
          }
          DocumentBuilder parser = docBuilderFactory.newDocumentBuilder();
          parser.setErrorHandler(errorHandler);




More information about the jbosscache-commits mailing list