|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.xorm.util.AppConfigFactory
Base class for deriving custom AppConfig factories. This object provides the core support for loading AppConfig objects from well-known set places. All you have to do when subclassing this object is to pass in the appropriate settings in the constructor. The rest is handled by this object.
For example, here is the code for a singleton implementation:
package com.myapp; import org.xorm.util.AppConfigFactory; public final class MyConfigFactory extends AppConfigFactory { private static MyConfigFactory singleton; static { singleton = new MyConfigFactory(); } public static MyConfigFactory getInstance() { return singleton; } private MyConfigFactory() { super("myapp/config", "com.myapp.configFile", "/myapp.properties"); } }
The example above would look for application configuration in the following places:
"myapp/config"
JNDI resource, which you
could set up under your servlet engine (i.e. Tomcat) or webapp
configuration. If you choose to configure your application via JNDI,
you should make sure the resource points to an AppConfig object.
"com.myapp.configFile"
system property,
which would specify the resource or file where the application properties
live.
"/myapp.properties"
which can live either on the classpath
or on the file system. Generally you are encouraged to build a default
property file into your application's JAR or class files...in the case
above named myapp.properties.
Then, in your application code, whenever you need to access properties or get a PersistenceManager instance, simply do this:
package com.myapp; import javax.jdo.PersistenceManager; import org.xorm.util.AppConfig; public class Example { public void main(String[] args) { AppConfig appConfig = MyAppConfigFactory.getInstance().getAppConfig(); PersistenceManager mgr = appConfig.getPersistenceManager(); String prop = appConfig.getProperty("someProperty"); } }
AppConfig
Field Summary | |
protected Class |
appConfigClass
|
protected AppConfig |
config
|
protected String |
configFileSystemProperty
|
protected String |
defaultConfigFile
|
protected String |
jndiConfigResource
|
protected Logger |
logger
|
Constructor Summary | |
protected |
AppConfigFactory(String jndiConfigResource,
String configFileSystemProperty,
String defaultConfigFile)
Constructor |
protected |
AppConfigFactory(String jndiConfigResource,
String configFileSystemProperty,
String defaultConfigFile,
Class appConfigClass)
|
Method Summary | |
AppConfig |
getAppConfig()
Get the AppConfig associated with this factory. |
protected AppConfig |
loadAppConfig()
Load the AppConfig from the specified locations. |
protected AppConfig |
loadAppConfigFromJNDI()
Load the AppConfig as a JNDI resource |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected String jndiConfigResource
protected String configFileSystemProperty
protected String defaultConfigFile
protected Class appConfigClass
protected Logger logger
protected AppConfig config
Constructor Detail |
protected AppConfigFactory(String jndiConfigResource, String configFileSystemProperty, String defaultConfigFile)
jndiConfigResource
- the resource path (under "jndi:comp/env")
where the first attempt to load the configuration should lookconfigFileSystemProperty
- the name of a system property that
may have been defined as a second-level fallback, pointing to a file
or resource where the configuration should be loadeddefaultConfigFile
- the path of a file or resource where the
last ditch attempt to find the configuration will lookprotected AppConfigFactory(String jndiConfigResource, String configFileSystemProperty, String defaultConfigFile, Class appConfigClass)
Method Detail |
public AppConfig getAppConfig()
AppConfig
protected AppConfig loadAppConfig()
protected AppConfig loadAppConfigFromJNDI()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |