cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r662216 - in /cayenne/main/trunk/framework: cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/conf/ cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/ cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/co...
Date Sun, 01 Jun 2008 14:11:03 GMT
Author: aadamchik
Date: Sun Jun  1 07:11:02 2008
New Revision: 662216

URL: http://svn.apache.org/viewvc?rev=662216&view=rev
Log:
CAY-943 Support multiple cayenne.xml files in the project
(refactoring)

Modified:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/conf/Configuration.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/conf/DefaultConfiguration.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/conf/MultiProjectConfiguration.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextStaticsTest.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/conf/MockConfiguration.java
    cayenne/main/trunk/framework/cayenne-jpa-unpublished/src/main/java/org/apache/cayenne/jpa/Provider.java
    cayenne/main/trunk/framework/cayenne-modeler/src/test/java/org/apache/cayenne/modeler/action/MockConfiguration.java

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/conf/Configuration.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/conf/Configuration.java?rev=662216&r1=662215&r2=662216&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/conf/Configuration.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/conf/Configuration.java
Sun Jun  1 07:11:02 2008
@@ -19,7 +19,9 @@
 
 package org.apache.cayenne.conf;
 
+import java.io.IOException;
 import java.io.InputStream;
+import java.net.URL;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
@@ -223,8 +225,30 @@
 
     /**
      * Returns the resource locator used for finding and loading resources.
+     * 
+     * @deprecated since 3.0 use/override {@link #getResourceFinder()}.
+     */
+    protected ResourceLocator getResourceLocator() {
+        ResourceFinder finder = getResourceFinder();
+        if (finder == null) {
+            return null;
+        }
+
+        if (finder instanceof ResourceLocator) {
+            return (ResourceLocator) finder;
+        }
+
+        throw new IllegalStateException("ResourceFinder is not a ResourceLocator: "
+                + finder);
+    }
+
+    /**
+     * Returns {@link ResourceFinder} associated with this Configuration that is to be
+     * used for config files lookup.
+     * 
+     * @since 3.0
      */
-    protected abstract ResourceLocator getResourceLocator();
+    protected abstract ResourceFinder getResourceFinder();
 
     /**
      * Returns a DataDomain as a stream or <code>null</code> if it cannot be
found.
@@ -233,26 +257,50 @@
      *             the superclass.
      */
     protected InputStream getDomainConfiguration() {
-        throw new UnsupportedOperationException();
+        URL url = getResourceFinder().getResource(getDomainConfigurationName());
+        try {
+            return url != null ? url.openStream() : null;
+        }
+        catch (IOException e) {
+            throw new ConfigurationException("Can't open config file URL: " + url, e);
+        }
     }
 
     /**
      * Returns a DataMap with the given name or <code>null</code> if it cannot
be found.
      */
-    protected abstract InputStream getMapConfiguration(String name);
+    protected InputStream getMapConfiguration(String name) {
+        URL url = getResourceFinder().getResource(name);
+        try {
+            return url != null ? url.openStream() : null;
+        }
+        catch (IOException e) {
+            throw new ConfigurationException("Can't open config file URL: " + url, e);
+        }
+    }
 
     /**
      * See 'https://svn.apache.org/repos/asf/cayenne/dataviews/trunk' for DataViews code,
      * which is not a part of Cayenne since 3.0.
+     * 
+     * @deprecated since 3.0 as Cayenne no longer cares to read view config files.
      */
-    protected abstract InputStream getViewConfiguration(String location);
+    protected InputStream getViewConfiguration(String location) {
+        URL url = getResourceFinder().getResource(location);
+        try {
+            return url != null ? url.openStream() : null;
+        }
+        catch (IOException e) {
+            throw new ConfigurationException("Can't open config file URL: " + url, e);
+        }
+    }
 
     /**
      * Returns the name of the main domain configuration resource. Defaults to
      * {@link Configuration#DEFAULT_DOMAIN_FILE}.
      */
     public String getDomainConfigurationName() {
-        return this.domainConfigurationName;
+        return domainConfigurationName;
     }
 
     /**

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/conf/DefaultConfiguration.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/conf/DefaultConfiguration.java?rev=662216&r1=662215&r2=662216&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/conf/DefaultConfiguration.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/conf/DefaultConfiguration.java
Sun Jun  1 07:11:02 2008
@@ -45,8 +45,6 @@
      * Default constructor. Simply calls
      * {@link DefaultConfiguration#DefaultConfiguration(String)} with
      * {@link Configuration#DEFAULT_DOMAIN_FILE} as argument.
-     * 
-     * @see Configuration#Configuration()
      */
     public DefaultConfiguration() {
         this(Configuration.DEFAULT_DOMAIN_FILE);
@@ -123,6 +121,12 @@
         this.getResourceLocator().addFilesystemPath(path);
     }
 
+    @Override
+    protected InputStream getDomainConfiguration() {
+        // deprecation in superclass does not affect subclass...
+        return super.getDomainConfiguration();
+    }
+
     /**
      * Initializes all Cayenne resources. Loads all configured domains and their data
      * maps, initializes all domain Nodes and their DataSources.
@@ -131,7 +135,7 @@
     public void initialize() throws Exception {
         logger.debug("initialize starting.");
 
-        InputStream in = this.getDomainConfiguration();
+        InputStream in = getDomainConfiguration();
         if (in == null) {
             StringBuilder msg = new StringBuilder();
             msg.append("[").append(this.getClass().getName()).append(
@@ -162,47 +166,30 @@
 
     /**
      * Returns the default ResourceLocator configured for CLASSPATH lookups.
+     * 
+     * @deprecated since 3.0 as super is deprecated.
      */
     @Override
     protected ResourceLocator getResourceLocator() {
-        return this.locator;
-    }
-
-    /**
-     * Sets the specified {@link ResourceLocator}. Currently called from
-     * {@link #initialize}.
-     */
-    protected void setResourceLocator(ResourceLocator locator) {
-        this.locator = locator;
+        return locator;
     }
 
     /**
-     * Returns the domain configuration as a stream or <code>null</code> if it
cannot be
-     * found. Uses the configured {@link ResourceLocator} to find the file.
+     * @since 3.0
      */
     @Override
-    protected InputStream getDomainConfiguration() {
-        return locator.findResourceStream(this.getDomainConfigurationName());
+    protected ResourceFinder getResourceFinder() {
+        return locator;
     }
 
     /**
-     * Returns the {@link org.apache.cayenne.map.DataMap} configuration from a specified
-     * location or <code>null</code> if it cannot be found. Uses the configured
-     * {@link ResourceLocator} to find the file.
+     * Sets the specified {@link ResourceLocator}. Currently called from
+     * {@link #initialize}.
      */
-    @Override
-    protected InputStream getMapConfiguration(String location) {
-        return locator.findResourceStream(location);
-    }
-
-    @Override
-    protected InputStream getViewConfiguration(String location) {
-        return locator.findResourceStream(location);
+    protected void setResourceLocator(ResourceLocator locator) {
+        this.locator = locator;
     }
 
-    /**
-     * @see Object#toString()
-     */
     @Override
     public String toString() {
         StringBuilder buf = new StringBuilder();
@@ -214,5 +201,4 @@
                 .append(']');
         return buf.toString();
     }
-
 }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/conf/MultiProjectConfiguration.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/conf/MultiProjectConfiguration.java?rev=662216&r1=662215&r2=662216&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/conf/MultiProjectConfiguration.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/conf/MultiProjectConfiguration.java
Sun Jun  1 07:11:02 2008
@@ -19,11 +19,8 @@
 package org.apache.cayenne.conf;
 
 import java.io.InputStream;
-import java.net.URL;
-import java.util.Collection;
 
 import org.apache.cayenne.ConfigurationException;
-import org.apache.cayenne.util.ResourceLocator;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
@@ -77,23 +74,13 @@
         logger.debug("initialize finished.");
     }
 
-    /**
-     * Returns a collection of all available unit descriptor URLs. Unit descriptors
-     * (usually cayenne.xml files) are looked up using the internal resource locator.
-     * 
-     * @since 3.0
-     */
-    protected Collection<URL> getUnitDescriptors() {
-        return resourceFinder.getResources(getDomainConfigurationName());
-    }
-
     @Override
-    protected InputStream getMapConfiguration(String name) {
-        return null;
+    protected ResourceFinder getResourceFinder() {
+        return resourceFinder;
     }
 
     @Override
-    protected ResourceLocator getResourceLocator() {
+    protected InputStream getMapConfiguration(String name) {
         return null;
     }
 

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextStaticsTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextStaticsTest.java?rev=662216&r1=662215&r2=662216&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextStaticsTest.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextStaticsTest.java
Sun Jun  1 07:11:02 2008
@@ -19,11 +19,9 @@
 
 package org.apache.cayenne.access;
 
-import java.io.InputStream;
-
 import org.apache.cayenne.conf.Configuration;
+import org.apache.cayenne.conf.ResourceFinder;
 import org.apache.cayenne.unit.CayenneCase;
-import org.apache.cayenne.util.ResourceLocator;
 
 /**
  * @author Andrus Adamchik
@@ -78,17 +76,7 @@
         }
 
         @Override
-        public ResourceLocator getResourceLocator() {
-            return null;
-        }
-
-        @Override
-        protected InputStream getMapConfiguration(String location) {
-            return null;
-        }
-
-        @Override
-        protected InputStream getViewConfiguration(String location) {
+        protected ResourceFinder getResourceFinder() {
             return null;
         }
     }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/conf/MockConfiguration.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/conf/MockConfiguration.java?rev=662216&r1=662215&r2=662216&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/conf/MockConfiguration.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/conf/MockConfiguration.java
Sun Jun  1 07:11:02 2008
@@ -19,27 +19,13 @@
 
 package org.apache.cayenne.conf;
 
-import java.io.InputStream;
-
-import org.apache.cayenne.util.ResourceLocator;
-
 /**
  * @author Andrus Adamchik
  */
 public class MockConfiguration extends Configuration {
 
     @Override
-    protected InputStream getMapConfiguration(String name) {
-        return null;
-    }
-
-    @Override
-    protected ResourceLocator getResourceLocator() {
-        return null;
-    }
-
-    @Override
-    protected InputStream getViewConfiguration(String location) {
+    protected ResourceFinder getResourceFinder() {
         return null;
     }
 

Modified: cayenne/main/trunk/framework/cayenne-jpa-unpublished/src/main/java/org/apache/cayenne/jpa/Provider.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jpa-unpublished/src/main/java/org/apache/cayenne/jpa/Provider.java?rev=662216&r1=662215&r2=662216&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jpa-unpublished/src/main/java/org/apache/cayenne/jpa/Provider.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jpa-unpublished/src/main/java/org/apache/cayenne/jpa/Provider.java
Sun Jun  1 07:11:02 2008
@@ -19,7 +19,6 @@
 
 package org.apache.cayenne.jpa;
 
-import java.io.InputStream;
 import java.io.PrintWriter;
 import java.lang.instrument.ClassFileTransformer;
 import java.sql.Connection;
@@ -40,6 +39,7 @@
 import org.apache.cayenne.access.DbGenerator;
 import org.apache.cayenne.conf.Configuration;
 import org.apache.cayenne.conf.ConnectionProperties;
+import org.apache.cayenne.conf.ResourceFinder;
 import org.apache.cayenne.dba.AutoAdapter;
 import org.apache.cayenne.dba.DbAdapter;
 import org.apache.cayenne.enhancer.Enhancer;
@@ -57,7 +57,6 @@
 import org.apache.cayenne.reflect.ClassDescriptorMap;
 import org.apache.cayenne.reflect.FaultFactory;
 import org.apache.cayenne.reflect.SingletonFaultFactory;
-import org.apache.cayenne.util.ResourceLocator;
 import org.apache.cayenne.util.Util;
 import org.apache.cayenne.validation.SimpleValidationFailure;
 import org.apache.cayenne.validation.ValidationResult;
@@ -562,17 +561,7 @@
         }
 
         @Override
-        protected ResourceLocator getResourceLocator() {
-            throw new UnsupportedOperationException();
-        }
-
-        @Override
-        protected InputStream getMapConfiguration(String name) {
-            throw new UnsupportedOperationException();
-        }
-
-        @Override
-        protected InputStream getViewConfiguration(String location) {
+        protected ResourceFinder getResourceFinder() {
             throw new UnsupportedOperationException();
         }
     }

Modified: cayenne/main/trunk/framework/cayenne-modeler/src/test/java/org/apache/cayenne/modeler/action/MockConfiguration.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/test/java/org/apache/cayenne/modeler/action/MockConfiguration.java?rev=662216&r1=662215&r2=662216&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/test/java/org/apache/cayenne/modeler/action/MockConfiguration.java
(original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/test/java/org/apache/cayenne/modeler/action/MockConfiguration.java
Sun Jun  1 07:11:02 2008
@@ -18,22 +18,13 @@
  ****************************************************************/
 package org.apache.cayenne.modeler.action;
 
-import java.io.InputStream;
-
 import org.apache.cayenne.conf.Configuration;
-import org.apache.cayenne.util.ResourceLocator;
+import org.apache.cayenne.conf.ResourceFinder;
 
 public class MockConfiguration extends Configuration {
 
-    protected InputStream getMapConfiguration(String name) {
-        return null;
-    }
-
-    protected ResourceLocator getResourceLocator() {
-        return null;
-    }
-
-    protected InputStream getViewConfiguration(String location) {
+    @Override
+    protected ResourceFinder getResourceFinder() {
         return null;
     }
 



Mime
View raw message