FileDocCategorySizeDatePackage
CommandProxy.javaAPI DocExample3164Sat Jan 24 10:44:30 GMT 2004je3.reflect

CommandProxy

public class CommandProxy extends Object implements InvocationHandler
This class is an InvocationHandler based on a Map of method names to Command objects. When the invoke() method is called, the name of the method to be invoked is looked up in the map, and the associated Command, if any is invoked. Arguments passed to invoke() are always ignored. Note that there is no public constructor for this class. Instead, there is a static factory method for creating Proxy objects that use an instance of this class. Pass the interface to be implemented and a Map of name/Command pairs.

Fields Summary
Map
methodMap
Constructors Summary
private CommandProxy(Map methodMap)

 this.methodMap = methodMap; 
Methods Summary
public static java.lang.Objectcreate(java.lang.Class iface, java.util.Map methodMap)

	InvocationHandler handler = new CommandProxy(methodMap);
	ClassLoader loader = handler.getClass().getClassLoader();
	return Proxy.newProxyInstance(loader, new Class[] { iface }, handler);
    
public java.lang.Objectinvoke(java.lang.Object p, java.lang.reflect.Method m, java.lang.Object[] args)

	String methodName = m.getName();
	Command command = (Command) methodMap.get(methodName);
	if (command != null) command.invoke();
	return null;