org.yajul.util
Class ObjectFactory

java.lang.Object
  extended by org.yajul.util.ObjectFactory

public class ObjectFactory
extends java.lang.Object

Provides utility methods for instantiating objects with dynamic, or 'soft' linkages. This is particularly useful for instantiating abstract singletons, or replacing 'hard' dependencies (often circular) with soft linkages that are resolved at run-time.
User: josh Date: Oct 21, 2003 Time: 8:23:12 AM


Constructor Summary
ObjectFactory()
           
 
Method Summary
static java.lang.Object createInstanceFromProperties(java.util.Properties properties, java.lang.String propertyName, java.lang.String defaultClassName, boolean propertyRequired)
          Creates an instance from the specified set of properties If the class implements Initializeable, it will be initialized.
static java.lang.Object createInstanceFromPropertiesResource(java.lang.String resourceName, java.lang.String propertyName, java.lang.String defaultClassName, boolean resourceAndPropertyRequired)
          Creates an instance from the specified property in the specified properties-file resource, which will be loaded from the current thread's class loader.
static java.lang.String getClasspathRoot(java.lang.Class c)
          Returns the base part of the classpath where the specified class can be found.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ObjectFactory

public ObjectFactory()
Method Detail

createInstanceFromPropertiesResource

public static java.lang.Object createInstanceFromPropertiesResource(java.lang.String resourceName,
                                                                    java.lang.String propertyName,
                                                                    java.lang.String defaultClassName,
                                                                    boolean resourceAndPropertyRequired)
                                                             throws InitializationException,
                                                                    java.io.IOException
Creates an instance from the specified property in the specified properties-file resource, which will be loaded from the current thread's class loader. If the class implements Initializeable, it will be initialized.

Parameters:
resourceName - The name of the resource to load.
propertyName - The name of the property to look for in the resource.
defaultClassName - The default class name to use, if the resource was not found.
resourceAndPropertyRequired - Set to true if the resource and property name are required.
Returns:
Object - The new instance.
Throws:
InitializationException - if the resource could not be loaded.
java.io.IOException - if the properties resource could not be read

createInstanceFromProperties

public static java.lang.Object createInstanceFromProperties(java.util.Properties properties,
                                                            java.lang.String propertyName,
                                                            java.lang.String defaultClassName,
                                                            boolean propertyRequired)
                                                     throws InitializationException
Creates an instance from the specified set of properties If the class implements Initializeable, it will be initialized.

Parameters:
properties - The properties to use.
propertyName - The name of the property to look for.
defaultClassName - The default class name to use, if the property was not found.
propertyRequired - Set to true if the property name is required.
Returns:
Object - The new instance.
Throws:
InitializationException - if the resource could not be loaded.

getClasspathRoot

public static java.lang.String getClasspathRoot(java.lang.Class c)
Returns the base part of the classpath where the specified class can be found.

Parameters:
c - The class to look up.
Returns:
the base part of the classpath where the class was found.


Copyright © 2008. All Rights Reserved.