Asterisk-Java

org.asteriskjava.manager.action
Class GetVarAction

java.lang.Object
  extended by org.asteriskjava.manager.action.AbstractManagerAction
      extended by org.asteriskjava.manager.action.GetVarAction
All Implemented Interfaces:
java.io.Serializable, ManagerAction

public class GetVarAction
extends AbstractManagerAction

The GetVarAction queries for a global or local channel variable.

Reading global variables is supported since Asterisk 1.2.

You cannot read built-in channel variables such as LANGUAGE or CALLERIDNUM using the Manager API. You can only read channel variables that you have explicitly set using the Set or SetVar (for Asterisk 1.0.x) applications in the dialplan, in an AGI script or by using the SetVarAction through the Manager API itself.

GetVarAction returns a GetVarResponse. To get the actual value from the corresponding ManagerResponse call ManagerResponse.getAttribute(String) with either the variable name as parameter (for Asterisk 1.0.x) or with "Value" as parameter (for Asterisk since 1.2).

Example (for Asterisk 1.2):

 GetVarAction getVarAction = new GetVarAction(channel, "MY_VAR");
 ManagerResponse response = c.sendAction(getVarAction);
 String value = response.getAttribute("Value");
 System.out.println("MY_VAR on " + channel + " is " + value);
 
Where c is an instance of ManagerConnection and channel contains the name of a channel instance, for example "SIP/1234-9cd".

Since Asterisk-Java 1.0.0 you can also call GetVarResponse.getValue() when using Asterisk 1.2 or later.

Since Asterisk 1.4 this action also supports built-in functions like DB(), CALLERID() and ENV().

Version:
$Id: GetVarAction.java 1153 2008-08-22 10:10:22Z srt $
Author:
srt
See Also:
Serialized Form

Constructor Summary
GetVarAction()
          Creates a new empty GetVarAction.
GetVarAction(java.lang.String variable)
          Creates a new GetVarAction that queries for the given global variable.
GetVarAction(java.lang.String channel, java.lang.String variable)
          Creates a new GetVarAction that queries for the given local channel variable.
 
Method Summary
 java.lang.String getAction()
          Returns the name of this action, i.e.
 java.lang.String getChannel()
          Returns the name of the channel if you query for a local channel variable or null if it is a global variable.
 java.lang.String getVariable()
          Retruns the name of the variable to query.
 void setChannel(java.lang.String channel)
          Sets the name of the channel if you query for a local channel variable.
 void setVariable(java.lang.String variable)
          Sets the name of the variable to query.
 
Methods inherited from class org.asteriskjava.manager.action.AbstractManagerAction
getActionId, setActionId, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

GetVarAction

public GetVarAction()
Creates a new empty GetVarAction.


GetVarAction

public GetVarAction(java.lang.String variable)
Creates a new GetVarAction that queries for the given global variable.

Parameters:
variable - the name of the global variable to query.
Since:
0.2

GetVarAction

public GetVarAction(java.lang.String channel,
                    java.lang.String variable)
Creates a new GetVarAction that queries for the given local channel variable.

Parameters:
channel - the name of the channel, for example "SIP/1234-9cd".
variable - the name of the variable to query.
Since:
0.2
Method Detail

getAction

public java.lang.String getAction()
Returns the name of this action, i.e. "GetVar".

Specified by:
getAction in interface ManagerAction
Specified by:
getAction in class AbstractManagerAction

getChannel

public java.lang.String getChannel()
Returns the name of the channel if you query for a local channel variable or null if it is a global variable.


setChannel

public void setChannel(java.lang.String channel)
Sets the name of the channel if you query for a local channel variable. Leave empty to query for a global variable.

Parameters:
channel - the channel if you query for a local channel variable or null to query for a gloabl variable.

getVariable

public java.lang.String getVariable()
Retruns the name of the variable to query.


setVariable

public void setVariable(java.lang.String variable)
Sets the name of the variable to query.


Asterisk-Java

Copyright © 2004-2009 Stefan Reuter. All Rights Reserved.