Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

org.objectstyle.cayenne.conf
Class Configuration  view Configuration download Configuration.java

java.lang.Object
  extended byorg.objectstyle.cayenne.conf.Configuration
Direct Known Subclasses:
DefaultConfiguration

public abstract class Configuration
extends java.lang.Object

This class is an entry point to Cayenne. It loads all configuration files and instantiates main Cayenne objects. Used as a singleton via the getSharedConfiguration() 55 method.

To use a custom subclass of Configuration, Java applications must call initializeSharedConfiguration() 55 with the subclass as argument. This will create and initialize a Configuration singleton instance of the specified class. By default DefaultConfiguration is instantiated.


Nested Class Summary
private  class Configuration.ConfigurationShutdownHook
           
 
Field Summary
protected  Configuration.ConfigurationShutdownHook configurationShutdownHook
           
protected  org.objectstyle.cayenne.util.CayenneMap dataDomains
          Lookup map that stores DataDomains with names as keys.
protected  java.util.Collection dataDomainsRef
           
static java.lang.Class DEFAULT_CONFIGURATION_CLASS
           
static java.lang.String DEFAULT_DOMAIN_FILE
           
static java.lang.String DEFAULT_LOGGING_PROPS_FILE
           
protected  java.lang.String domainConfigurationName
           
protected  boolean ignoringLoadFailures
           
protected  ConfigStatus loadStatus
           
private static boolean loggingConfigured
           
private static org.apache.log4j.Logger logObj
           
protected  DataSourceFactory overrideFactory
           
protected static java.lang.ClassLoader resourceLoader
          Defines a ClassLoader to use for resource lookup.
protected static Configuration sharedConfiguration
           
 
Constructor Summary
protected Configuration()
          Default constructor for new Configuration instances.
protected Configuration(java.lang.String domainConfigurationName)
          Default constructor for new Configuration instances using the given resource name as the main domain file.
 
Method Summary
 void addDomain(org.objectstyle.cayenne.access.DataDomain domain)
          Adds new DataDomain to the list of registered domains.
static void bootstrapSharedConfiguration(java.lang.Class cl)
          Sets cl class's ClassLoader to serve as shared configuration resource ClassLoader.
abstract  boolean canInitialize()
          Indicates whether initialize() 55 can be called.
static void configureCommonLogging()
          Configures Cayenne logging properties.
static void configureCommonLogging(java.net.URL propsFile)
          Configures Cayenne logging properties using properties found at the specified URL.
protected  void configureLogging()
          Configures log4J.
abstract  void didInitialize()
          Called after successful completion of initialize() 55 .
 DataSourceFactory getDataSourceFactory()
          Returns an internal property for the DataSource factory that will override any settings configured in XML.
 org.objectstyle.cayenne.access.DataDomain getDomain()
          Returns default domain of this configuration.
 org.objectstyle.cayenne.access.DataDomain getDomain(java.lang.String name)
          Returns registered domain matching name or null if no such domain is found.
protected abstract  java.io.InputStream getDomainConfiguration()
          Returns a DataDomain as a stream or null if it cannot be found.
 java.lang.String getDomainConfigurationName()
          Returns the name of the main domain configuration resource.
 java.util.Collection getDomains()
          Returns an unmodifiable collection of registered org.objectstyle.cayenne.access.DataDomain objects.
 ConfigLoaderDelegate getLoaderDelegate()
          Returns a delegate used for controlling the loading of configuration elements.
 ConfigStatus getLoadStatus()
          Returns the load status.
static org.apache.log4j.Level getLoggingLevel()
          Returns default log level for loading configuration.
protected abstract  java.io.InputStream getMapConfiguration(java.lang.String name)
          Returns a DataMap with the given name or null if it cannot be found.
static java.lang.ClassLoader getResourceLoader()
          Returns the ClassLoader used to load resources.
protected abstract  org.objectstyle.cayenne.util.ResourceLocator getResourceLocator()
          Returns the resource locator used for finding and loading resources.
static Configuration getSharedConfiguration()
          Use this method as an entry point to all Cayenne access objects.
abstract  void initialize()
          Initializes the new instance.
static void initializeSharedConfiguration()
          Creates and initializes shared Configuration object.
static void initializeSharedConfiguration(java.lang.Class configurationClass)
          Creates and initializes a shared Configuration object of a custom Configuration subclass.
static void initializeSharedConfiguration(Configuration conf)
          Sets the shared Configuration object to a new Configuration object.
 void installConfigurationShutdownHook()
           
 boolean isIgnoringLoadFailures()
          Returns whether to ignore any failures during map loading or not.
static boolean isLoggingConfigured()
          Indicates whether Log4j has been initialized, either by cayenne or otherwise.
 void removeDomain(java.lang.String name)
          Unregisters DataDomain matching name from this Configuration object.
 void setDataSourceFactory(DataSourceFactory overrideFactory)
           
protected  void setDomainConfigurationName(java.lang.String domainConfigurationName)
          Sets the name of the main domain configuration resource.
protected  void setIgnoringLoadFailures(boolean ignoringLoadFailures)
          Sets whether to ignore any failures during map loading or not.
protected  void setLoadStatus(ConfigStatus status)
          Sets the load status.
static void setLoggingConfigured(boolean state)
          Indicate whether Log4j has been initialized.
static void setLoggingLevel(org.apache.log4j.Level logLevel)
          Sets the default log level for loading a configuration.
 void shutdown()
          Shutdowns all owned domains.
 void uninstallConfigurationShutdownHook()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logObj

private static org.apache.log4j.Logger logObj

DEFAULT_LOGGING_PROPS_FILE

public static final java.lang.String DEFAULT_LOGGING_PROPS_FILE
See Also:
Constant Field Values

DEFAULT_DOMAIN_FILE

public static final java.lang.String DEFAULT_DOMAIN_FILE
See Also:
Constant Field Values

DEFAULT_CONFIGURATION_CLASS

public static final java.lang.Class DEFAULT_CONFIGURATION_CLASS

sharedConfiguration

protected static Configuration sharedConfiguration

loggingConfigured

private static boolean loggingConfigured

resourceLoader

protected static java.lang.ClassLoader resourceLoader
Defines a ClassLoader to use for resource lookup. Configuration objects that are using ClassLoaders to locate resources may need to be bootstrapped explicitly.


dataDomains

protected org.objectstyle.cayenne.util.CayenneMap dataDomains
Lookup map that stores DataDomains with names as keys.


dataDomainsRef

protected java.util.Collection dataDomainsRef

overrideFactory

protected DataSourceFactory overrideFactory

loadStatus

protected ConfigStatus loadStatus

domainConfigurationName

protected java.lang.String domainConfigurationName

ignoringLoadFailures

protected boolean ignoringLoadFailures

configurationShutdownHook

protected Configuration.ConfigurationShutdownHook configurationShutdownHook
Constructor Detail

Configuration

protected Configuration()
Default constructor for new Configuration instances. Simply calls Configuration(String) 55 .


Configuration

protected Configuration(java.lang.String domainConfigurationName)
Default constructor for new Configuration instances using the given resource name as the main domain file. First calls configureLogging() 55 , then setDomainConfigurationName(java.lang.String) 55 with the given domain configuration resource name.

Method Detail

bootstrapSharedConfiguration

public static void bootstrapSharedConfiguration(java.lang.Class cl)
Sets cl class's ClassLoader to serve as shared configuration resource ClassLoader. If shared Configuration object does not use ClassLoader, this method call will have no effect on how resources are loaded.


configureCommonLogging

public static void configureCommonLogging()
Configures Cayenne logging properties. Search for the properties file called cayenne-log.properties is first done in $HOME/.cayenne, then in CLASSPATH.


configureCommonLogging

public static void configureCommonLogging(java.net.URL propsFile)
Configures Cayenne logging properties using properties found at the specified URL.


isLoggingConfigured

public static boolean isLoggingConfigured()
Indicates whether Log4j has been initialized, either by cayenne or otherwise. If an external setup has been detected, setLoggingConfigured(boolean) 55 will be called to remember this.


setLoggingConfigured

public static void setLoggingConfigured(boolean state)
Indicate whether Log4j has been initialized. Can be used when subclasses customize the initialization process, or to configure Log4J outside of Cayenne.


getSharedConfiguration

public static Configuration getSharedConfiguration()
Use this method as an entry point to all Cayenne access objects.

Note that if you want to provide a custom Configuration, make sure you call one of the initializeSharedConfiguration() 55 methods before your application code has a chance to call this method.


getResourceLoader

public static java.lang.ClassLoader getResourceLoader()
Returns the ClassLoader used to load resources.


getLoggingLevel

public static org.apache.log4j.Level getLoggingLevel()
Returns default log level for loading configuration. Log level is made static so that applications can set it before shared Configuration object is instantiated.


setLoggingLevel

public static void setLoggingLevel(org.apache.log4j.Level logLevel)
Sets the default log level for loading a configuration.


initializeSharedConfiguration

public static void initializeSharedConfiguration()
Creates and initializes shared Configuration object. By default DefaultConfiguration will be instantiated and assigned to a singleton instance of Configuration.


initializeSharedConfiguration

public static void initializeSharedConfiguration(java.lang.Class configurationClass)
Creates and initializes a shared Configuration object of a custom Configuration subclass.


initializeSharedConfiguration

public static void initializeSharedConfiguration(Configuration conf)
Sets the shared Configuration object to a new Configuration object. First calls canInitialize() 55 and - if permitted - initialize() 55 followed by didInitialize() 55 .


canInitialize

public abstract boolean canInitialize()
Indicates whether initialize() 55 can be called. Returning false allows new instances to delay or refuse the initialization process.


initialize

public abstract void initialize()
                         throws java.lang.Exception
Initializes the new instance.


didInitialize

public abstract void didInitialize()
Called after successful completion of initialize() 55 .


getResourceLocator

protected abstract org.objectstyle.cayenne.util.ResourceLocator getResourceLocator()
Returns the resource locator used for finding and loading resources.


getDomainConfiguration

protected abstract java.io.InputStream getDomainConfiguration()
Returns a DataDomain as a stream or null if it cannot be found.


getMapConfiguration

protected abstract java.io.InputStream getMapConfiguration(java.lang.String name)
Returns a DataMap with the given name or null if it cannot be found.


configureLogging

protected void configureLogging()
Configures log4J. This implementation calls configureCommonLogging() 55 .


getDomainConfigurationName

public java.lang.String getDomainConfigurationName()
Returns the name of the main domain configuration resource. Defaults to DEFAULT_DOMAIN_FILE 55 .


setDomainConfigurationName

protected void setDomainConfigurationName(java.lang.String domainConfigurationName)
Sets the name of the main domain configuration resource.


getDataSourceFactory

public DataSourceFactory getDataSourceFactory()
Returns an internal property for the DataSource factory that will override any settings configured in XML. Subclasses may override this method to provide a special factory for DataSource creation that will take precedence over any factories configured in a cayenne project.


setDataSourceFactory

public void setDataSourceFactory(DataSourceFactory overrideFactory)

addDomain

public void addDomain(org.objectstyle.cayenne.access.DataDomain domain)
Adds new DataDomain to the list of registered domains.


getDomain

public org.objectstyle.cayenne.access.DataDomain getDomain(java.lang.String name)
Returns registered domain matching name or null if no such domain is found.


getDomain

public org.objectstyle.cayenne.access.DataDomain getDomain()
Returns default domain of this configuration. If no domains are configured, null is returned. If more than one domain exists in this configuration, a CayenneRuntimeException is thrown, indicating that the domain name must be explicitly specified. In such cases getDomain(String name) 55 must be used instead.


removeDomain

public void removeDomain(java.lang.String name)
Unregisters DataDomain matching name from this Configuration object. Note that any domain database connections remain open, and it is a responsibility of a caller to clean it up.


getDomains

public java.util.Collection getDomains()
Returns an unmodifiable collection of registered org.objectstyle.cayenne.access.DataDomain objects.


isIgnoringLoadFailures

public boolean isIgnoringLoadFailures()
Returns whether to ignore any failures during map loading or not.


setIgnoringLoadFailures

protected void setIgnoringLoadFailures(boolean ignoringLoadFailures)
Sets whether to ignore any failures during map loading or not.


getLoadStatus

public ConfigStatus getLoadStatus()
Returns the load status.


setLoadStatus

protected void setLoadStatus(ConfigStatus status)
Sets the load status.


getLoaderDelegate

public ConfigLoaderDelegate getLoaderDelegate()
Returns a delegate used for controlling the loading of configuration elements. By default a RuntimeLoadDelegate is used.


shutdown

public void shutdown()
Shutdowns all owned domains. Invokes DataDomain.shutdown().


installConfigurationShutdownHook

public void installConfigurationShutdownHook()

uninstallConfigurationShutdownHook

public void uninstallConfigurationShutdownHook()