nl.toolforge.karma.core.cmd
Class CommandContext

java.lang.Object
  extended bynl.toolforge.karma.core.cmd.CommandContext
All Implemented Interfaces:
nl.toolforge.core.util.listener.ChangeListener

public final class CommandContext
extends java.lang.Object
implements nl.toolforge.core.util.listener.ChangeListener

The command context is the class that provides a runtime for commands to run in. The command context maintains access to the current manifest and all commands that are valid. A CommandContext must be initialized through its init(nl.toolforge.karma.core.cmd.CommandResponseHandler, boolean) method so it can initialize all resources it requires to properly run commands. The init method can only be run once.

Version:
$Id: CommandContext.java,v 1.83 2004/11/16 22:31:57 asmedes Exp $
Author:
D.A. Smedes

Constructor Summary
CommandContext(WorkingContext workingContext)
          Constructs a CommandContext, in which commands are run.
 
Method Summary
 void changeCurrentManifest(Manifest newManifest)
          Changes the current manifest for this context.
 void changeCurrentManifest(java.lang.String manifestName)
          Changes the current manifest for this context.
 void execute(Command command)
          Exceutes command.
 void execute(java.lang.String commandLine)
          Executes a command.
 java.util.Collection getAllManifests()
          Gets all manifests.
 Manifest getCurrentManifest()
          Gets the currently active manifest.
 java.io.File getLocalPath(Module module)
          Some module-types (e.g.
 WorkingContext getWorkingContext()
           
 void init(CommandResponseHandler handler, boolean updateStores)
          Initializes the context to run commands.
 boolean isManifestLoaded()
          Checks if a manifest is active for this context.
 void process()
          Implementation of the ChangeListener interface.
(package private)  void register()
          Registers this CommandContext for automatic manifest file update changes.
 void setWorkingContext(WorkingContext workingContext)
          Sets the workingContext for this command context.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CommandContext

public CommandContext(WorkingContext workingContext)
Constructs a CommandContext, in which commands are run.

Method Detail

getWorkingContext

public WorkingContext getWorkingContext()

init

public void init(CommandResponseHandler handler,
                 boolean updateStores)
          throws CommandException
Initializes the context to run commands. This method should only be called once on a CommandContext.

Parameters:
handler - The CommandResponseHandler object that will be passed to all commands run through this context.
updateStores - If this paramter is true, the CommandContext will update the local manifest and location store with the latest manifests and locations.
Throws:
CommandException

process

public void process()
Implementation of the ChangeListener interface. This method reloads the current manifest to allow changes to be reflected without having to restart Karma.

Specified by:
process in interface nl.toolforge.core.util.listener.ChangeListener

getCurrentManifest

public Manifest getCurrentManifest()
Gets the currently active manifest.

Returns:
The currently active manifest, or null when no manifest is current.

changeCurrentManifest

public void changeCurrentManifest(java.lang.String manifestName)
                           throws ManifestException,
                                  LocationException
Changes the current manifest for this context. This method loads the manifest with the manifestName name.

Parameters:
manifestName -
Throws:
ManifestException - When the manifest could not be changed. See ManifestException.MANIFEST_LOAD_ERROR.
LocationException

changeCurrentManifest

public void changeCurrentManifest(Manifest newManifest)
Changes the current manifest for this context. This method assumes a loaded manifest.

Parameters:
newManifest -

register

void register()
Registers this CommandContext for automatic manifest file update changes.


getAllManifests

public java.util.Collection getAllManifests()
Gets all manifests.

Returns:
See ManifestLoader.getAllManifests().

execute

public void execute(java.lang.String commandLine)
             throws CommandException

Executes a command. Interface applications should use this method to actually execute a command. When a KarmaException is thrown an interface applications should *** NOT *** quit program execution as a result of this exception. It should be handled nicely.

Parameters:
commandLine - The command to execute. A full command line is passed as a parameter.
Throws:
CommandException - A whole lot. Interface applications should *** NOT *** quit program execution as a result of this exception. It should be handled nicely.

execute

public void execute(Command command)
             throws CommandException
Exceutes command.

Parameters:
command - The command to execute.
Throws:
CommandException

isManifestLoaded

public boolean isManifestLoaded()
Checks if a manifest is active for this context.

Returns:
true if a manifest is active for the context, or false if no manifest is active.

getLocalPath

public java.io.File getLocalPath(Module module)

Some module-types (e.g. source modules) have a physical location on disk where the module can be located. This method returns a valid reference to that location. When the module-root is located at /home/jensen/dev/modules/CORE-conversion, getLocalPath() will return a File handle to that directory.

Parameters:
module - The module for which the local path should be retrieved.
Returns:
A File handle to the module directory on a local disk. todo consider moving it to Module.

setWorkingContext

public void setWorkingContext(WorkingContext workingContext)
Sets the workingContext for this command context.

Parameters:
workingContext -


Copyright © 2002-2004 Toolforge. All Rights Reserved.