org.pietschy.command

Class ReflectionCommand

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(String commandId, Class clazz, String methodName)
Creates a new reflection command that invokess a static no arg method.
ReflectionCommand(String commandId, Class clazz, String methodName, Class[] methodArgs)
Creates a new reflection command that invokes a static class method with arguments.
ReflectionCommand(String commandId, Object instance, String methodName)
Creates a new reflection command that invokes a non static method on the specified object.
ReflectionCommand(String commandId, Object instance, String methodName, Class[] methodArgs)
ReflectionCommand(String commandId, String className, String methodName)
Creates a new reflection command that invokes a static no arg method.

Method Summary

protected 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(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, handleExecute, 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, attach, buttonIterator, configureButtonAppearance, configureButtonAppearances, configureButtonAppearances, configureButtonStates, createButton, createButton, createButton, createButton, createMenuItem, createMenuItem, createMenuItem, createMenuItem, detach, 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

Constructor Details

ReflectionCommand

public ReflectionCommand(String commandId,
                         Class clazz,
                         String methodName)
            throws 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.

ReflectionCommand

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

ReflectionCommand

public ReflectionCommand(String commandId,
                         Object instance,
                         String methodName)
            throws 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.

ReflectionCommand

public ReflectionCommand(String commandId,
                         Object instance,
                         String methodName,
                         Class[] methodArgs)
            throws NoSuchMethodException

ReflectionCommand

public ReflectionCommand(String commandId,
                         String className,
                         String methodName)
            throws NoSuchMethodException,
                   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.

Method Details

getInvocationArgs

protected 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.

handleExecute

protected final void handleExecute()
Overrides:
handleExecute in interface ActionCommand

handleInvocationException

protected void handleInvocationException(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(..)