[Asterisk-java-cvs] CVS: asterisk-java/src/java/net/sf/asterisk/manager ManagerConnectionFactory.jav
Brought to you by:
srt
From: Stefan R. <sr...@us...> - 2005-08-05 05:03:54
|
Update of /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/manager In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7848/src/java/net/sf/asterisk/manager Modified Files: ManagerConnectionFactory.java Log Message: Made default values customizable Index: ManagerConnectionFactory.java =================================================================== RCS file: /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/manager/ManagerConnectionFactory.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -p -r1.2 -r1.3 --- ManagerConnectionFactory.java 23 Feb 2005 22:50:57 -0000 1.2 +++ ManagerConnectionFactory.java 5 Aug 2005 05:03:14 -0000 1.3 @@ -22,7 +22,6 @@ import java.io.IOException; * This factory is used to obtain new ManagerConnections. * * @see net.sf.asterisk.manager.ManagerConnection - * * @author srt * @version $Id$ */ @@ -30,63 +29,146 @@ public class ManagerConnectionFactory { private static final String DEFAULT_HOSTNAME = "localhost"; private static final int DEFAULT_PORT = 5038; + private static final String DEFAULT_USERNAME = "admin"; + private static final String DEFAULT_PASSWORD = "admin"; + + private String hostname; + private int port; + private String username; + private String password; /** * Creates a new ManagerConnectionFactory. */ public ManagerConnectionFactory() { + this.hostname = DEFAULT_HOSTNAME; + this.port = DEFAULT_PORT; + this.username = DEFAULT_USERNAME; + this.password = DEFAULT_PASSWORD; + } + /** + * Sets the default hostname.<br> + * Default is "localhost". + * + * @param hostname the default hostname + * @since 0.2 + */ + public void setHostname(String hostname) + { + this.hostname = hostname; } /** - * Returns a new ManagerConnection to an asterisk server running on localhost with the call - * manager interface listening on its default port 5038. + * Sets the default port.<br> + * Default is 5038. * - * @param username the username as specified in asterisk's <code>manager.conf</code> - * @param password the password as specified in asterisk's <code>manager.conf</code> + * @param port the default port + * @since 0.2 + */ + public void setPort(int port) + { + this.port = port; + } + + /** + * Sets the default username.<br> + * Default is "admin". * - * @return the created connection to the asterisk call manager + * @param username the default username + * @since 0.2 + */ + public void setUsername(String username) + { + this.username = username; + } + + /** + * Sets the default password.<br> + * Default is "admin". * - * @throws IOException if the connection cannot be established. + * @param username the default password + * @since 0.2 */ - public ManagerConnection getManagerConnection(String username, String password) throws IOException + public void setPassword(String password) { - return new DefaultManagerConnection(DEFAULT_HOSTNAME, DEFAULT_PORT, username, password); + this.password = password; } /** - * Returns a new ManagerConnection to an asterisk server running on given host with the call - * manager interface listening on its default port 5038. + * Returns a new ManagerConnection with the default values for hostname, + * port, username and password. It uses either the built-in defaults + * ("localhost", 5038, "admin", "admin") or the custom default values you + * set via {@link #setHostname(String)}, {@link #setPort(int)}, + * {@link #setUsername(String)} and {@link #setPassword(String)}. * - * @param hostname the name of the host the asterisk server is running on - * @param username the username as specified in asterisk's <code>manager.conf</code> - * @param password the password as specified in asterisk's <code>manager.conf</code> + * @return the created connection to the Asterisk call manager + * @throws IOException if the connection cannot be established. + * @since 0.2 + */ + public ManagerConnection getManagerConnection() throws IOException + { + return new DefaultManagerConnection(this.hostname, this.port, + this.username, this.password); + } + + /** + * Returns a new ManagerConnection to an Asterisk server running on default + * host ("localhost" if you didn't change that via + * {@link #setHostname(String)}) with the call manager interface listening + * on the default port (5038 if you didn't change that via + * {@link #setPort(int)}). * - * @return the created connection to the asterisk call manager + * @param username the username as specified in Asterisk's + * <code>manager.conf</code> + * @param password the password as specified in Asterisk's + * <code>manager.conf</code> + * @return the created connection to the Asterisk call manager + * @throws IOException if the connection cannot be established. + */ + public ManagerConnection getManagerConnection(String username, + String password) throws IOException + { + return new DefaultManagerConnection(this.hostname, this.port, username, + password); + } + + /** + * Returns a new ManagerConnection to an Asterisk server running on given + * host with the call manager interface listening on the default port (5038 + * if you didn't change that via {@link #setPort(int)}). * + * @param hostname the name of the host the Asterisk server is running on + * @param username the username as specified in Asterisk's + * <code>manager.conf</code> + * @param password the password as specified in Asterisk's + * <code>manager.conf</code> + * @return the created connection to the Asterisk call manager * @throws IOException if the connection cannot be established. */ - public ManagerConnection getManagerConnection(String hostname, String username, String password) throws IOException + public ManagerConnection getManagerConnection(String hostname, + String username, String password) throws IOException { - return new DefaultManagerConnection(hostname, DEFAULT_PORT, username, password); + return new DefaultManagerConnection(hostname, this.port, username, + password); } /** - * Returns a new ManagerConnection to an asterisk server running on given host with the call - * manager interface listening on the given port. + * Returns a new ManagerConnection to an Asterisk server running on given + * host with the call manager interface listening on the given port. * - * @param hostname the name of the host the asterisk server is running on + * @param hostname the name of the host the Asterisk server is running on * @param port the port the call manager interface is listening on - * @param username the username as specified in asterisk's <code>manager.conf</code> - * @param password the password as specified in asterisk's <code>manager.conf</code> - * - * @return the created connection to the asterisk call manager - * + * @param username the username as specified in Asterisk's + * <code>manager.conf</code> + * @param password the password as specified in Asterisk's + * <code>manager.conf</code> + * @return the created connection to the Asterisk call manager * @throws IOException if the connection cannot be established. */ - public ManagerConnection getManagerConnection(String hostname, int port, String username, String password) - throws IOException + public ManagerConnection getManagerConnection(String hostname, int port, + String username, String password) throws IOException { return new DefaultManagerConnection(hostname, port, username, password); } |