org.pietschy.command
Class ReflectionCommand

java.lang.Object
  extended by org.pietschy.command.Command
      extended by org.pietschy.command.ActionCommand
          extended by org.pietschy.command.ReflectionCommand
All Implemented Interfaces:
ActionCommandExecutor

public class ReflectionCommand
extends ActionCommand

The ReflectionCommand invokes a target method using reflection.

Version:
$Revision: 1.3 $
Author:
andrewp

Field Summary
 
Fields inherited from class org.pietschy.command.ActionCommand
HINT_ACTION_EVENT, HINT_INVOKER, HINT_INVOKER_WINDOW, HINT_MODIFIERS
 
Fields inherited from class org.pietschy.command.Command
internalLog, listenerList, pcs
 
Constructor Summary
ReflectionCommand(java.lang.String commandId, java.lang.Class clazz, java.lang.String methodName)
          Creates a new reflection command that invokess a static no arg method.
ReflectionCommand(java.lang.String commandId, java.lang.Class clazz, java.lang.String methodName, java.lang.Class[] methodArgs)
          Creates a new reflection command that invokes a static class method with arguments.
ReflectionCommand(java.lang.String commandId, java.lang.Object instance, java.lang.String methodName)
          Creates a new reflection command that invokes a non static method on the specified object.
ReflectionCommand(java.lang.String commandId, java.lang.Object instance, java.lang.String methodName, java.lang.Class[] methodArgs)
           
ReflectionCommand(java.lang.String commandId, java.lang.String className, java.lang.String methodName)
          Creates a new reflection command that invokes a static no arg method.
 
Method Summary
protected  java.lang.Object[] getInvocationArgs()
          Gets any arguments required by the delegate.
protected  void handleExecute()
          Main entry point for command subclasses that must be implemented to provide command specific behaviour.
protected  void handleInvocationException(java.lang.Exception e)
          Called to handle any exceptions that occur during the invocation of the delegate method.
 
Methods inherited from class org.pietschy.command.ActionCommand
addCommandListener, addInterceptor, areEqual, attach, configureButtonStates, detach, execute, execute, getActionAdapter, getActionAdapter, getActionCommand, getActionEvent, getHint, getHint, getHints, getInvoker, getInvokerWindow, getModifiers, installShortCut, installShortCut, postExecute, preExecute, putHint, putHints, removeCommandListener, removeInterceptor, requestDefautIn, setActionCommand, uninstallShortCut, uninstallShortCut
 
Methods inherited from class org.pietschy.command.Command
addFace, addHoverListener, addNewFace, addNotify, addPropertyChangeListener, addPropertyChangeListener, buttonIterator, configureButtonAppearance, configureButtonAppearances, configureButtonAppearances, createButton, createButton, createButton, createButton, createMenuItem, createMenuItem, createMenuItem, createMenuItem, export, faceExists, fireHoverEnded, fireHoverStarted, getAccelerator, getAlternativeFaceNames, getButtonFactory, getButtonIn, getCommandManager, getDefaultFace, getDefaultFace, getDescription, getFace, getFace, getIcon, getId, getLongDescription, getMenuFactory, getMnemonic, getMnemonicIndex, getProperty, getProperty, getPropertyNames, getSelectedIcon, getText, getTextPosition, getToolbarFactory, initCommandManager, installFace, isAnonymous, isAttachedTo, isEnabled, isVisible, putProperty, removeHoverListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, requestFocusIn, setAccelerator, setButtonFactory, setDescription, setEnabled, setIcon, setLongDescription, setMenuFactory, setMnemonic, setMnemonicIndex, setSelectedIcon, setText, setTextPosition, setToolbarFactory, setVisible, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.pietschy.command.ActionCommandExecutor
addPropertyChangeListener, addPropertyChangeListener, isEnabled, removePropertyChangeListener, removePropertyChangeListener
 

Constructor Detail

ReflectionCommand

public ReflectionCommand(java.lang.String commandId,
                         java.lang.String className,
                         java.lang.String methodName)
                  throws java.lang.NoSuchMethodException,
                         java.lang.ClassNotFoundException
Creates a new reflection command that invokes a static no arg method. This constructor uses it's own classloader that loaded the target class.

Parameters:
commandId - the id of the command.
className - the class on which the static method resides
methodName - the name of the no arg static method.
Throws:
java.lang.NoSuchMethodException - if the method doesn't exist
java.lang.NullPointerException - if either the instance or methodName is null.
java.lang.ClassNotFoundException

ReflectionCommand

public ReflectionCommand(java.lang.String commandId,
                         java.lang.Class clazz,
                         java.lang.String methodName)
                  throws java.lang.NoSuchMethodException
Creates a new reflection command that invokess a static no arg method.

Parameters:
commandId - the id of the command.
clazz - the class on which the static method resides
methodName - the name of the no arg static method.
Throws:
java.lang.NoSuchMethodException - if the method doesn't exist
java.lang.NullPointerException - if either the instance or methodName is null.

ReflectionCommand

public ReflectionCommand(java.lang.String commandId,
                         java.lang.Class clazz,
                         java.lang.String methodName,
                         java.lang.Class[] methodArgs)
                  throws java.lang.NoSuchMethodException
Creates a new reflection command that invokes a static class method with arguments.

Parameters:
commandId - the id of the command.
clazz - the class on which the static method resides.
methodName - the method name.
methodArgs - the arguments of the method. This may be null if the argument takes no methods. If arguments are specified, the getInvocationArgs() method must be implemented to provide the arguments to the method invocation.
Throws:
java.lang.NoSuchMethodException - if the method doesn't exist
java.lang.NullPointerException - if either the instance or methodName is null.

ReflectionCommand

public ReflectionCommand(java.lang.String commandId,
                         java.lang.Object instance,
                         java.lang.String methodName)
                  throws java.lang.NoSuchMethodException
Creates a new reflection command that invokes a non static method on the specified object.

Parameters:
commandId - the id of the command
instance - that target instance on which the method will be invoked.
methodName - the name of the method to invoke.
Throws:
java.lang.NoSuchMethodException - if the method doesn't exist
java.lang.NullPointerException - if either the instance or methodName is null.

ReflectionCommand

public ReflectionCommand(java.lang.String commandId,
                         java.lang.Object instance,
                         java.lang.String methodName,
                         java.lang.Class[] methodArgs)
                  throws java.lang.NoSuchMethodException
Parameters:
commandId -
instance -
methodName -
methodArgs - the arguments of the method. This may be null if the argument takes no methods. If arguments are specified, the getInvocationArgs() method must be implemented to provide the arguments to the method invocation.
Throws:
java.lang.NoSuchMethodException - if the method doesn't exist
java.lang.NullPointerException - if either the instance or methodName is null.
Method Detail

handleExecute

protected final void handleExecute()
Description copied from class: ActionCommand
Main entry point for command subclasses that must be implemented to provide command specific behaviour.

This method should never be called directly to invoke a comand. All command invocation must be performed using the ActionCommand.execute() and ActionCommand.execute(Map) methods.

Specified by:
handleExecute in class ActionCommand

getInvocationArgs

protected java.lang.Object[] getInvocationArgs()
Gets any arguments required by the delegate. The default implementation returns null, subclass should override as required.

Returns:
the arguments required for the method delegate. Returns null by default.

handleInvocationException

protected void handleInvocationException(java.lang.Exception e)
Called to handle any exceptions that occur during the invocation of the delegate method.

Parameters:
e - the exception that occured while calling method.invoke(..)