org.owasp.esapi.util
Class ObjFactory

java.lang.Object
  extended by org.owasp.esapi.util.ObjFactory

public class ObjFactory
extends java.lang.Object

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

Author:
[email protected], Chris Schmidt ( chrisisbeef .at. gmail.com )

Method Summary
static
<T> T
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

make

public static <T> T make(java.lang.String className,
                         java.lang.String typeName)
              throws ConfigurationException
Create an object based on the className parameter.

Parameters:
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.
Returns:
An object of type className, which is cast to type T.
Throws:
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.


Copyright © 2011 The Open Web Application Security Project (OWASP). All Rights Reserved.