info.monitorenter.cpdetector.reflect
Class SingletonLoader

java.lang.Object
  extended by info.monitorenter.cpdetector.reflect.SingletonLoader

public final class SingletonLoader
extends Object

A stateless helper that performs dynamic class loading and instantiation with support for invoking Singleton-retrieval methods of classes if detected.

Before invoking someClass.newInstance() the loaded class is inspected for methods, that are public, static, parameterless, contain the substring "intance" in their name (case-insensitive) and return an instance of the same type.

If such a method is found, it is considered to be a singleton retrieval method and will be invoked instead of trying to use the default constructor triggered by newInstance() (which then should be private if it is really a singleton.

This class is in turn a singleton as it only contains procedural code. For possible desireable future configuration requirements, the single public method is not declared static but bound to the singleton instance.

Author:
Achim Westermann

Method Summary
static SingletonLoader getInstance()
           
 Object newInstance(Class c)
          Dynamic instantiation of the given type with singleton retrieval support as described in this class description.
 Object newInstance(String fullyQualifiedClassName)
          High-level method for instantiation of a new instance of the class specified by the given fully qualified class name with singleton retrieval support.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getInstance

public static SingletonLoader getInstance()

newInstance

public Object newInstance(String fullyQualifiedClassName)
                   throws InstantiationException,
                          IllegalAccessException,
                          ClassNotFoundException
High-level method for instantiation of a new instance of the class specified by the given fully qualified class name with singleton retrieval support. Delegates to newInstance(Class).

Throws:
InstantiationException
IllegalAccessException
ClassNotFoundException

newInstance

public Object newInstance(Class c)
                   throws InstantiationException,
                          IllegalAccessException
Dynamic instantiation of the given type with singleton retrieval support as described in this class description.

Throws:
InstantiationException
IllegalAccessException


Copyleft ㊢ 2003-2004 MPL 1.1, All Rights Footloose.