[Asterisk-java-cvs] CVS: asterisk-java/src/java/net/sf/asterisk/fastagi/reply AGIReply.java,1.12,1.1
Brought to you by:
srt
From: Stefan R. <sr...@us...> - 2005-04-15 04:47:11
|
Update of /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/fastagi/reply In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16598/src/java/net/sf/asterisk/fastagi/reply Modified Files: AGIReply.java Log Message: - Moved funcitonality of ReplyBuilder and RequestBuilder to AGIReplyImpl and AGIRequestImpl (thanks to Steve Drach for providing this patch) - Removed ReplyBuilde and RequestBuilder - Refactored Reply into interface and implementation Index: AGIReply.java =================================================================== RCS file: /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/fastagi/reply/AGIReply.java,v retrieving revision 1.12 retrieving revision 1.13 diff -u -d -p -r1.12 -r1.13 --- AGIReply.java 30 Mar 2005 01:39:05 -0000 1.12 +++ AGIReply.java 15 Apr 2005 04:47:02 -0000 1.13 @@ -16,9 +16,7 @@ */ package net.sf.asterisk.fastagi.reply; -import java.io.Serializable; -import java.util.HashMap; -import java.util.Map; +import java.util.List; /** * Reply received in response to an AGICommand.<br> @@ -31,7 +29,7 @@ import java.util.Map; * @author srt * @version $Id$ */ -public class AGIReply implements Serializable +public interface AGIReply { /** * Status code (200) indicating Asterisk successfully processed the @@ -54,84 +52,24 @@ public class AGIReply implements Seriali * code. */ public static int SC_INVALID_COMMAND_SYNTAX = 520; + + String getFirstLine(); - /** - * Serial version identifier. - */ - private static final long serialVersionUID = 3256727294671337012L; - - /** - * The result, that is the part directly following the "result=" - * string. - */ - private String result; - - /** - * The status code. - */ - 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. - */ - private String synopsis; - - /** - * In case of status == 520 (invalid command syntax) this attribute contains - * the usage of the command. - */ - private String usage; + List getLines(); /** * Returns the return code (the result as int). * * @return the return code or -1 if the result is not an int. */ - public int getResultCode() - { - if (result == null) - { - return -1; - } - - try - { - return Integer.parseInt(result); - } - catch (NumberFormatException e) - { - return -1; - } - } + int getResultCode(); /** * Returns the return code as character. * * @return the return code as character. */ - public char getResultCodeAsChar() - { - int resultCode; - - resultCode = getResultCode(); - if (resultCode < 0) - { - return 0x0; - } - - return (char) resultCode; - } + char getResultCodeAsChar(); /** * Returns the result, that is the part directly following the "result=" @@ -139,20 +77,7 @@ public class AGIReply implements Seriali * * @return the result. */ - public String getResult() - { - return result; - } - - /** - * Sets the result. - * - * @param result the result to set. - */ - public void setResult(String result) - { - this.result = result; - } + String getResult(); /** * Returns the status code.<br> @@ -165,20 +90,7 @@ public class AGIReply implements Seriali * * @return the status code. */ - public int getStatus() - { - return status; - } - - /** - * Sets the status code. - * - * @param status the status code to set. - */ - public void setStatus(int status) - { - this.status = status; - } + int getStatus(); /** * Returns an additional attribute contained in the reply.<br> @@ -192,36 +104,7 @@ public class AGIReply implements Seriali * @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); - } + String getAttribute(String name); /** * Returns the text in parenthesis contained in this reply.<br> @@ -231,20 +114,7 @@ public class AGIReply implements Seriali * * @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; - } + String getExtra(); /** * Returns the synopsis of the command sent if Asterisk expected a different @@ -253,20 +123,7 @@ public class AGIReply implements Seriali * @return the synopsis of the command sent, <code>null</code> if there * were no syntax errors. */ - public String getSynopsis() - { - return synopsis; - } - - /** - * Sets the synopsis of the command sent. - * - * @param synopsis the synopsis of the command sent. - */ - public void setSynopsis(String synopsis) - { - this.synopsis = synopsis; - } + String getSynopsis(); /** * Returns the usage of the command sent if Asterisk expected a different @@ -275,39 +132,6 @@ public class AGIReply implements Seriali * @return the usage of the command sent, <code>null</code> if there were * no syntax errors. */ - public String getUsage() - { - return usage; - } - - /** - * Sets the synopsis of the command sent. - * - * @param usage the usage of the command sent. - */ - public void setUsage(String usage) - { - this.usage = usage; - } - - public String toString() - { - StringBuffer sb; - - sb = new StringBuffer(getClass().getName() + ": "); - sb.append("status='" + getStatus() + "'; "); - if (status == SC_SUCCESS) - { - sb.append("result='" + getResult() + "'; "); - sb.append("extra='" + getExtra() + "'; "); - sb.append("attributes=" + attributes + "; "); - } - if (status == SC_INVALID_COMMAND_SYNTAX) - { - sb.append("synopsis='" + getSynopsis() + "'; "); - } - sb.append("systemHashcode=" + System.identityHashCode(this)); + String getUsage(); - return sb.toString(); - } } |