wyvern.util
Class NullObjectFactory

java.lang.Object
  extended bywyvern.util.NullObjectFactory

public final class NullObjectFactory
extends java.lang.Object

A factory that can produce a dummy implementation of an interface, on the fly. Probably not a good idea for you to use it.

Version:
1.0, Oct 27, 2003
Author:
Steve Yegge

Nested Class Summary
static class NullObjectFactory.NullInvocationHandler
          Routes all interface calls to null (returns empty strings and other zero-values for methods with return types).
 
Method Summary
static java.lang.Object create(java.lang.Class ifc)
          Creates a NullObject implementing the passed interface.
static java.lang.Object create(java.lang.Class ifc, java.lang.reflect.InvocationHandler handler)
          Creates a NullObject implementing the passed interface, with methods handled by the passed InvocationHandler.
static void main(java.lang.String[] args)
          Tests it.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

create

public static java.lang.Object create(java.lang.Class ifc)
Creates a NullObject implementing the passed interface. For example, to create a null Monster object, pass in Monster.class.

Parameters:
ifc - an interface to create a proxy for
Returns:
a proxy object
Throws:
java.lang.IllegalArgumentException - if interface is null

create

public static java.lang.Object create(java.lang.Class ifc,
                                      java.lang.reflect.InvocationHandler handler)
Creates a NullObject implementing the passed interface, with methods handled by the passed InvocationHandler. You can override NullObjectFactory.NullInvocationHandler to handle specific methods on your proxy object, while delegating the rest of them to the superclass.

Parameters:
ifc - an interface to create a proxy for
handler - an InvocationHandler that will handle all the methods called on the proxy.
Returns:
a proxy object
Throws:
java.lang.IllegalArgumentException - if interface or handler is null

main

public static void main(java.lang.String[] args)
                 throws java.lang.Exception
Tests it.

Throws:
java.lang.Exception