[infinispan-commits] Infinispan SVN: r653 - in trunk/core/src/main/java/org/infinispan/config: parsing and 1 other directory.

infinispan-commits at lists.jboss.org infinispan-commits at lists.jboss.org
Wed Aug 12 03:23:29 EDT 2009


Author: vblagojevic at jboss.com
Date: 2009-08-12 03:23:28 -0400 (Wed, 12 Aug 2009)
New Revision: 653

Removed:
   trunk/core/src/main/java/org/infinispan/config/parsing/ParsedAttributes.java
   trunk/core/src/main/java/org/infinispan/config/parsing/RootElementBuilder.java
Modified:
   trunk/core/src/main/java/org/infinispan/config/InfinispanConfiguration.java
   trunk/core/src/main/java/org/infinispan/config/parsing/XmlConfigHelper.java
Log:
remove old parsers

Modified: trunk/core/src/main/java/org/infinispan/config/InfinispanConfiguration.java
===================================================================
--- trunk/core/src/main/java/org/infinispan/config/InfinispanConfiguration.java	2009-08-12 06:51:26 UTC (rev 652)
+++ trunk/core/src/main/java/org/infinispan/config/InfinispanConfiguration.java	2009-08-12 07:23:28 UTC (rev 653)
@@ -56,6 +56,8 @@
 @XmlAccessorType(XmlAccessType.FIELD)
 public class InfinispanConfiguration implements XmlConfigurationParser {
    
+   public static final String VALIDATING_SYSTEM_PROPERTY = "infinispan.config.validate";
+   
    @XmlElement
    private GlobalConfiguration global;
    
@@ -139,9 +141,12 @@
       try {
          JAXBContext jc = JAXBContext.newInstance(InfinispanConfiguration.class);
          Unmarshaller u = jc.createUnmarshaller();
-         if (schema != null) {
+         String s = System.getProperty(VALIDATING_SYSTEM_PROPERTY);
+         boolean isValidatingOff = s!=null && !Boolean.parseBoolean(s);
+         
+         if (schema != null && !isValidatingOff) {
             SchemaFactory factory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
-            u.setSchema(factory.newSchema(new StreamSource(schema)));
+            u.setSchema(factory.newSchema(new StreamSource(schema)));      
          }
          InfinispanConfiguration doc = (InfinispanConfiguration) u.unmarshal(config);
          //legacy, don't ask

Deleted: trunk/core/src/main/java/org/infinispan/config/parsing/ParsedAttributes.java
===================================================================
--- trunk/core/src/main/java/org/infinispan/config/parsing/ParsedAttributes.java	2009-08-12 06:51:26 UTC (rev 652)
+++ trunk/core/src/main/java/org/infinispan/config/parsing/ParsedAttributes.java	2009-08-12 07:23:28 UTC (rev 653)
@@ -1,42 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.infinispan.config.parsing;
-
-import org.w3c.dom.Element;
-
-import java.util.Map;
-
-/**
- * Helper class for holding attributes defined in configuration file.
- *
- * @author Mircea.Markus at jboss.com
- * @since 4.0
- */
-public class ParsedAttributes {
-   public final Map<String, String> stringAttribs;
-   public final Map<String, Element> xmlAttribs;
-
-   ParsedAttributes(Map strings, Map elements) {
-      this.stringAttribs = strings;
-      this.xmlAttribs = elements;
-   }
-}

Deleted: trunk/core/src/main/java/org/infinispan/config/parsing/RootElementBuilder.java
===================================================================
--- trunk/core/src/main/java/org/infinispan/config/parsing/RootElementBuilder.java	2009-08-12 06:51:26 UTC (rev 652)
+++ trunk/core/src/main/java/org/infinispan/config/parsing/RootElementBuilder.java	2009-08-12 07:23:28 UTC (rev 653)
@@ -1,128 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.infinispan.config.parsing;
-
-import org.infinispan.config.ConfigurationException;
-import org.infinispan.util.logging.Log;
-import org.infinispan.util.logging.LogFactory;
-import org.jboss.util.xml.JBossEntityResolver;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.xml.sax.ErrorHandler;
-import org.xml.sax.SAXException;
-import org.xml.sax.SAXParseException;
-
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import java.io.InputStream;
-
-/**
- * Parses an xml files and validates xml elements form {@link RootElementBuilder#HORIZON_NS} namespace according to the
- * configured schema.
- *
- * @author Mircea.Markus at jboss.com
- * @since 4.0
- */
-public class RootElementBuilder {
-
-   private static final JBossEntityResolver resolver = new JBossEntityResolver();
-
-   public static final String HORIZON_NS = "urn:infinispan:config:4.0";
-
-   static {
-      // Globally register this namespace
-      JBossEntityResolver.registerEntity(HORIZON_NS, "infinispan-config-4.0.xsd");
-   }
-
-   private static final Log log = LogFactory.getLog(RootElementBuilder.class);
-   private ErrorHandler errorHandler;
-   private boolean isValidating;
-   public static final String VALIDATING_SYSTEM_PROPERTY = "infinispan.config.validate";
-
-   public RootElementBuilder(ErrorHandler errorHandler) {
-      this.errorHandler = errorHandler;
-      isValidating = System.getProperty(VALIDATING_SYSTEM_PROPERTY) == null || Boolean.getBoolean(VALIDATING_SYSTEM_PROPERTY);
-   }
-
-   public RootElementBuilder(ErrorHandler errorHandler, boolean validating) {
-      this.errorHandler = errorHandler;
-      isValidating = validating;
-   }
-
-   public RootElementBuilder() {
-      this(new FailureErrorHandler());
-   }
-
-   public RootElementBuilder(boolean validating) {
-      this(new FailureErrorHandler(), validating);
-   }
-
-   public Element readRoot(InputStream config) {
-      try {
-         DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
-         docBuilderFactory.setNamespaceAware(true);
-         if (isValidating) {
-            docBuilderFactory.setValidating(true);
-            docBuilderFactory.setAttribute("http://java.sun.com/xml/jaxp/properties/schemaLanguage", "http://www.w3.org/2001/XMLSchema");
-            String[] value = {HORIZON_NS};
-            docBuilderFactory.setAttribute("http://java.sun.com/xml/jaxp/properties/schemaSource", value);
-         }
-         DocumentBuilder parser = docBuilderFactory.newDocumentBuilder();
-         parser.setEntityResolver(resolver);
-         parser.setErrorHandler(errorHandler);
-         Document doc = parser.parse(config);
-         Element root = doc.getDocumentElement();
-         root.normalize();
-         return root;
-      }
-      catch (Exception e) {
-         log.error(e);
-         throw new ConfigurationException("Could not parse the config file", e);
-      }
-   }
-
-   /**
-    * Default schema validation error handler, that throws an exception on validation errors.
-    */
-   private static class FailureErrorHandler implements ErrorHandler {
-      public void warning(SAXParseException exception) throws SAXException {
-         logAndThrowException(exception);
-      }
-
-      public void error(SAXParseException exception) throws SAXException {
-         logAndThrowException(exception);
-      }
-
-      public void fatalError(SAXParseException exception) throws SAXException {
-         logAndThrowException(exception);
-      }
-
-      private void logAndThrowException(SAXParseException exception) {
-         log.error("Configuration warning: " + exception.getMessage());
-         throw new ConfigurationException("Incorrect configuration file. Use '-D" + VALIDATING_SYSTEM_PROPERTY + "=false' to disable validation.", exception);
-      }
-   }
-
-   public boolean isValidating() {
-      return isValidating;
-   }
-}

Modified: trunk/core/src/main/java/org/infinispan/config/parsing/XmlConfigHelper.java
===================================================================
--- trunk/core/src/main/java/org/infinispan/config/parsing/XmlConfigHelper.java	2009-08-12 06:51:26 UTC (rev 652)
+++ trunk/core/src/main/java/org/infinispan/config/parsing/XmlConfigHelper.java	2009-08-12 07:23:28 UTC (rev 653)
@@ -331,24 +331,6 @@
     * @return a DOM Element
     * @throws Exception if unable to parse the String or if it doesn't contain valid XML.
     */
-   public static Element stringToElementInCoreNS(String xml) throws Exception {
-      xml = "<wrapper xmlns='" + RootElementBuilder.HORIZON_NS + "'>" + xml + "</wrapper>";
-      ByteArrayInputStream bais = new ByteArrayInputStream(xml.getBytes("utf8"));
-      DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
-      factory.setNamespaceAware(true);
-      DocumentBuilder builder = factory.newDocumentBuilder();
-      Document d = builder.parse(bais);
-      bais.close();
-      return getFirstChildElement(d.getDocumentElement());
-   }
-
-   /**
-    * Converts a String representing an XML snippet into an {@link org.w3c.dom.Element}.
-    *
-    * @param xml snippet as a string
-    * @return a DOM Element
-    * @throws Exception if unable to parse the String or if it doesn't contain valid XML.
-    */
    public static Element stringToElement(String xml) throws Exception {
       ByteArrayInputStream bais = new ByteArrayInputStream(xml.getBytes("utf8"));
       DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();



More information about the infinispan-commits mailing list