You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cayenne.apache.org by aa...@apache.org on 2008/05/25 21:03:09 UTC
svn commit: r660018 - 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...
Author: aadamchik
Date: Sun May 25 12:03:08 2008
New Revision: 660018
URL: http://svn.apache.org/viewvc?rev=660018&view=rev
Log:
CAY-943 Support multiple cayenne.xml files in the project
(preliminary 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/FileConfiguration.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=660018&r1=660017&r2=660018&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 May 25 12:03:08 2008
@@ -193,9 +193,16 @@
/**
* Indicates whether {@link #initialize}can be called. Returning <code>false</code>
- * allows new instances to delay or refuse the initialization process.
+ * allows new instances to delay or refuse the initialization process. This
+ * impementation returns true unconditionally.
+ *
+ * @deprecated since 3.0 - this method is redundant, as subclasses can prevent
+ * initialization by overriding {@link #initialize()} and throwing an
+ * exception.
*/
- public abstract boolean canInitialize();
+ public boolean canInitialize() {
+ return true;
+ }
/**
* Initializes the new instance.
@@ -205,9 +212,14 @@
public abstract void initialize() throws Exception;
/**
- * Called after successful completion of {@link #initialize}.
+ * Called after successful completion of {@link #initialize}. This implementation is
+ * a noop.
+ *
+ * @deprecated since 3.0 subclasses are recommended to override {@link #initialize()}.
*/
- public abstract void didInitialize();
+ public void didInitialize() {
+ // noop
+ }
/**
* Returns the resource locator used for finding and loading resources.
@@ -217,8 +229,8 @@
/**
* Returns a DataDomain as a stream or <code>null</code> if it cannot be found.
*
- * @deprecated since 3.0 This method is specific to subclass, so it should not be in the
- * superclass.
+ * @deprecated since 3.0 This method is specific to subclass, so it should not be in
+ * the superclass.
*/
protected InputStream getDomainConfiguration() {
throw new UnsupportedOperationException();
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=660018&r1=660017&r2=660018&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 May 25 12:03:08 2008
@@ -124,18 +124,6 @@
}
/**
- * Default implementation of {@link Configuration#canInitialize}. Creates a
- * ResourceLocator suitable for loading from the CLASSPATH, unless it has already been
- * set in a subclass. Always returns <code>true</code>.
- */
- @Override
- public boolean canInitialize() {
- logger.debug("canInitialize started.");
- // allow to proceed
- return true;
- }
-
- /**
* Initializes all Cayenne resources. Loads all configured domains and their data
* maps, initializes all domain Nodes and their DataSources.
*/
@@ -173,16 +161,6 @@
}
/**
- * Default implementation of {@link Configuration#didInitialize}. Currently does
- * nothing except logging.
- */
- @Override
- public void didInitialize() {
- // empty default implementation
- logger.debug("didInitialize finished.");
- }
-
- /**
* Returns the default ResourceLocator configured for CLASSPATH lookups.
*/
@Override
@@ -208,9 +186,9 @@
}
/**
- * 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.
+ * 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.
*/
@Override
protected InputStream getMapConfiguration(String location) {
Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/conf/FileConfiguration.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/conf/FileConfiguration.java?rev=660018&r1=660017&r2=660018&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/conf/FileConfiguration.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/conf/FileConfiguration.java Sun May 25 12:03:08 2008
@@ -27,171 +27,173 @@
import org.apache.commons.logging.LogFactory;
/**
- * FileConfiguration loads a Cayenne configuraton file from a given
- * location in the file system.
- *
+ * FileConfiguration loads a Cayenne configuraton file from a given location in the file
+ * system.
+ *
* @author Holger Hoffstaette
*/
public class FileConfiguration extends DefaultConfiguration {
+
private static final Log logger = LogFactory.getLog(FileConfiguration.class);
- /**
- * The domain file used for this configuration
- */
- protected File projectFile;
-
- /**
- * Default constructor.
- * Simply calls {@link FileConfiguration#FileConfiguration(String)}
- * with {@link Configuration#DEFAULT_DOMAIN_FILE} as argument.
- * @see DefaultConfiguration#DefaultConfiguration()
- */
- public FileConfiguration() {
- this(Configuration.DEFAULT_DOMAIN_FILE);
- }
-
- /**
- * Creates a configuration that uses the provided file name
- * as the main project file, ignoring any other lookup strategies.
- * The file name is <b>not</b> checked for existence and must not
- * contain relative or absolute paths, i.e. only the file name.
- *
- * @throws ConfigurationException when projectFile is <code>null</code>.
- * @see DefaultConfiguration#DefaultConfiguration(String)
- */
- public FileConfiguration(String domainConfigurationName) {
- super(domainConfigurationName);
-
- // set the project file
- this.projectFile = new File(domainConfigurationName);
-
- // configure the ResourceLocator for plain files
- ResourceLocator locator = this.getResourceLocator();
- locator.setSkipAbsolutePath(false);
- locator.setSkipClasspath(true);
- locator.setSkipCurrentDirectory(false);
- locator.setSkipHomeDirectory(true);
-
- // add the file's location to the search path, if it exists
- File projectDirectory = this.getProjectDirectory();
- if (projectDirectory != null) {
- locator.addFilesystemPath(projectDirectory.getPath());
- }
- }
-
- /**
- * Creates a configuration that uses the provided file
- * as the main project file, ignoring any other lookup strategies.
- *
- * @throws ConfigurationException when projectFile is <code>null</code>,
- * a directory or not readable.
- */
- public FileConfiguration(File domainConfigurationFile) {
- super();
-
- logger.debug("using domain file: " + domainConfigurationFile);
-
- // set the project file
- this.setProjectFile(domainConfigurationFile);
-
- // configure the ResourceLocator for plain files
- ResourceLocator locator = this.getResourceLocator();
- locator.setSkipAbsolutePath(false);
- locator.setSkipClasspath(true);
- locator.setSkipCurrentDirectory(false);
- locator.setSkipHomeDirectory(true);
-
- // add the file's location to the search path, if it exists
- File projectDirectory = this.getProjectDirectory();
- if (projectDirectory != null) {
- locator.addFilesystemPath(projectDirectory);
- }
- }
-
- /**
- * Adds the given String as a custom path for filesystem lookups.
- * The path can be relative or absolute and is <i>not</i> checked
- * for existence.
- *
- * This allows for easy customization of resource search paths after
- * Constructor invocation:
- * <pre>
- * conf = new FileConfiguration("myconfig-cayenne.xml");
- * conf.addFilesystemPath(new File("a/relative/path"));
- * conf.addFilesystemPath(new File("/an/absolute/search/path"));
- * Configuration.initializeSharedConfiguration(conf);
- * </pre>
- *
- * Alternatively use {@link FileConfiguration#addFilesystemPath(File)}
- * for adding a path that is checked for existence.
- *
- * @throws IllegalArgumentException if <code>path</code> is <code>null</code>.
- */
- public void addFilesystemPath(String path) {
- this.getResourceLocator().addFilesystemPath(path);
- }
-
- /**
- * Adds the given directory as a path for filesystem lookups.
- * The directory is checked for existence.
- *
- * @throws IllegalArgumentException if <code>path</code> is <code>null</code>,
- * not a directory or not readable.
- */
- public void addFilesystemPath(File path) {
- this.getResourceLocator().addFilesystemPath(path);
- }
-
- /**
- * Only returns <code>true</code> when {@link #getProjectFile} does not
- * return <code>null</code>.
- */
- @Override
+ /**
+ * The domain file used for this configuration
+ */
+ protected File projectFile;
+
+ /**
+ * Default constructor. Simply calls
+ * {@link FileConfiguration#FileConfiguration(String)} with
+ * {@link Configuration#DEFAULT_DOMAIN_FILE} as argument.
+ *
+ * @see DefaultConfiguration#DefaultConfiguration()
+ */
+ public FileConfiguration() {
+ this(Configuration.DEFAULT_DOMAIN_FILE);
+ }
+
+ /**
+ * Creates a configuration that uses the provided file name as the main project file,
+ * ignoring any other lookup strategies. The file name is <b>not</b> checked for
+ * existence and must not contain relative or absolute paths, i.e. only the file name.
+ *
+ * @throws ConfigurationException when projectFile is <code>null</code>.
+ * @see DefaultConfiguration#DefaultConfiguration(String)
+ */
+ public FileConfiguration(String domainConfigurationName) {
+ super(domainConfigurationName);
+
+ // set the project file
+ this.projectFile = new File(domainConfigurationName);
+
+ // configure the ResourceLocator for plain files
+ ResourceLocator locator = this.getResourceLocator();
+ locator.setSkipAbsolutePath(false);
+ locator.setSkipClasspath(true);
+ locator.setSkipCurrentDirectory(false);
+ locator.setSkipHomeDirectory(true);
+
+ // add the file's location to the search path, if it exists
+ File projectDirectory = this.getProjectDirectory();
+ if (projectDirectory != null) {
+ locator.addFilesystemPath(projectDirectory.getPath());
+ }
+ }
+
+ /**
+ * Creates a configuration that uses the provided file as the main project file,
+ * ignoring any other lookup strategies.
+ *
+ * @throws ConfigurationException when projectFile is <code>null</code>, a
+ * directory or not readable.
+ */
+ public FileConfiguration(File domainConfigurationFile) {
+ super();
+
+ logger.debug("using domain file: " + domainConfigurationFile);
+
+ // set the project file
+ this.setProjectFile(domainConfigurationFile);
+
+ // configure the ResourceLocator for plain files
+ ResourceLocator locator = this.getResourceLocator();
+ locator.setSkipAbsolutePath(false);
+ locator.setSkipClasspath(true);
+ locator.setSkipCurrentDirectory(false);
+ locator.setSkipHomeDirectory(true);
+
+ // add the file's location to the search path, if it exists
+ File projectDirectory = this.getProjectDirectory();
+ if (projectDirectory != null) {
+ locator.addFilesystemPath(projectDirectory);
+ }
+ }
+
+ /**
+ * Adds the given String as a custom path for filesystem lookups. The path can be
+ * relative or absolute and is <i>not</i> checked for existence. This allows for easy
+ * customization of resource search paths after Constructor invocation:
+ *
+ * <pre>
+ * conf = new FileConfiguration("myconfig-cayenne.xml");
+ * conf.addFilesystemPath(new File("a/relative/path"));
+ * conf.addFilesystemPath(new File("/an/absolute/search/path"));
+ * Configuration.initializeSharedConfiguration(conf);
+ * </pre>
+ *
+ * Alternatively use {@link FileConfiguration#addFilesystemPath(File)} for adding a
+ * path that is checked for existence.
+ *
+ * @throws IllegalArgumentException if <code>path</code> is <code>null</code>.
+ */
+ public void addFilesystemPath(String path) {
+ this.getResourceLocator().addFilesystemPath(path);
+ }
+
+ /**
+ * Adds the given directory as a path for filesystem lookups. The directory is checked
+ * for existence.
+ *
+ * @throws IllegalArgumentException if <code>path</code> is <code>null</code>,
+ * not a directory or not readable.
+ */
+ public void addFilesystemPath(File path) {
+ this.getResourceLocator().addFilesystemPath(path);
+ }
+
+ /**
+ * Only returns <code>true</code> when {@link #getProjectFile} does not return
+ * <code>null</code>.
+ *
+ * @deprecated since 3.0 - superclass method is deprecated.
+ */
+ @Override
public boolean canInitialize() {
- // I can only initialize myself when I have a valid file
- return (this.getProjectFile() != null);
- }
-
- /**
- * Returns the main domain file used for this configuration.
- */
- public File getProjectFile() {
- return projectFile;
- }
-
- /**
- * Sets the main domain file used for this configuration.
- * @throws ConfigurationException if <code>projectFile</code> is null,
- * a directory or not readable.
- */
- protected void setProjectFile(File projectFile) {
- if (projectFile != null) {
- if (projectFile.isFile()) {
- this.projectFile = projectFile;
- this.setDomainConfigurationName(projectFile.getName());
- }
- else {
- throw new ConfigurationException("Project file: "
- + projectFile
- + " is a directory or not readable.");
- }
- }
- else {
- throw new ConfigurationException("Cannot use null as project file.");
- }
- }
-
- /**
- * Returns the directory of the current project file as
- * returned by {@link #getProjectFile}.
- */
- public File getProjectDirectory() {
- File pfile = this.getProjectFile();
- if (pfile != null) {
- return pfile.getParentFile();
- }
- else {
- return null;
- }
- }
+ // TODO: move this to "initialize" once the deprecated method is removed
+ return this.getProjectFile() != null;
+ }
+
+ /**
+ * Returns the main domain file used for this configuration.
+ */
+ public File getProjectFile() {
+ return projectFile;
+ }
+
+ /**
+ * Sets the main domain file used for this configuration.
+ *
+ * @throws ConfigurationException if <code>projectFile</code> is null, a directory
+ * or not readable.
+ */
+ protected void setProjectFile(File projectFile) {
+ if (projectFile != null) {
+ if (projectFile.isFile()) {
+ this.projectFile = projectFile;
+ this.setDomainConfigurationName(projectFile.getName());
+ }
+ else {
+ throw new ConfigurationException("Project file: "
+ + projectFile
+ + " is a directory or not readable.");
+ }
+ }
+ else {
+ throw new ConfigurationException("Cannot use null as project file.");
+ }
+ }
+
+ /**
+ * Returns the directory of the current project file as returned by
+ * {@link #getProjectFile}.
+ */
+ public File getProjectDirectory() {
+ File pfile = this.getProjectFile();
+ if (pfile != null) {
+ return pfile.getParentFile();
+ }
+ else {
+ 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=660018&r1=660017&r2=660018&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 May 25 12:03:08 2008
@@ -74,19 +74,10 @@
}
@Override
- public boolean canInitialize() {
- return true;
- }
-
- @Override
public void initialize() throws Exception {
}
@Override
- public void didInitialize() {
- }
-
- @Override
public ResourceLocator getResourceLocator() {
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=660018&r1=660017&r2=660018&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 May 25 12:03:08 2008
@@ -28,19 +28,6 @@
*/
public class MockConfiguration extends Configuration {
- public MockConfiguration() {
- super();
- }
-
- @Override
- public boolean canInitialize() {
- return true;
- }
-
- @Override
- public void didInitialize() {
- }
-
@Override
protected InputStream getMapConfiguration(String name) {
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=660018&r1=660017&r2=660018&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 May 25 12:03:08 2008
@@ -558,19 +558,10 @@
class LazyConfiguration extends Configuration {
@Override
- public boolean canInitialize() {
- return true;
- }
-
- @Override
public void initialize() throws Exception {
}
@Override
- public void didInitialize() {
- }
-
- @Override
protected ResourceLocator getResourceLocator() {
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=660018&r1=660017&r2=660018&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 May 25 12:03:08 2008
@@ -25,17 +25,6 @@
public class MockConfiguration extends Configuration {
- public MockConfiguration() {
- super();
- }
-
- public boolean canInitialize() {
- return true;
- }
-
- public void didInitialize() {
- }
-
protected InputStream getMapConfiguration(String name) {
return null;
}