FreeHEP API
Version current

org.freehep.util.commanddispatcher
Class CommandProcessor

java.lang.Object
  extended byjava.util.Observable
      extended byorg.freehep.util.commanddispatcher.CommandProcessor
All Implemented Interfaces:
CommandGroup
Direct Known Subclasses:
Application.ApplicationCommandProcessor, PageManager.PageManagerCommandProcessor, PluginManager.Commands

public class CommandProcessor
extends Observable
implements CommandGroup

A default implementation of CommandGroup. Typically applications provide their own CommandProcessor(s) which extend this base class and which can handle a set of commands. By default CommandProcessor's acceptCommand method uses reflection to search for methods in the subClass which correspond to specific commands, although subclasses could also override the acceptCommand method to implement a different scheme. The default scheme looks for methods of type:

            public void onXXX()
 
to handle the command XXX. Also
            public void enableXXX(CommandState state)
 
to determine if the command is active or not.

Version:
$Id: CommandProcessor.java,v 1.9 2003/05/14 17:53:08 tonyj Exp $
Author:
Tony Johnson (tonyj@slac.stanford.edu)
Source Code:
CommandProcessor.java

Nested Class Summary
protected  class CommandProcessor.BooleanTarget
          Boolean target is an implementation of CommandTarget for command targets which can be swithced on/off.
protected  class CommandProcessor.SimpleTarget
          A SimpleTarget is an implementation of CommandTarget
 
Constructor Summary
CommandProcessor()
           
 
Method Summary
protected  CommandTarget acceptCommand(Class klass, String command)
          Uses reflection to check if the specified class has an "on" or "enable" method for this comamnd.
 CommandTarget acceptCommand(String command)
          The CommandTargetManager calls acceptCommand to find out if this CommandProcessor can respond to the specified command.
protected  void invoke(Method method, Object[] args)
           
protected  void invokeCommand(CommandProcessor.BooleanTarget t, boolean arg)
          Override this method to provide application specific handling for errors generated during command dispatch
protected  void invokeCommand(CommandProcessor.SimpleTarget t)
          Override this method to provide application specific handling for errors generated during command dispatch
protected  void invokeCommand(Method method, Object[] args)
           
protected  void invokeEnable(Method method, Object[] args)
           
 void setChanged()
           
 void setManager(CommandTargetManager m)
           
protected  String translate(String command)
          Translates a command.
 
Methods inherited from class java.util.Observable
addObserver, clearChanged, countObservers, deleteObserver, deleteObservers, hasChanged, notifyObservers, notifyObservers
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.freehep.util.commanddispatcher.CommandGroup
addObserver, deleteObserver
 

Constructor Detail

CommandProcessor

public CommandProcessor()
Method Detail

setChanged

public void setChanged()

setManager

public void setManager(CommandTargetManager m)
Specified by:
setManager in interface CommandGroup

acceptCommand

public CommandTarget acceptCommand(String command)
The CommandTargetManager calls acceptCommand to find out if this CommandProcessor can respond to the specified command. If it can it returns a CommandTarget for the command, otherwise it returns null.

Specified by:
acceptCommand in interface CommandGroup
Parameters:
command - The command to test for

acceptCommand

protected CommandTarget acceptCommand(Class klass,
                                      String command)
Uses reflection to check if the specified class has an "on" or "enable" method for this comamnd.

Parameters:
klass - The class to check
command - The command to test for

invoke

protected void invoke(Method method,
                      Object[] args)
               throws IllegalAccessException,
                      InvocationTargetException
Throws:
IllegalAccessException
InvocationTargetException

invokeCommand

protected void invokeCommand(CommandProcessor.SimpleTarget t)
Override this method to provide application specific handling for errors generated during command dispatch


invokeCommand

protected void invokeCommand(CommandProcessor.BooleanTarget t,
                             boolean arg)
Override this method to provide application specific handling for errors generated during command dispatch


invokeCommand

protected void invokeCommand(Method method,
                             Object[] args)
                      throws IllegalAccessException,
                             InvocationTargetException
Throws:
IllegalAccessException
InvocationTargetException

invokeEnable

protected void invokeEnable(Method method,
                            Object[] args)
                     throws IllegalAccessException,
                            InvocationTargetException
Throws:
IllegalAccessException
InvocationTargetException

translate

protected String translate(String command)
Translates a command. The default implementation removes trailing ..., and any spaces and then uppercases the first character .


FreeHEP API
Version current

Copyright © 2000-2004 FreeHEP, All Rights Reserved.