Class AppConfigFactory


public class AppConfigFactory
extends Object

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() {

The example above would look for application configuration in the following places:

  1. It looks for a "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.
  2. It looks at the "com.myapp.configFile" system property, which would specify the resource or file where the application properties live.
  3. It falls back on a default resource or file "/" 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 the case above named

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");

Dan Checkoway
See Also:

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)
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 look
configFileSystemProperty - 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 loaded
defaultConfigFile - the path of a file or resource where the last ditch attempt to find the configuration will look


protected AppConfigFactory(String jndiConfigResource,
                           String configFileSystemProperty,
                           String defaultConfigFile,
                           Class appConfigClass)
Method Detail


public AppConfig getAppConfig()
Get the AppConfig associated with this factory. This factory loads a single instance of AppConfig and keeps it around for subsequent calls. Only that one instance is ever created.

the respective AppConfig object
See Also:


protected AppConfig loadAppConfig()
Load the AppConfig from the specified locations. This method will first try to load the config from the specified JNDI resource. Then it will look at the specified system property value, falling back on the default path.

a new instance of a freshly loaded AppConfig


protected AppConfig loadAppConfigFromJNDI()
Load the AppConfig as a JNDI resource

any AppConfig instance configured under the specified resource path, if found; otherwise null

$Header: /cvsroot/xorm/xorm/docs/api/org/xorm/util/AppConfigFactory.html,v 1.2 2004/05/30 08:55:10 wbiggs Exp $