OpenNMS API 1.2.9

## org.opennms.web.notification.bobject
Class Command

    java.lang.Object
      org.opennms.web.notification.bobject.Command

public class Command
extends java.lang.Object

This is a class to store and execute a console command

Version:
  1.1.1.1
Author:
  Jason Johns , OpenNMS

Field Summary
`private java.util.List` `m_arguments` The map of arguments in the command
`private java.lang.String` `m_commandComments` The comments for the command
`private java.lang.String` `m_commandName` The name of the command
`private java.util.List` `m_types` The types of the command, useful for supporting classes to do things based on what this command is for.
`private boolean` `m_useStream` A boolean that indicates if this command requires data passed to it from an input stream.

Constructor Summary
`Command()` Default constructor, intializes the members

Method Summary
`void` `addArgument(Argument anArgument)` Adds a argument to the list of arguments
`void` `addType(java.lang.String aType)` Adds an identifier type for command
`Command` `copy()` Creates a new Command objects with identical values to the current Command object.
`static java.lang.String[]` `createCommandArray(java.lang.String s, char delim)` Convenience method for creating arrays of strings suitable for use as command-line parameters when executing an external process.
`int` `execute()` This method executes the command using a Process.
`java.util.List` `getArguments()` Returns the list of arguments
`java.util.List` `getArgumentSwitches()` This method gets the list of switches that Notify knows about that will map to a given console command.
`java.lang.String` `getCommandComments()` Returns the comments for the command
`java.lang.String` `getCommandName()` Returns the command name
`java.lang.String` `getType()` Returns the first type in the list as a string
`boolean` `hasSwitch(java.lang.String aSwitch)` This method determines if this command has a given switch as a member of its arguments
`boolean` `isOfType(java.lang.String aType)` Returns the notification type of the command
`void` `setArgumentValue(java.lang.String aSwitch, java.lang.String aValue)` This method sets an argument specified by the switch param to the given value param
`void` `setCommandComments(java.lang.String someComments)` Sets the comments for the command
`void` `setCommandName(java.lang.String aName)` Sets the command name
`void` `setUseStream(boolean aBool)` This method sets the boolean that indicates if this command requires an input stream.
`java.lang.String` `toString()` Returns a String representation of the command as it would look to execute on the console.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

Field Detail

### m_commandName

    private java.lang.String m_commandName

  The name of the command

### m_types

    private java.util.List m_types

  The types of the command, useful for supporting classes to do things based on what this command is for. Basically an identifying name.

### m_commandComments

    private java.lang.String m_commandComments

  The comments for the command

### m_arguments

    private java.util.List m_arguments

  The map of arguments in the command

### m_useStream

    private boolean m_useStream

  A boolean that indicates if this command requires data passed to it from an input stream.

Constructor Detail

### Command

    public Command()

  Default constructor, intializes the members

Method Detail

### copy

    public Command copy()

  Creates a new Command objects with identical values to the current Command object.

  Returns:
    a copy of this command

### setCommandName

    public void setCommandName(java.lang.String aName)

  Sets the command name

  Parameters:
    `aName` - the name of the command

### getCommandName

    public java.lang.String getCommandName()

  Returns the command name

  Returns:
    the name of the command

### addType

    public void addType(java.lang.String aType)

  Adds an identifier type for command

  Parameters:
    `aType` - the notification type

### isOfType

    public boolean isOfType(java.lang.String aType)

  Returns the notification type of the command

  Returns:
    true if contains the type

### getType

    public java.lang.String getType()

  Returns the first type in the list as a string

  Returns:
    the type

### setCommandComments

    public void setCommandComments(java.lang.String someComments)

  Sets the comments for the command

  Parameters:
    `someComments` - the comments for the command

### getCommandComments

    public java.lang.String getCommandComments()

  Returns the comments for the command

  Returns:
    the comments for the command

### addArgument

    public void addArgument(Argument anArgument)

  Adds a argument to the list of arguments

  Parameters:
    `anArgument` - the argument to be added.

### setUseStream

    public void setUseStream(boolean aBool)

  This method sets the boolean that indicates if this command requires an input stream.

  Parameters:
    `aBool` - true if a stream should be used, false otherwise

### getArguments

    public java.util.List getArguments()

  Returns the list of arguments

  Returns:
    the list of arguments

### setArgumentValue

    public void setArgumentValue(java.lang.String aSwitch,
                                 java.lang.String aValue)

  This method sets an argument specified by the switch param to the given value param

  Parameters:
    `aSwitch` - the argument to set
    `aValue` - the value to set

### hasSwitch

    public boolean hasSwitch(java.lang.String aSwitch)

  This method determines if this command has a given switch as a member of its arguments

  Parameters:
    `aSwitch` - the switch to check for
  Returns:
    true if the command has the switch, false otherwise

### getArgumentSwitches

    public java.util.List getArgumentSwitches()

  This method gets the list of switches that Notify knows about that will map to a given console command.

  Returns:
    a list of parameter switches

### execute

    public int execute()

  This method executes the command using a Process. The method will decide if an input stream needs to be used.

  Returns:
    the return code of the command

### toString

    public java.lang.String toString()

  Returns a String representation of the command as it would look to execute on the console.

  Returns:
    a string representation

### createCommandArray

    public static java.lang.String[] createCommandArray(java.lang.String s,
                                                        char delim)

  Convenience method for creating arrays of strings suitable for use as command-line parameters when executing an external process.

  The default `Runtime.exec(java.lang.String[])`method will split a single string based on spaces, but it does not respect spaces within quotation marks, and it will leave the quotation marks in the resulting substrings. This method solves those problems by replacing all in-quote spaces with the given delimiter, removes the quotes, and then splits the resulting string by the remaining out-of-quote spaces. It then goes through each substring and replaces the delimiters with spaces.

  Caveat: This method does not respect escaped quotes! It will simply remove them and leave the stray escape characters.

  Parameters:
    `s` - the string to split
    `delim` - a char that does not already exist in `s`
  Returns:
    An array of strings split by spaces outside of quotes.
  Throws:
    `java.lang.IllegalArgumentException` - If `s` is null or if `delim` already exists in `s`.

OpenNMS API 1.2.9

Generated by ranger on May 19 2007 2335.