[Asterisk-java-cvs] CVS: asterisk-java/src/java/net/sf/asterisk/fastagi/reply AGIReply.java,1.9,1.10
Brought to you by:
srt
From: Stefan R. <sr...@us...> - 2005-03-11 13:40:24
|
Update of /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/fastagi/reply In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25827/src/java/net/sf/asterisk/fastagi/reply Modified Files: AGIReply.java Log Message: Added extra and attributes properties to AGIReply Index: AGIReply.java =================================================================== RCS file: /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/fastagi/reply/AGIReply.java,v retrieving revision 1.9 retrieving revision 1.10 diff -u -d -p -r1.9 -r1.10 --- AGIReply.java 10 Mar 2005 13:54:06 -0000 1.9 +++ AGIReply.java 11 Mar 2005 13:40:06 -0000 1.10 @@ -17,6 +17,8 @@ package net.sf.asterisk.fastagi.reply; import java.io.Serializable; +import java.util.HashMap; +import java.util.Map; import org.apache.commons.lang.builder.EqualsBuilder; import org.apache.commons.lang.builder.HashCodeBuilder; @@ -65,9 +67,9 @@ public class AGIReply implements Seriali private static final long serialVersionUID = 3256727294671337012L; /** - * The return code. + * The result. */ - private int result; + private String result; /** * The status code. @@ -75,6 +77,16 @@ public class AGIReply implements Seriali private int status; /** + * Additional attributes contained in this reply, for example endpos. + */ + private Map attributes; + + /** + * The contents of the parenthesis. + */ + private String extra; + + /** * In case of status == 520 (invalid command syntax) this attribute contains * the synopsis of the command. */ @@ -87,33 +99,63 @@ public class AGIReply implements Seriali private String usage; /** - * Returns the return code. + * Returns the return code (the result as int). * - * @return the return code. + * @return the return code or -1 if the result is not an int. */ - public int getResult() + public int getResultCode() { - return result; + if (result == null) + { + return -1; + } + + try + { + return Integer.parseInt(result); + } + catch (NumberFormatException e) + { + return -1; + } } /** - * Sets the return code. + * Returns the return code as character. * - * @param result the return code to set. + * @return the return code as character. */ - public void setResult(int result) + public char getResultCodeAsChar() { - this.result = result; + int resultCode; + + resultCode = getResultCode(); + if (resultCode < 0) + { + return 0x0; + } + + return (char) resultCode; } /** - * Returns the return code as character. + * Returns the result. * - * @return the return code as character. + * @return the result. */ - public char getResultAsChar() + public String getResult() { - return (char) result; + return result; + } + + /** + * Sets the result. + * + * @param result the result to set. + */ + public void setResult(String result) + { + this.result = result; } /** @@ -143,6 +185,72 @@ public class AGIReply implements Seriali } /** + * Returns an additional attribute contained in the reply.<br> + * For example the reply to the StreamFileCommand contains an additional + * endpos attribute indicating the frame where the playback was stopped. + * This can be retrieved by calling getAttribute("endpos") on the + * corresponding reply. + * + * @param name the name of the attribute to retrieve. The name is case + * insensitive. + * @return the value of the attribute or <code>null</code> if it is not + * set. + */ + public String getAttribute(String name) + { + if ("result".equalsIgnoreCase(name)) + { + return getResult(); + } + + if (attributes == null) + { + return null; + } + + return (String) attributes.get(name.toLowerCase()); + } + + /** + * Sets an additional attribute. + * + * @param name the name of the attribute to set. + * @param value the value of the attribute to set. + */ + public void setAttribute(String name, String value) + { + if (attributes == null) + { + attributes = new HashMap(); + } + + attributes.put(name.toLowerCase(), value); + } + + /** + * Returns the text in parenthesis contained in this reply.<br> + * The meaning of this property depends on the command sent. Sometimes it + * contains a flag like "timeout" or "hangup" or - in case of the + * GetVariableCommand - the value of the variable. + * + * @return the text in the parenthesis or <code>null</code> if not set. + */ + public String getExtra() + { + return extra; + } + + /** + * Sets the text in parenthesis in this reply. + * + * @param extra the text in parenthesis to set. + */ + public void setExtra(String extra) + { + this.extra = extra; + } + + /** * Returns the synopsis of the command sent if Asterisk expected a different * syntax (getStatus() == SC_INVALID_COMMAND_SYNTAX). * |