|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.owasp.esapi.util.ObjFactory
public class ObjFactory
A generic object factory to create an object of class T. T must be a concrete class that has a no-argument public constructor or a implementor of the Singleton pattern that has a no-arg static getInstance method. If the class being created has a getInstance method, it will be used as a singleton and newInstance() will never be called on the class no matter how many times it comes through this factory.
Typical use is something like:
import com.example.interfaces.DrinkingEstablishment; import com.example.interfaces.Beer; ... // Typically these would be populated from some Java properties file String barName = "com.example.foo.Bar"; String beerBrand = "com.example.brewery.Guiness"; ... DrinkingEstablishment bar = ObjFactory.make(barName, "DrinkingEstablishment"); Beer beer = ObjFactory.make(beerBrand, "Beer"); bar.drink(beer); // Drink a Guiness beer at the foo Bar. :) ...
Copyright (c) 2009 - The OWASP Foundation
Method Summary | ||
---|---|---|
static
|
make(java.lang.String className,
java.lang.String typeName)
Create an object based on the className parameter. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static <T> T make(java.lang.String className, java.lang.String typeName) throws ConfigurationException
className
parameter.
className
- The name of the class to construct. Should be a fully qualified name and
generally the same as type T
typeName
- A type name used in error messages / exceptions.
className
, which is cast to type T
.
ConfigurationException
- thrown if class name not found in class path, or does not
have a public, no-argument constructor, or is not a concrete class, or if it is
not a sub-type of T
(or T
itself). Usually this is
caused by a misconfiguration of the class names specified in the ESAPI.properties
file. Also thrown if the CTOR of the specified className
throws
an Exception
of some type.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |