|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.pietschy.command.Command
com.pietschy.command.ActionCommand
com.pietschy.command.reflection.ReflectionCommand
public class ReflectionCommand
An ActionCommand that invokes a method on a target object using reflection.
As an alternative you can also consider using the @ActionCommand
and @SwingWorkerCommand annotations in
conjuction with GuiCommands.bindAnnotatedCommands(CommandContainer, Object) to achive
a similar outcome.
| Field Summary |
|---|
| Fields inherited from class com.pietschy.command.ActionCommand |
|---|
PARAMETER_ACTION_EVENT, PARAMETER_INVOKER, PARAMETER_INVOKER_WINDOW, PARAMETER_MODIFIERS |
| Fields inherited from class com.pietschy.command.Command |
|---|
internalLog, PROPERTY_ENABLED, PROPERTY_VISIBLE |
| Constructor Summary | |
|---|---|
ReflectionCommand(java.lang.String id,
java.lang.Class clazz,
java.lang.String methodName,
java.lang.Class... methodArgs)
Creates a new instance that invokes a static class method. |
|
ReflectionCommand(java.lang.String id,
java.lang.Object target,
java.lang.reflect.Method method)
Creates a new instance that invokes the specified method on the specified target object. |
|
ReflectionCommand(java.lang.String id,
java.lang.Object target,
java.lang.reflect.Method method,
ArgumentProvider argumentProvider)
Creates a new instance that invokes the specified method on the specified target object. |
|
ReflectionCommand(java.lang.String id,
java.lang.Object target,
java.lang.String methodName,
java.lang.Class... methodArgs)
Creates a new reflection command that invokes a specified method on the specified target. |
|
ReflectionCommand(java.lang.String id,
java.lang.String className,
java.lang.String methodName,
java.lang.Class... methodArgs)
Creates a new reflection command that invokes a static method. |
|
| Method Summary | |
|---|---|
ArgumentProvider |
getArgumentProvider()
Sets the current ArgumentProvider for this command. |
ExceptionHandler |
getExceptionHandler()
Gets the current exception handler for this command. |
protected java.lang.Object[] |
getInvocationArgs()
Gets any arguments required by the delegate. |
java.lang.reflect.Method |
getMethod()
Gets the method this command will invoke. |
java.lang.Object |
getTarget()
Gets the object instance that will recieve the method call. |
protected void |
handleExecute()
Invokes the commands method using reflection. |
protected void |
handleInvocationException(java.lang.Exception e)
Called to handle any exceptions that occur during the invocation of the delegate method. |
void |
setArgumentProvider(ArgumentProvider argumentProvider)
Sets the current ArgumentProvider for this command. |
void |
setExceptionHandler(ExceptionHandler exceptionHandler)
Sets the current exception handler for this command. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Methods inherited from interface com.pietschy.command.ActionCommandExecutor |
|---|
addPropertyChangeListener, addPropertyChangeListener, isEnabled, removePropertyChangeListener, removePropertyChangeListener |
| Methods inherited from interface com.pietschy.command.Identifiable |
|---|
getId |
| Constructor Detail |
|---|
public ReflectionCommand(java.lang.String id,
java.lang.Object target,
java.lang.String methodName,
java.lang.Class... methodArgs)
throws java.lang.NoSuchMethodException
id - the command id.target - the target object.methodName - the method on the target.methodArgs - the arguments of the method. This is a var-args parameter that my be empty if the
method takes no arguments. If arguments are specified an ArgumentProvider
must be specified using setArgumentProvider(ArgumentProvider).
java.lang.NoSuchMethodException - if the method doesn't exist
java.lang.NullPointerException - if either the instance or methodName is null.setArgumentProvider(ArgumentProvider)
public ReflectionCommand(java.lang.String id,
java.lang.String className,
java.lang.String methodName,
java.lang.Class... methodArgs)
throws java.lang.NoSuchMethodException,
java.lang.ClassNotFoundException
Defaults.getClassLoader() is used to load the class.
id - the id of the command.className - the class on which the static method residesmethodName - the name of the no arg static method.methodArgs - the arguments of the method. This is a var-args parameter that my be empty if the
method takes no arguments. If arguments are specified an ArgumentProvider
must be specified using setArgumentProvider(ArgumentProvider).
java.lang.NoSuchMethodException - if the method doesn't exist
java.lang.NullPointerException - if either the instance or methodName is null.
java.lang.ClassNotFoundException
public ReflectionCommand(java.lang.String id,
java.lang.Class clazz,
java.lang.String methodName,
java.lang.Class... methodArgs)
throws java.lang.NoSuchMethodException
id - 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 is a var-args parameter that my be empty if the
method takes no arguments. If arguments are specified an ArgumentProvider
must be specified using setArgumentProvider(ArgumentProvider).
java.lang.NoSuchMethodException - if the method doesn't exist
java.lang.NullPointerException - if either the instance or methodName is null.
public ReflectionCommand(java.lang.String id,
java.lang.Object target,
java.lang.reflect.Method method)
id - the command id.target - the target object.method - the target method.
public ReflectionCommand(java.lang.String id,
java.lang.Object target,
java.lang.reflect.Method method,
ArgumentProvider argumentProvider)
ArgumentProvider is used to generate the arguments for the
method call.
id - the command id.target - the target object.method - the target method.| Method Detail |
|---|
protected final void handleExecute()
handleExecute in class ActionCommandprotected java.lang.Object[] getInvocationArgs()
ArgumentProvider. The method will return null if the
provider is null.
setArgumentProvider(ArgumentProvider)protected void handleInvocationException(java.lang.Exception e)
ExceptionHandler. If
the handler is null a RuntimeException is thrown.
e - the exception that occured while calling method.invoke(..)setExceptionHandler(ExceptionHandler)public java.lang.reflect.Method getMethod()
public java.lang.Object getTarget()
null for static methods.
public ArgumentProvider getArgumentProvider()
ArgumentProvider for this command. May be null
if no arguments are used.
ArgumentProvider for this command, or null if
none has been specified.public void setArgumentProvider(ArgumentProvider argumentProvider)
ArgumentProvider for this command.
argumentProvider - the ArgumentProvider to use to obtain the arguments for
the method invocation.public ExceptionHandler getExceptionHandler()
public void setExceptionHandler(ExceptionHandler exceptionHandler)
exceptionHandler - the exception handler for this command.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||