cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r932955 - in /cayenne/main/trunk: docs/doc/src/main/resources/ framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/conf/ framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/ framework/cayenn...
Date Sun, 11 Apr 2010 17:48:31 GMT
Author: aadamchik
Date: Sun Apr 11 17:48:31 2010
New Revision: 932955

URL: http://svn.apache.org/viewvc?rev=932955&view=rev
Log:
CAY-1419 File-based ResourceLocator to replace legacy FileConfiguration

Added:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/resource/FilesystemResourceLocator.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/resource/FilesystemResourceLocatorTest.java
Removed:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/conf/FileConfiguration.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/conf/package.html
Modified:
    cayenne/main/trunk/docs/doc/src/main/resources/RELEASE-NOTES.txt
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/CayenneRuntime.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/RuntimeProperties.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/server/CayenneServerModule.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/server/CayenneServerRuntime.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/server/DataDomainProvider.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/web/CayenneFilter.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/conf/ConfigurationTest.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/configuration/server/CayenneServerRuntimeTest.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/configuration/server/DataDomainProviderTest.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/configuration/web/CayenneFilterTest.java
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/CreateNodeAction.java
    cayenne/main/trunk/framework/cayenne-tools/src/main/java/org/apache/cayenne/tools/DataPortTask.java
    cayenne/main/trunk/itests/cayenne-di-stack/src/main/java/org/apache/cayenne/configuration/server/CayenneServerRuntimeCase.java

Modified: cayenne/main/trunk/docs/doc/src/main/resources/RELEASE-NOTES.txt
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/docs/doc/src/main/resources/RELEASE-NOTES.txt?rev=932955&r1=932954&r2=932955&view=diff
==============================================================================
--- cayenne/main/trunk/docs/doc/src/main/resources/RELEASE-NOTES.txt (original)
+++ cayenne/main/trunk/docs/doc/src/main/resources/RELEASE-NOTES.txt Sun Apr 11 17:48:31 2010
@@ -34,6 +34,7 @@ CAY-1374 Add parent dataMap property to 
 CAY-1393 Update velocity to 1.6.3
 CAY-1394 DI-based replacement for JNDI hack
 CAY-1415 Replace WebApplicationContextFilter with a DI-enabled filter
+CAY-1419 File-based ResourceLocator to replace legacy FileConfiguration
 
 Bug Fixes Since 3.0:
 

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/CayenneRuntime.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/CayenneRuntime.java?rev=932955&r1=932954&r2=932955&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/CayenneRuntime.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/CayenneRuntime.java
Sun Apr 11 17:48:31 2010
@@ -25,6 +25,7 @@ import org.apache.cayenne.ObjectContext;
 import org.apache.cayenne.di.DIBootstrap;
 import org.apache.cayenne.di.Injector;
 import org.apache.cayenne.di.Module;
+import org.apache.cayenne.resource.ResourceLocator;
 
 /**
  * A superclass of possible Cayenne runtime objects. A CayenneRuntime is the main access
@@ -35,24 +36,24 @@ import org.apache.cayenne.di.Module;
  */
 public abstract class CayenneRuntime {
 
-    protected String name;
+    protected String configurationLocation;
     protected Injector injector;
     protected Module[] modules;
 
     /**
      * Creates a CayenneRuntime with configuration based on supplied array of DI modules.
      */
-    public CayenneRuntime(String name, Module... modules) {
+    public CayenneRuntime(String configurationLocation, Module... modules) {
 
-        if (name == null) {
-            throw new NullPointerException("Null runtime name");
+        if (configurationLocation == null) {
+            throw new NullPointerException("Null runtime configurationLocation");
         }
 
         if (modules == null) {
             modules = new Module[0];
         }
 
-        this.name = name;
+        this.configurationLocation = configurationLocation;
         this.modules = modules;
         this.injector = DIBootstrap.createInjector(modules);
     }
@@ -60,13 +61,13 @@ public abstract class CayenneRuntime {
     /**
      * Creates a CayenneRuntime with configuration based on supplied array of DI modules.
      */
-    public CayenneRuntime(String name, Collection<Module> modules) {
+    public CayenneRuntime(String configurationLocation, Collection<Module> modules)
{
 
-        if (name == null) {
-            throw new NullPointerException("Null runtime name");
+        if (configurationLocation == null) {
+            throw new NullPointerException("Null runtime configurationLocation");
         }
 
-        this.name = name;
+        this.configurationLocation = configurationLocation;
 
         if (modules == null) {
             this.modules = new Module[0];
@@ -79,11 +80,11 @@ public abstract class CayenneRuntime {
     }
 
     /**
-     * Returns runtime name. By default a name of Cayenne project XML file contains a
-     * runtime name in it in the form "cayenne-<name>.xml".
+     * Returns location of the runtime configuration resource. E.g. "cayenne-xyz.xml".
+     * Configuration URL is passing this location to {@link ResourceLocator}.
      */
-    public String getName() {
-        return name;
+    public String getConfigurationLocation() {
+        return configurationLocation;
     }
 
     /**

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/RuntimeProperties.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/RuntimeProperties.java?rev=932955&r1=932954&r2=932955&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/RuntimeProperties.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/RuntimeProperties.java
Sun Apr 11 17:48:31 2010
@@ -18,7 +18,6 @@
  ****************************************************************/
 package org.apache.cayenne.configuration;
 
-
 /**
  * Represents a properties map for a given {@link CayenneRuntime}.
  * 
@@ -29,7 +28,7 @@ public interface RuntimeProperties {
     /**
      * A property defining the name of the current runtime.
      */
-    public static final String CAYENNE_RUNTIME_NAME = "cayenne.runtime.name";
+    public static final String CONFIGURATION_LOCATION = "cayenne.config.location";
 
     /**
      * Returns property value for a given key.

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/server/CayenneServerModule.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/server/CayenneServerModule.java?rev=932955&r1=932954&r2=932955&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/server/CayenneServerModule.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/server/CayenneServerModule.java
Sun Apr 11 17:48:31 2010
@@ -62,18 +62,18 @@ import org.apache.cayenne.resource.Resou
  */
 public class CayenneServerModule implements Module {
 
-    protected String runtimeName;
+    protected String configurationLocation;
 
-    public CayenneServerModule(String runtimeName) {
-        this.runtimeName = runtimeName;
+    public CayenneServerModule(String configurationLocation) {
+        this.configurationLocation = configurationLocation;
     }
 
     public void configure(Binder binder) {
 
         // configure global stack properties
         binder.bindMap(RuntimeProperties.class).put(
-                RuntimeProperties.CAYENNE_RUNTIME_NAME,
-                runtimeName);
+                RuntimeProperties.CONFIGURATION_LOCATION,
+                configurationLocation);
 
         // configure known DbAdapter detectors in reverse order of popularity. Users can
         // add their own to install custom adapters automatically

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/server/CayenneServerRuntime.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/server/CayenneServerRuntime.java?rev=932955&r1=932954&r2=932955&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/server/CayenneServerRuntime.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/server/CayenneServerRuntime.java
Sun Apr 11 17:48:31 2010
@@ -34,12 +34,12 @@ import org.apache.cayenne.di.Module;
 public class CayenneServerRuntime extends CayenneRuntime {
 
     /**
-     * Creates a server runtime object based on XML configuration file called
-     * "cayenne-<name>.xml" and configures the runtime with a standard set of services
-     * contained in {@link CayenneServerModule}.
+     * Creates a server runtime object based on XML configuration file specified via
+     * 'configurationLocation' parameter. Configures the runtime with a standard set of
+     * services contained in {@link CayenneServerModule}.
      */
-    public CayenneServerRuntime(String name) {
-        super(name, new CayenneServerModule(name));
+    public CayenneServerRuntime(String configurationLocation) {
+        super(configurationLocation, new CayenneServerModule(configurationLocation));
     }
 
     /**
@@ -49,8 +49,8 @@ public class CayenneServerRuntime extend
      * {@link CayenneServerModule} or its subclass as one of the modules to this
      * constructor.
      */
-    public CayenneServerRuntime(String name, Module... modules) {
-        super(name, modules);
+    public CayenneServerRuntime(String configurationLocation, Module... modules) {
+        super(configurationLocation, modules);
     }
 
     /**
@@ -60,8 +60,8 @@ public class CayenneServerRuntime extend
      * {@link CayenneServerModule} or its subclass as one of the modules to this
      * constructor.
      */
-    public CayenneServerRuntime(String name, Collection<Module> modules) {
-        super(name, modules);
+    public CayenneServerRuntime(String configurationLocation, Collection<Module> modules)
{
+        super(configurationLocation, modules);
     }
 
     /**

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/server/DataDomainProvider.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/server/DataDomainProvider.java?rev=932955&r1=932954&r2=932955&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/server/DataDomainProvider.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/server/DataDomainProvider.java
Sun Apr 11 17:48:31 2010
@@ -28,7 +28,6 @@ import org.apache.cayenne.access.DataDom
 import org.apache.cayenne.access.DataNode;
 import org.apache.cayenne.access.dbsync.SchemaUpdateStrategy;
 import org.apache.cayenne.configuration.AdhocObjectFactory;
-import org.apache.cayenne.configuration.ConfigurationNameMapper;
 import org.apache.cayenne.configuration.ConfigurationTree;
 import org.apache.cayenne.configuration.DataChannelDescriptor;
 import org.apache.cayenne.configuration.DataChannelDescriptorLoader;
@@ -73,9 +72,6 @@ public class DataDomainProvider implemen
     @Inject
     protected AdhocObjectFactory objectFactory;
 
-    @Inject
-    protected ConfigurationNameMapper nameMapper;
-
     protected volatile DataDomain dataDomain;
 
     public DataDomain get() throws ConfigurationException {
@@ -104,23 +100,29 @@ public class DataDomainProvider implemen
     }
 
     protected void createDataChannel() throws Exception {
-        String runtimeName = configurationProperties
-                .get(RuntimeProperties.CAYENNE_RUNTIME_NAME);
+        String configurationLocation = configurationProperties
+                .get(RuntimeProperties.CONFIGURATION_LOCATION);
+
+        if (configurationLocation == null) {
+            throw new DataDomainLoadException(
+                    "No configuration location available. "
+                            + "You can specify when creating Cayenne runtime "
+                            + "or via a system property '%s'",
+                    RuntimeProperties.CONFIGURATION_LOCATION);
+        }
 
         long t0 = System.currentTimeMillis();
         if (logger.isDebugEnabled()) {
-            logger.debug("starting configuration loading: " + runtimeName);
+            logger.debug("starting configuration loading: " + configurationLocation);
         }
 
-        String resourceName = nameMapper.configurationLocation(
-                DataChannelDescriptor.class,
-                runtimeName);
-        Collection<Resource> configurations = resourceLocator.findResources(resourceName);
+        Collection<Resource> configurations = resourceLocator
+                .findResources(configurationLocation);
 
         if (configurations.isEmpty()) {
             throw new DataDomainLoadException(
                     "Configuration file \"%s\" is not found.",
-                    resourceName);
+                    configurationLocation);
         }
 
         Resource configurationResource = configurations.iterator().next();
@@ -144,7 +146,7 @@ public class DataDomainProvider implemen
 
         if (logger.isDebugEnabled()) {
             logger.debug("finished configuration loading: "
-                    + runtimeName
+                    + configurationLocation
                     + " in "
                     + (t1 - t0)
                     + " ms.");

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/web/CayenneFilter.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/web/CayenneFilter.java?rev=932955&r1=932954&r2=932955&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/web/CayenneFilter.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/web/CayenneFilter.java
Sun Apr 11 17:48:31 2010
@@ -43,10 +43,10 @@ import org.apache.cayenne.util.Util;
  * custom modules are loaded after the two standard ones to allow custom service
  * overrides. Filter initialization parameters:
  * <ul>
- * <li>runtime-name - (optional) a name of Cayenne runtime. When looking for a Cayenne
- * configuration XML file in the classpath, Cayenne derives the name of the file from the
- * value of this parameter. If "runtime-name" is "foo", configuration file name is assumed
- * to be "cayenne-foo.xml". By default filter name is used as runtime name.
+ * <li>configuration-location - (optional) a name of Cayenne configuration XML file
that
+ * will be used to load Cayenne stack. If missing, the filter name will be used to derive
+ * the location using the following naming convention: if filter name is "foo",
+ * configuration file name is name is "cayenne-foo.xml".
  * <li>extra-modules - (optional) a comma or space-separated list of class names, with
  * each class implementing {@link Module} interface. These are the custom modules loaded
  * after the two standard ones that allow users to override any Cayenne runtime aspects,
@@ -61,7 +61,7 @@ import org.apache.cayenne.util.Util;
  */
 public class CayenneFilter implements Filter {
 
-    static final String RUNTIME_NAME_PARAMETER = "runtime-name";
+    static final String CONFIGURATION_LOCATION_PARAMETER = "configuration-location";
     static final String EXTRA_MODULES_PARAMETER = "extra-modules";
 
     protected ServletContext servletContext;
@@ -70,20 +70,21 @@ public class CayenneFilter implements Fi
 
         this.servletContext = config.getServletContext();
 
-        String runtimeName = config.getInitParameter(RUNTIME_NAME_PARAMETER);
-        if (runtimeName == null) {
-            runtimeName = config.getFilterName();
+        String configurationLocation = config
+                .getInitParameter(CONFIGURATION_LOCATION_PARAMETER);
+        if (configurationLocation == null) {
+            configurationLocation = "cayenne-" + config.getFilterName() + ".xml";
         }
 
-        if (runtimeName == null) {
+        if (configurationLocation == null) {
             throw new ServletException(
                     "Can't initialize Cayenne runtime. CayenneFilter has no name and no '"
-                            + RUNTIME_NAME_PARAMETER
+                            + CONFIGURATION_LOCATION_PARAMETER
                             + "' parameter");
         }
 
         Collection<Module> modules = new ArrayList<Module>(5);
-        modules.add(new CayenneServerModule(runtimeName));
+        modules.add(new CayenneServerModule(configurationLocation));
         modules.add(new CayenneWebModule());
 
         String extraModules = config.getInitParameter(EXTRA_MODULES_PARAMETER);
@@ -111,7 +112,9 @@ public class CayenneFilter implements Fi
             }
         }
 
-        CayenneServerRuntime runtime = new CayenneServerRuntime(runtimeName, modules);
+        CayenneServerRuntime runtime = new CayenneServerRuntime(
+                configurationLocation,
+                modules);
         WebUtil.setCayenneRuntime(config.getServletContext(), runtime);
     }
 

Added: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/resource/FilesystemResourceLocator.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/resource/FilesystemResourceLocator.java?rev=932955&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/resource/FilesystemResourceLocator.java
(added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/resource/FilesystemResourceLocator.java
Sun Apr 11 17:48:31 2010
@@ -0,0 +1,115 @@
+/*****************************************************************
+ *   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.cayenne.resource;
+
+import java.io.File;
+import java.net.MalformedURLException;
+import java.util.ArrayList;
+import java.util.Collection;
+
+import org.apache.cayenne.CayenneRuntimeException;
+import org.apache.cayenne.ConfigurationException;
+
+/**
+ * A {@link ResourceLocator} that can locate resources in the filesystem. Instances of
+ * {@link FilesystemResourceLocator} are explicitly created by the user and then bound to
+ * a DI registry. E.g.:
+ * 
+ * <pre>
+ * class MyModule implements Module {
+ * 
+ *     public void configure(Binder binder) {
+ *        File dir1 = ...
+ *        File dir2 = ...
+ *        binder.bind(ResourceLocator.class).
+ *           toInstance(new FilesystemResourceLocator(dir1, dir2);
+ *     }
+ * </pre>
+ * 
+ * @since 3.1
+ */
+public class FilesystemResourceLocator implements ResourceLocator {
+
+    protected File[] roots;
+
+    /**
+     * Creates a new {@link FilesystemResourceLocator}, using an array of base locations
+     * ("roots"). If a location is a file, its parent directory is used for resolving. If
+     * location is a directory, it is used as is. If no locations are specified, current
+     * application directory is used as a single base.
+     */
+    public FilesystemResourceLocator(File... roots) {
+        init(roots);
+    }
+
+    /**
+     * Creates a new {@link FilesystemResourceLocator}, using a collection of base
+     * locations. If a location is a file, its parent directory is used for resolving. If
+     * location is a directory, it is used as is. If no locations are specified, current
+     * application directory is used as a single base.
+     */
+    public FilesystemResourceLocator(Collection<File> roots) {
+        if (roots == null) {
+            throw new NullPointerException("Null roots");
+        }
+
+        init(roots.toArray(new File[roots.size()]));
+    }
+
+    private void init(File[] roots) {
+
+        if (roots == null || roots.length == 0) {
+            roots = new File[] {
+                new File(System.getProperty("user.dir"))
+            };
+        }
+
+        this.roots = new File[roots.length];
+        for (int i = 0; i < roots.length; i++) {
+            File root = roots[i].isDirectory() ? roots[i] : roots[i].getParentFile();
+            if (root == null) {
+                throw new ConfigurationException("Invalid root: %s", roots[i]);
+            }
+
+            this.roots[i] = root;
+        }
+    }
+
+    public Collection<Resource> findResources(String name) {
+        Collection<Resource> resources = new ArrayList<Resource>(3);
+
+        for (File root : roots) {
+
+            File resourceFile = new File(root, name);
+            if (resourceFile.exists()) {
+                try {
+                    resources.add(new URLResource(resourceFile.toURL()));
+                }
+                catch (MalformedURLException e) {
+                    throw new CayenneRuntimeException(
+                            "Can't convert file to URL: %s",
+                            e,
+                            resourceFile.getAbsolutePath());
+                }
+            }
+        }
+
+        return resources;
+    }
+}

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/conf/ConfigurationTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/conf/ConfigurationTest.java?rev=932955&r1=932954&r2=932955&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/conf/ConfigurationTest.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/conf/ConfigurationTest.java
Sun Apr 11 17:48:31 2010
@@ -19,8 +19,6 @@
 
 package org.apache.cayenne.conf;
 
-import java.io.File;
-
 import org.apache.cayenne.ConfigurationException;
 import org.apache.cayenne.access.DataDomain;
 import org.apache.cayenne.unit.CayenneCase;
@@ -48,24 +46,4 @@ public class ConfigurationTest extends C
         }
     }
 
-    public void testFileConfigurationConstructorWithNullFile() {
-        try {
-            new FileConfiguration((File) null);
-            fail("expected ConfigurationException!");
-        }
-        catch (ConfigurationException ex) {
-            // OK
-        }
-    }
-
-    public void testFileConfigurationConstructorWithNullName() {
-        try {
-            new FileConfiguration((String) null);
-            fail("expected ConfigurationException!");
-        }
-        catch (ConfigurationException ex) {
-            // OK
-        }
-    }
-
 }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/configuration/server/CayenneServerRuntimeTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/configuration/server/CayenneServerRuntimeTest.java?rev=932955&r1=932954&r2=932955&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/configuration/server/CayenneServerRuntimeTest.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/configuration/server/CayenneServerRuntimeTest.java
Sun Apr 11 17:48:31 2010
@@ -37,7 +37,7 @@ public class CayenneServerRuntimeTest ex
     public void testDefaultConstructor() {
         CayenneServerRuntime runtime = new CayenneServerRuntime("xxxx");
 
-        assertEquals("xxxx", runtime.getName());
+        assertEquals("xxxx", runtime.getConfigurationLocation());
 
         assertEquals(1, runtime.getModules().length);
         assertTrue(runtime.getModules()[0] instanceof CayenneServerModule);
@@ -63,7 +63,7 @@ public class CayenneServerRuntimeTest ex
 
         CayenneServerRuntime runtime = new CayenneServerRuntime("yyyy", m1, m2);
 
-        assertEquals("yyyy", runtime.getName());
+        assertEquals("yyyy", runtime.getConfigurationLocation());
         assertEquals(2, runtime.getModules().length);
 
         for (int i = 0; i < configured.length; i++) {

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/configuration/server/DataDomainProviderTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/configuration/server/DataDomainProviderTest.java?rev=932955&r1=932954&r2=932955&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/configuration/server/DataDomainProviderTest.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/configuration/server/DataDomainProviderTest.java
Sun Apr 11 17:48:31 2010
@@ -91,7 +91,7 @@ public class DataDomainProviderTest exte
         final ResourceLocator locator = new ResourceLocator() {
 
             public Collection<Resource> findResources(String name) {
-                assertEquals("cayenne-" + testConfigName + ".xml", name);
+                assertEquals(testConfigName, name);
                 return Collections.<Resource> singleton(new MockResource());
             }
         };
@@ -106,7 +106,7 @@ public class DataDomainProviderTest exte
 
         final DefaultRuntimeProperties testProperties = new DefaultRuntimeProperties(
                 Collections.singletonMap(
-                        RuntimeProperties.CAYENNE_RUNTIME_NAME,
+                        RuntimeProperties.CONFIGURATION_LOCATION,
                         testConfigName));
 
         Module testModule = new Module() {

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/configuration/web/CayenneFilterTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/configuration/web/CayenneFilterTest.java?rev=932955&r1=932954&r2=932955&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/configuration/web/CayenneFilterTest.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/configuration/web/CayenneFilterTest.java
Sun Apr 11 17:48:31 2010
@@ -47,14 +47,14 @@ public class CayenneFilterTest extends T
         CayenneRuntime runtime = WebUtil.getCayenneRuntime(context);
         assertNotNull(runtime);
 
-        assertEquals("abc", runtime.getName());
+        assertEquals("cayenne-abc.xml", runtime.getConfigurationLocation());
     }
 
     public void testInitWithRuntimeName() throws Exception {
 
         MockFilterConfig config = new MockFilterConfig();
         config.setFilterName("abc");
-        config.setInitParameter(CayenneFilter.RUNTIME_NAME_PARAMETER, "xyz");
+        config.setInitParameter(CayenneFilter.CONFIGURATION_LOCATION_PARAMETER, "xyz");
 
         MockServletContext context = new MockServletContext();
         config.setupServletContext(context);
@@ -65,10 +65,10 @@ public class CayenneFilterTest extends T
         CayenneRuntime runtime = WebUtil.getCayenneRuntime(context);
         assertNotNull(runtime);
 
-        assertEquals("xyz", runtime.getName());
+        assertEquals("xyz", runtime.getConfigurationLocation());
     }
 
-    public void testInitWithStarndardModules() throws Exception {
+    public void testInitWithStandardModules() throws Exception {
 
         MockFilterConfig config = new MockFilterConfig();
         config.setFilterName("abc");
@@ -84,7 +84,7 @@ public class CayenneFilterTest extends T
         CayenneRuntime runtime = WebUtil.getCayenneRuntime(context);
         assertNotNull(runtime);
 
-        assertEquals("abc", runtime.getName());
+        assertEquals("cayenne-abc.xml", runtime.getConfigurationLocation());
         assertEquals(2, runtime.getModules().length);
         assertTrue(runtime.getModules()[0] instanceof CayenneServerModule);
         assertTrue(runtime.getModules()[1] instanceof CayenneWebModule);

Added: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/resource/FilesystemResourceLocatorTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/resource/FilesystemResourceLocatorTest.java?rev=932955&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/resource/FilesystemResourceLocatorTest.java
(added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/resource/FilesystemResourceLocatorTest.java
Sun Apr 11 17:48:31 2010
@@ -0,0 +1,102 @@
+/*****************************************************************
+ *   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.cayenne.resource;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+
+import org.apache.cayenne.unit.BasicCase;
+
+public class FilesystemResourceLocatorTest extends BasicCase {
+
+    public void testArrayConstructor() {
+        FilesystemResourceLocator l1 = new FilesystemResourceLocator();
+        assertEquals(1, l1.roots.length);
+        assertEquals(System.getProperty("user.dir"), l1.roots[0].getPath());
+
+        File base = getTestDir();
+        File f1 = new File(base, "f1");
+        File f2 = new File(new File(base, "f2"), "f3");
+
+        FilesystemResourceLocator l2 = new FilesystemResourceLocator(f1, f2);
+        assertEquals(2, l2.roots.length);
+        assertEquals(base, l2.roots[0]);
+        assertEquals(new File(base, "f2"), l2.roots[1]);
+    }
+
+    public void testCollectionConstructor() {
+        FilesystemResourceLocator l1 = new FilesystemResourceLocator(Collections
+                .<File> emptyList());
+        assertEquals(1, l1.roots.length);
+        assertEquals(System.getProperty("user.dir"), l1.roots[0].getPath());
+
+        File base = getTestDir();
+        File f1 = new File(base, "f1");
+        File f2 = new File(new File(base, "f2"), "f3");
+
+        FilesystemResourceLocator l2 = new FilesystemResourceLocator(Arrays
+                .asList(f1, f2));
+        assertEquals(2, l2.roots.length);
+        assertEquals(base, l2.roots[0]);
+        assertEquals(new File(base, "f2"), l2.roots[1]);
+    }
+
+    public void testFindResources() throws Exception {
+
+        File base = new File(getTestDir(), getClass().getName());
+        File root1 = new File(base, "r1");
+        File root2 = new File(base, "r2");
+
+        root1.mkdirs();
+        root2.mkdirs();
+
+        FilesystemResourceLocator locator = new FilesystemResourceLocator(root1, root2);
+        Collection<Resource> resources1 = locator.findResources("x.txt");
+        assertNotNull(resources1);
+        assertEquals(0, resources1.size());
+
+        File f1 = new File(root1, "x.txt");
+        touch(f1);
+
+        Collection<Resource> resources2 = locator.findResources("x.txt");
+        assertNotNull(resources2);
+        assertEquals(1, resources2.size());
+        assertEquals(f1.toURL(), resources2.iterator().next().getURL());
+
+        File f2 = new File(root2, "x.txt");
+        touch(f2);
+
+        Collection<Resource> resources3 = locator.findResources("x.txt");
+        assertNotNull(resources3);
+        assertEquals(2, resources3.size());
+        
+        Resource[] resources3a = resources3.toArray(new Resource[2]);
+        assertEquals(f1.toURL(), resources3a[0].getURL());
+        assertEquals(f2.toURL(), resources3a[1].getURL());
+    }
+
+    private void touch(File f) throws Exception {
+        FileOutputStream out = new FileOutputStream(f);
+        out.write('a');
+        out.close();
+    }
+}

Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/CreateNodeAction.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/CreateNodeAction.java?rev=932955&r1=932954&r2=932955&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/CreateNodeAction.java
(original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/CreateNodeAction.java
Sun Apr 11 17:48:31 2010
@@ -47,7 +47,7 @@ public class CreateNodeAction extends Ca
     /**
      * Constructor for CreateNodeAction.
      * 
-     * @param name
+     * @param location
      */
     public CreateNodeAction(Application application) {
         super(getActionName(), application);

Modified: cayenne/main/trunk/framework/cayenne-tools/src/main/java/org/apache/cayenne/tools/DataPortTask.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-tools/src/main/java/org/apache/cayenne/tools/DataPortTask.java?rev=932955&r1=932954&r2=932955&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-tools/src/main/java/org/apache/cayenne/tools/DataPortTask.java
(original)
+++ cayenne/main/trunk/framework/cayenne-tools/src/main/java/org/apache/cayenne/tools/DataPortTask.java
Sun Apr 11 17:48:31 2010
@@ -26,10 +26,14 @@ import java.util.HashSet;
 import org.apache.cayenne.access.DataDomain;
 import org.apache.cayenne.access.DataNode;
 import org.apache.cayenne.access.DataPort;
-import org.apache.cayenne.conf.Configuration;
-import org.apache.cayenne.conf.FileConfiguration;
+import org.apache.cayenne.configuration.server.CayenneServerModule;
+import org.apache.cayenne.configuration.server.CayenneServerRuntime;
+import org.apache.cayenne.di.Binder;
+import org.apache.cayenne.di.Module;
 import org.apache.cayenne.map.DataMap;
 import org.apache.cayenne.map.DbEntity;
+import org.apache.cayenne.resource.FilesystemResourceLocator;
+import org.apache.cayenne.resource.ResourceLocator;
 import org.apache.cayenne.util.Util;
 import org.apache.tools.ant.BuildException;
 import org.apache.tools.ant.Project;
@@ -59,30 +63,50 @@ public class DataPortTask extends Cayenn
     public void execute() throws BuildException {
         validateParameters();
 
-        FileConfiguration configuration = new FileConfiguration(projectFile);
+        String projectFileLocation = projectFile.getName();
+        Module module = new CayenneServerModule(projectFileLocation) {
 
-        ClassLoader threadContextClassLoader = Thread.currentThread().getContextClassLoader();
+            @Override
+            public void configure(Binder binder) {
+                super.configure(binder);
+
+                binder.bind(ResourceLocator.class).toInstance(
+                        new FilesystemResourceLocator(projectFile));
+            }
+        };
+
+        CayenneServerRuntime runtime = new CayenneServerRuntime(
+                projectFileLocation,
+                module);
+        DataDomain domain;
+
+        ClassLoader threadContextClassLoader = Thread
+                .currentThread()
+                .getContextClassLoader();
         try {
             // need to set context class loader so that cayenne can find jdbc driver and
             // PasswordEncoder
+            // TODO: andrus 04/11/2010 is this still relevant in 3.1?
             Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
-            configuration.initialize();
+
+            domain = runtime.getDataDomain();
         }
         catch (Exception ex) {
             throw new BuildException("Error loading Cayenne configuration from "
                     + projectFile, ex);
-        } finally {
+        }
+        finally {
             // set back to original ClassLoader
             Thread.currentThread().setContextClassLoader(threadContextClassLoader);
         }
 
         // perform project validation
-        DataNode source = findNode(configuration, srcNode);
+        DataNode source = domain.getNode(srcNode);
         if (source == null) {
             throw new BuildException("srcNode not found in the project: " + srcNode);
         }
 
-        DataNode destination = findNode(configuration, destNode);
+        DataNode destination = domain.getNode(destNode);
         if (destination == null) {
             throw new BuildException("destNode not found in the project: " + destNode);
         }
@@ -111,17 +135,6 @@ public class DataPortTask extends Cayenn
         }
     }
 
-    protected DataNode findNode(Configuration configuration, String name) {
-        for (DataDomain domain : configuration.getDomains()) {
-            DataNode node = domain.getNode(name);
-            if (node != null) {
-                return node;
-            }
-        }
-
-        return null;
-    }
-
     protected Collection<DbEntity> getAllEntities(DataNode source, DataNode target)
{
         // use a set to exclude duplicates, though a valid project will probably have
         // none...

Modified: cayenne/main/trunk/itests/cayenne-di-stack/src/main/java/org/apache/cayenne/configuration/server/CayenneServerRuntimeCase.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/itests/cayenne-di-stack/src/main/java/org/apache/cayenne/configuration/server/CayenneServerRuntimeCase.java?rev=932955&r1=932954&r2=932955&view=diff
==============================================================================
--- cayenne/main/trunk/itests/cayenne-di-stack/src/main/java/org/apache/cayenne/configuration/server/CayenneServerRuntimeCase.java
(original)
+++ cayenne/main/trunk/itests/cayenne-di-stack/src/main/java/org/apache/cayenne/configuration/server/CayenneServerRuntimeCase.java
Sun Apr 11 17:48:31 2010
@@ -47,9 +47,10 @@ public abstract class CayenneServerRunti
 		RuntimeName name = getRuntimeName();
 		assertNotNull(name);
 
-		runtime = runtimeCache.get(name);
+		String location = "cayenne-" + name + ".xml";
+		runtime = runtimeCache.get(location);
 		if (runtime == null) {
-			runtime = new CayenneServerRuntime(name.name());
+			runtime = new CayenneServerRuntime(location);
 			runtimeCache.put(name, runtime);
 
 			// setup schema



Mime
View raw message