|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.zion.jbuddy.bots.BotActionTask
public abstract class BotActionTask
An external task that can be called from bot actions.
To use a BotActionTask
, an implementation class must be created
that extends this class. The class can then be referenced using actions in a
Bot Definition File. Alternatively, a BotAction
can be created, of
type JAVA
, and having a path set to the
implementation's fully-qualified class name.
The following example creates a BotActionTask
that returns the
current system time to the user:
An XML target can then be placed in the Bot Definition File:
A BotActionTask
can also be used to retrieve
BotParameter
values. The following example retrieves a
STRING
parameter's value (name) and an
INT
parameter's value (age):
BotAction
,
BotParameter
Field Summary | |
---|---|
protected String |
command
The command the user entered, or null . |
protected String |
commandValue
The command value the user entered, or null . |
protected BotEngine |
engine
The bot engine associated with the action. |
protected BotMessage |
message
The message the user entered, or null . |
protected Map |
parameters
The parameter values submitted to this action task, mapped by the associated parameter names (key = String , value = Object ). |
protected BotUser |
user
The user associated with the action. |
Constructor Summary | |
---|---|
protected |
BotActionTask()
|
Method Summary | |
---|---|
abstract Object |
execute()
Executes this task. |
boolean |
getBooleanValue(String name)
Returns a boolean parameter value. |
BotParameter |
getBotParameter(String name)
Returns the specified parameter. |
Map |
getBotParameters()
Returns the parameters submitted to this action task, mapped by their associated names (key = String , value = BotParameter ). |
String |
getCommand()
Returns the command the user entered, or null . |
String |
getCommandValue()
Returns the command value the user entered, or null . |
Number |
getCurrencyValue(String name)
Returns a currency parameter value. |
Date |
getDateTimeValue(String name)
Returns a date-time parameter value. |
Date |
getDateValue(String name)
Returns a date parameter value. |
double |
getDoubleValue(String name)
Returns a double parameter value. |
BotEngine |
getEngine()
Returns the bot engine associated with the action. |
int |
getIntValue(String name)
Returns an int parameter value. |
long |
getLongValue(String name)
Returns a long parameter value. |
BotMessage |
getMessage()
Returns the message the user entered, or null . |
Number |
getNumberValue(String name)
Returns a number parameter value. |
Object |
getParameter(String name)
Returns the specified parameter value. |
Map |
getParameters()
Returns the parameter values submitted to this action task, mapped by the associated parameter names (key = String , value = Object ). |
Number |
getPercentValue(String name)
Returns a percent parameter value. |
String |
getStringValue(String name)
Returns a string parameter value. |
Date |
getTimeValue(String name)
Returns a time parameter value. |
BotUser |
getUser()
Returns the user associated with the action. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected BotEngine engine
protected BotUser user
protected BotMessage message
null
.
protected String command
null
.
protected String commandValue
null
. The command
value is everything entered after the command name.
protected Map parameters
String
, value = Object
).
Constructor Detail |
---|
protected BotActionTask()
Method Detail |
---|
public BotEngine getEngine()
public BotUser getUser()
public BotMessage getMessage()
null
.
public String getCommand()
null
.
public String getCommandValue()
null
. The
command value is everything entered after the command name.
public Object getParameter(String name)
name
- the parameter's name
null
if the parameter does not existgetParameters()
public Map getParameters()
String
, value = Object
).
public BotParameter getBotParameter(String name)
A BotParameter
does not hold a user's entered values.
It exists only as metadata to describe the type of value expected from
the user, and/or how to process that value. To retrieve parameter
values, use getParameter(java.lang.String)
, getParameters()
, or one of the
various getValue
methods.
name
- the parameter's name
null
if the parameter does not existgetBotParameters()
public Map getBotParameters()
String
, value = BotParameter
).
A BotParameter
does not hold a user's entered values.
It exists only as metadata to describe the type of value expected from
the user, and/or how to process that value. To retrieve parameter
values, use getParameter(java.lang.String)
, getParameters()
, or one of the
various getValue
methods.
public abstract Object execute() throws Exception
BotEngine
, and must be
overridden to do something useful.
The returned value is processed according to its type and the action's
result type
.
null
, or the result type is
NONE
, nothing is processed or sent
to the user.
byte[]
char[]
RichContent
File
(reads bytes from the file if necessary)
InputStream
(reads bytes from the stream)
Reader
(reads characters from the reader)
URL
(opens a connection and reads bytes from the input
stream)
Node
(existing XML content)
InputSource
(an XML input source)
Source
(an XML transformation source)
Object
types (can be converted into a string)
BotCall
, it is processed directly and/or
sent to the user.
RichContent
, it is sent to the user as
BotContent
.
File
, it is sent to the user as a
BotFile
.
String
(via toString
) and sent to the user as
BotContent
.
A task can take any amount of time to complete, depending on the
associated action's timeout
value. If a
timeout is specified, and expires before the task has finished
execution, its calling Thread
will be interrupted. Long-running
tasks can query isInterrupted
on the
current thread, or catch InterruptedException
from a waiting
object, to handle this.
Exception
public String getStringValue(String name) throws IllegalArgumentException
string
parameter value.
name
- the parameter's name
IllegalArgumentException
- if the specified parameter does not
existBotParameterType.STRING
public boolean getBooleanValue(String name) throws IllegalArgumentException
boolean
parameter value.
If the specified parameter value is a Boolean
, it is converted
directly to a boolean
and returned. Otherwise, the
String
value is parsed into a boolean
(as described
in BotParameterType.BOOLEAN
) and returned.
name
- the parameter's name
IllegalArgumentException
- if the specified parameter does not
exist, or has an invalid valueBotParameterType.BOOLEAN
public int getIntValue(String name) throws IllegalArgumentException
int
parameter value.
If the specified parameter value is a Number
, it is casted to an
int
and returned. Otherwise, the String
value is
parsed into a Number
, then processed as above.
name
- the parameter's name
IllegalArgumentException
- if the specified parameter does not
exist, or has an invalid valueBotParameterType.INT
,
getNumberValue(java.lang.String)
public long getLongValue(String name) throws IllegalArgumentException
long
parameter value.
If the specified parameter value is a Number
, it is casted to a
long
and returned. Otherwise, the String
value is
parsed into a Number
, then processed as above.
name
- the parameter's name
IllegalArgumentException
- if the specified parameter does not
exist, or has an invalid valueBotParameterType.LONG
,
getNumberValue(java.lang.String)
public double getDoubleValue(String name) throws IllegalArgumentException
double
parameter value.
If the specified parameter value is a Number
, it is casted to a
double
and returned. Otherwise, the String
value
is parsed into a Number
, then processed as above.
name
- the parameter's name
IllegalArgumentException
- if the specified parameter does not
exist, or has an invalid valueBotParameterType.DOUBLE
,
getNumberValue(java.lang.String)
public Number getNumberValue(String name) throws IllegalArgumentException
number
parameter value.
If the specified parameter value is a Number
, it is returned
directly. Otherwise, the String
value is parsed into a
Number
and returned.
Simple number values (such 1
and 3.14
) are
accepted, as well as locale-specific complex number formats (such as
1,234,567
). Related BotParameter
settings (such as
locale
and
numberFormat
) are used to parse the
value, if available.
name
- the parameter's name
IllegalArgumentException
- if the specified parameter does not
exist, or has an invalid valueBotParameterType.NUMBER
,
BotParameter
public Number getCurrencyValue(String name)
currency
parameter value.
If the specified parameter value is a Number
, and the parameter
type is currency
, the value is returned directly.
Otherwise, the String
value is parsed into a Number
and
returned.
Locale-specific currency values (such as $1.50
and
$1,000,000
) are accepted. Related BotParameter
settings (such as locale
and
numberFormat
) are used to parse the
value, if available.
name
- the parameter's name
IllegalArgumentException
- if the specified parameter does not
exist, or has an invalid valueBotParameterType.CURRENCY
,
BotParameter
public Number getPercentValue(String name)
percent
parameter value.
If the specified parameter value is a Number
, and the parameter
type is percent
, the value is returned directly.
Otherwise, the String
value is parsed into a Number
and
returned.
Locale-specific percentage values (such as 100%
and
5.25%
) are accepted. Related BotParameter
settings (such as locale
and
numberFormat
) are used to parse the
value, if available.
name
- the parameter's name
IllegalArgumentException
- if the specified parameter does not
exist, or has an invalid valueBotParameterType.PERCENT
,
BotParameter
public Date getDateValue(String name)
date
parameter value.
If the specified parameter value is a Date
, it is returned
directly. Otherwise, the String
value is parsed into a
Date
and returned.
Locale-specific date values (such as 12/22/92
) are
accepted. Related BotParameter
properties (such as
locale
and
dateFormat
) are used to parse the
value, if available.
name
- the parameter's name
IllegalArgumentException
- if the specified parameter does not
exist, or has an invalid valueBotParameterType.DATE
,
BotDateTimeStyle
,
BotParameter
public Date getTimeValue(String name)
time
parameter value.
If the specified parameter value is a Date
, it is returned
directly. Otherwise, the String
value is parsed into a
Date
and returned.
Locale-specific time values (such as 2:30 pm
) are
accepted. Related BotParameter
properties (such as
locale
and
dateFormat
) are used to parse the
value, if available.
name
- the parameter's name
IllegalArgumentException
- if the specified parameter does not
exist, or has an invalid valueBotParameterType.TIME
,
BotDateTimeStyle
,
BotParameter
public Date getDateTimeValue(String name)
date-time
parameter value.
If the specified parameter value is a Date
, it is returned
directly. Otherwise, the String
value is parsed into a
Date
and returned.
Locale-specific date/time values (such as 12/22/92 2:30 pm
)
are accepted. Related BotParameter
properties (such as
locale
and
dateFormat
) are used to parse the
value, if available.
name
- the parameter's name
IllegalArgumentException
- if the specified parameter does not
exist, or has an invalid valueBotParameterType.DATE_TIME
,
BotDateTimeStyle
,
BotParameter
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |