commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rgo...@apache.org
Subject svn commit: r771507 - in /commons/proper/configuration/trunk: conf/ src/java/org/apache/commons/configuration/ src/java/org/apache/commons/configuration/resolver/ src/test/org/apache/commons/configuration/
Date Tue, 05 May 2009 00:04:18 GMT
Author: rgoers
Date: Tue May  5 00:04:18 2009
New Revision: 771507

URL: http://svn.apache.org/viewvc?rev=771507&view=rev
Log:
Pass EntityResolver through MultiFileHierarchicalConfiguration. Allow CatalogResolver to load
Catalog even if xml-resolver is in lib/endorsed.

Added:
    commons/proper/configuration/trunk/conf/sample_1001.xml
      - copied, changed from r763836, commons/proper/configuration/trunk/conf/sample.xml
    commons/proper/configuration/trunk/conf/testValidation3.xml
      - copied, changed from r768677, commons/proper/configuration/trunk/conf/testValidation2.xml
    commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/resolver/EntityResolverSupport.java
Modified:
    commons/proper/configuration/trunk/conf/sample.xsd
    commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/DefaultConfigurationBuilder.java
    commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/MultiFileHierarchicalConfiguration.java
    commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/XMLConfiguration.java
    commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/resolver/CatalogResolver.java
    commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestDefaultConfigurationBuilder.java

Modified: commons/proper/configuration/trunk/conf/sample.xsd
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/conf/sample.xsd?rev=771507&r1=771506&r2=771507&view=diff
==============================================================================
--- commons/proper/configuration/trunk/conf/sample.xsd (original)
+++ commons/proper/configuration/trunk/conf/sample.xsd Tue May  5 00:04:18 2009
@@ -1,18 +1,22 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="http://commons.apache.org/employee"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
-  <xs:element name="Employees" type="emp:EmployeesType" xmlns:emp="http://commons.apache.org/employee"/>
-  <xs:complexType name="EmployeeType">
-    <xs:sequence>
-      <xs:element type="xs:string" name="SSN"/>
-      <xs:element type="xs:string" name="Name"/>
-      <xs:element type="xs:string" name="DateOfBirth"/>
-      <xs:element type="xs:string" name="EmployeeType"/>
-      <xs:element type="xs:string" name="Salary"/>
-    </xs:sequence>
-  </xs:complexType>
-  <xs:complexType name="EmployeesType">
-    <xs:sequence>
-      <xs:element type="emp:EmployeeType" name="Employee" xmlns:emp="http://commons.apache.org/employee"/>
-    </xs:sequence>
-  </xs:complexType>
+<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified"
+           targetNamespace="http://commons.apache.org/employee"
+           xmlns:xs="http://www.w3.org/2001/XMLSchema">
+  <xs:element name="Employees" xmlns="http://commons.apache.org/employee">
+    <xs:complexType>
+      <xs:sequence>
+        <xs:element name="Employee">
+          <xs:complexType>
+            <xs:sequence>
+            <xs:element type="xs:string" name="SSN" minOccurs="0"/>
+            <xs:element type="xs:string" name="Name" minOccurs="0"/>
+            <xs:element type="xs:string" name="DateOfBirth" minOccurs="0"/>
+            <xs:element type="xs:string" name="EmployeeType" minOccurs="0"/>
+            <xs:element type="xs:string" name="Salary" minOccurs="0"/>
+            </xs:sequence>
+          </xs:complexType>
+        </xs:element>
+      </xs:sequence>
+    </xs:complexType>
+  </xs:element>
 </xs:schema>
\ No newline at end of file

Copied: commons/proper/configuration/trunk/conf/sample_1001.xml (from r763836, commons/proper/configuration/trunk/conf/sample.xml)
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/conf/sample_1001.xml?p2=commons/proper/configuration/trunk/conf/sample_1001.xml&p1=commons/proper/configuration/trunk/conf/sample.xml&r1=763836&r2=771507&rev=771507&view=diff
==============================================================================
--- commons/proper/configuration/trunk/conf/sample.xml (original)
+++ commons/proper/configuration/trunk/conf/sample_1001.xml Tue May  5 00:04:18 2009
@@ -3,10 +3,6 @@
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xsi:schemaLocation="http://commons.apache.org/employee http://commons.apache.org/sample.xsd">
   <Employee>
-    <SSN>555121211</SSN>
-    <Name>John Doe</Name>
-    <DateOfBirth>1975-05-15</DateOfBirth>
-    <EmployeeType>Exempt</EmployeeType>
-    <Salary>100000</Salary>
+    <Name>Jane Doe</Name>
   </Employee>
 </Employees>
\ No newline at end of file

Copied: commons/proper/configuration/trunk/conf/testValidation3.xml (from r768677, commons/proper/configuration/trunk/conf/testValidation2.xml)
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/conf/testValidation3.xml?p2=commons/proper/configuration/trunk/conf/testValidation3.xml&p1=commons/proper/configuration/trunk/conf/testValidation2.xml&r1=768677&r2=771507&rev=771507&view=diff
==============================================================================
--- commons/proper/configuration/trunk/conf/testValidation2.xml (original)
+++ commons/proper/configuration/trunk/conf/testValidation3.xml Tue May  5 00:04:18 2009
@@ -2,15 +2,24 @@
 <!-- Test configuration definition file that demonstrates complex initialization -->
 <configuration>
   <header>
-    <result delimiterParsingDisabled="true">
-      <nodeCombiner config-class="org.apache.commons.configuration.tree.OverrideCombiner"/>
+    <result delimiterParsingDisabled="true" forceReloadCheck="true" loggerName="TestLogger"
+            config-class="org.apache.commons.configuration.DynamicCombinedConfiguration"
+            keyPattern="$${sys:Id}">
+      <nodeCombiner config-class="org.apache.commons.configuration.tree.MergeCombiner"/>
       <expressionEngine config-class="org.apache.commons.configuration.tree.xpath.XPathExpressionEngine"/>
     </result>
-    <entity-resolver catalogFiles="file://${sys:user.dir}/conf/catalog2.xml"/>    
+    <providers>
+      <provider config-tag="multifile"
+         config-class="org.apache.commons.configuration.DefaultConfigurationBuilder$FileConfigurationProvider"
+         configurationClass="org.apache.commons.configuration.MultiFileHierarchicalConfiguration"/>
+    </providers><entity-resolver catalogFiles="catalog.xml"/>
   </header>
   <system/>
   <properties fileName="test.properties.xml" throwExceptionOnMissing="true"
     config-name="properties">
   </properties>
-  <xml fileName="file://${sys:user.dir}/conf/sample.xml" config-name="xml" schemaValidation="true"/>
+  <multifile filePattern="sample_$$${sys:Id}.xml"
+             config-name="clientConfig" delimiterParsingDisabled="true" schemaValidation="true">
+  </multifile>
+  <xml fileName="sample.xml" config-name="xml" schemaValidation="true"/>
 </configuration>
\ No newline at end of file

Modified: commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/DefaultConfigurationBuilder.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/DefaultConfigurationBuilder.java?rev=771507&r1=771506&r2=771507&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/DefaultConfigurationBuilder.java
(original)
+++ commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/DefaultConfigurationBuilder.java
Tue May  5 00:04:18 2009
@@ -37,6 +37,7 @@
 import org.apache.commons.configuration.tree.UnionCombiner;
 import org.apache.commons.configuration.resolver.EntityRegistry;
 import org.apache.commons.configuration.resolver.CatalogResolver;
+import org.apache.commons.configuration.resolver.EntityResolverSupport;
 import org.apache.commons.lang.text.StrLookup;
 import org.apache.commons.logging.LogFactory;
 import org.xml.sax.EntityResolver;
@@ -1386,7 +1387,20 @@
         public AbstractConfiguration getEmptyConfiguration(
                 ConfigurationDeclaration decl) throws Exception
         {
-            return super.getConfiguration(decl);
+            AbstractConfiguration config = super.getConfiguration(decl);
+
+            /**
+             * Some wrapper classes may need to pass the EntityResolver to XMLConfigurations
+             * they construct buy may not be an XMLConfiguration.
+             */
+            if (config instanceof EntityResolverSupport)
+            {
+                DefaultConfigurationBuilder builder = decl.getConfigurationBuilder();
+                EntityResolver resolver = builder.getEntityResolver();
+                ((EntityResolverSupport)config).setEntityResolver(resolver);
+            }
+
+            return config;
         }
 
         /**

Modified: commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/MultiFileHierarchicalConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/MultiFileHierarchicalConfiguration.java?rev=771507&r1=771506&r2=771507&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/MultiFileHierarchicalConfiguration.java
(original)
+++ commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/MultiFileHierarchicalConfiguration.java
Tue May  5 00:04:18 2009
@@ -38,9 +38,11 @@
 import org.apache.commons.configuration.tree.ConfigurationNode;
 import org.apache.commons.configuration.tree.ExpressionEngine;
 import org.apache.commons.configuration.reloading.ReloadingStrategy;
+import org.apache.commons.configuration.resolver.EntityResolverSupport;
 import org.apache.commons.beanutils.BeanUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.xml.sax.EntityResolver;
 
 /**
  * This class provides access to multiple configuration files that reside in a location that
@@ -55,7 +57,7 @@
  * @version $Id$
  */
 public class MultiFileHierarchicalConfiguration extends AbstractHierarchicalFileConfiguration
-    implements ConfigurationListener, ConfigurationErrorListener
+    implements ConfigurationListener, ConfigurationErrorListener, EntityResolverSupport
 {
     /**
      * Prevent recursion while resolving unprefixed properties.
@@ -95,6 +97,9 @@
     /** The Reloading strategy to use on created configurations */
     private ReloadingStrategy fileStrategy;
 
+    /** The EntityResolver */
+    private EntityResolver entityResolver;
+
     /**
      * Default Constructor.
      */
@@ -169,6 +174,16 @@
         this.fileStrategy = strategy;
     }
 
+    public void setEntityResolver(EntityResolver entityResolver)
+    {
+        this.entityResolver = entityResolver;
+    }
+
+    public EntityResolver getEntityResolver()
+    {
+        return this.entityResolver;
+    }
+
     /**
      * Set to true if an empty Configuration should be returned when loading fails. If
      * false an exception will be thrown.
@@ -703,6 +718,7 @@
         configuration.setDelimiterParsingDisabled(isDelimiterParsingDisabled());
         configuration.setValidating(validating);
         configuration.setSchemaValidation(schemaValidation);
+        configuration.setEntityResolver(entityResolver);
         configuration.setAttributeSplittingDisabled(attributeSplittingDisabled);
         configuration.setListDelimiter(getListDelimiter());
         configuration.addConfigurationListener(this);

Modified: commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/XMLConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/XMLConfiguration.java?rev=771507&r1=771506&r2=771507&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/XMLConfiguration.java
(original)
+++ commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/XMLConfiguration.java
Tue May  5 00:04:18 2009
@@ -936,6 +936,11 @@
             initProperties(newDocument, oldDocument == null);
             document = (oldDocument == null) ? newDocument : oldDocument;
         }
+        catch (SAXParseException spe)
+        {
+            this.getLogger().debug("Error parsing " + source.getSystemId(), spe);
+            throw new ConfigurationException("Error parsing " + source.getSystemId(), spe);
+        }
         catch (Exception e)
         {
             throw new ConfigurationException("Unable to load the configuration", e);

Modified: commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/resolver/CatalogResolver.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/resolver/CatalogResolver.java?rev=771507&r1=771506&r2=771507&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/resolver/CatalogResolver.java
(original)
+++ commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/resolver/CatalogResolver.java
Tue May  5 00:04:18 2009
@@ -20,6 +20,7 @@
 import org.xml.sax.InputSource;
 import org.xml.sax.SAXException;
 import org.apache.xml.resolver.CatalogException;
+import org.apache.xml.resolver.Catalog;
 import org.apache.xml.resolver.readers.CatalogReader;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.impl.NoOpLog;
@@ -88,7 +89,6 @@
     {
         manager.setIgnoreMissingProperties(true);
         manager.setUseStaticCatalog(false);
-        manager.setCatalogClassName(Catalog.class.getName());
         manager.setFileSystem(fs);
         setLogger(null);
     }
@@ -255,6 +255,9 @@
         /** The String Substitutor */
         private StrSubstitutor substitutor;
 
+        /** The static catalog used by this manager. */
+        private static org.apache.xml.resolver.Catalog staticCatalog = null;
+
         /**
          * Set the FileSystem
          * @param fileSystem The FileSystem in use.
@@ -303,6 +306,52 @@
         {
             return this.substitutor;
         }
+
+
+        /**
+         * Get a new catalog instance. This method is only overridden because xml-resolver
+         * might be in a parent ClassLoader and will be incapable of loading our Catalog
+         * implementation.
+         *
+         * This method always returns a new instance of the underlying catalog class.
+         */
+        public org.apache.xml.resolver.Catalog getPrivateCatalog()
+        {
+            org.apache.xml.resolver.Catalog catalog = staticCatalog;
+
+            if (catalog == null || !getUseStaticCatalog())
+            {
+                try
+                {
+	                catalog = new Catalog();
+	                catalog.setCatalogManager(this);
+	                catalog.setupReaders();
+	                catalog.loadSystemCatalogs();
+                }
+                catch (Exception ex)
+                {
+	                ex.printStackTrace();
+                }
+
+                if (getUseStaticCatalog())
+                {
+	                staticCatalog = catalog;
+                }
+            }
+
+            return catalog;
+        }
+
+        /**
+         * Get a catalog instance.
+         *
+         * If this manager uses static catalogs, the same static catalog will
+         * always be returned. Otherwise a new catalog will be returned.
+         */
+        public org.apache.xml.resolver.Catalog getCatalog()
+        {
+            return getPrivateCatalog();
+        }
     }
 
     /**

Added: commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/resolver/EntityResolverSupport.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/resolver/EntityResolverSupport.java?rev=771507&view=auto
==============================================================================
--- commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/resolver/EntityResolverSupport.java
(added)
+++ commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/resolver/EntityResolverSupport.java
Tue May  5 00:04:18 2009
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.configuration.resolver;
+
+import org.xml.sax.EntityResolver;
+
+/**
+ * Interface that identifies the class as using an EntityResolver
+ */
+public interface EntityResolverSupport
+{
+    /**
+     * Return the EntityResolver associated with the class.
+     * @return The EntityResolver.
+     */
+    EntityResolver getEntityResolver();
+
+    /**
+     * Set the EntityResolver to assoicate with this class.
+     * @param resolver The EntityResolver
+     */
+    void setEntityResolver(EntityResolver resolver);
+}

Modified: commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestDefaultConfigurationBuilder.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestDefaultConfigurationBuilder.java?rev=771507&r1=771506&r2=771507&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestDefaultConfigurationBuilder.java
(original)
+++ commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestDefaultConfigurationBuilder.java
Tue May  5 00:04:18 2009
@@ -87,6 +87,9 @@
     private static final File VALIDATION_FILE = new File(
             "conf/testValidation.xml");
 
+    private static final File VALIDATION3_FILE = new File(
+            "conf/testValidation3.xml");
+
     private static final File MULTI_TENENT_FILE = new File(
             "conf/testMultiTenentConfigurationBuilder.xml");
 
@@ -851,6 +854,21 @@
         assertEquals("Incorrect value retrieved","value1",value);
     }
 
+
+    public void testValidation3() throws Exception
+    {
+        System.getProperties().remove("Id");
+        factory.setFile(VALIDATION3_FILE);
+        CombinedConfiguration config = factory.getConfiguration(true);
+        String value = config.getString("Employee/Name");
+        assertNotNull("The test key was not located", value);
+        assertEquals("Incorrect value retrieved","John Doe",value);
+        System.setProperty("Id", "1001");
+        value = config.getString("Employee/Name");
+        assertNotNull("The test key was not located", value);
+        assertEquals("Incorrect value retrieved","Jane Doe",value);
+    }
+
     public void testMultiTenentConfiguration() throws Exception
     {
         factory.setFile(MULTI_TENENT_FILE);



Mime
View raw message