1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package net.sf.asterisk.manager;
18
19 import java.io.IOException;
20
21 /***
22 * This factory is used to obtain new ManagerConnections.
23 *
24 * @see net.sf.asterisk.manager.ManagerConnection
25 * @author srt
26 * @version $Id: ManagerConnectionFactory.java,v 1.3 2005/08/05 05:03:14 srt Exp $
27 */
28 public class ManagerConnectionFactory
29 {
30 private static final String DEFAULT_HOSTNAME = "localhost";
31 private static final int DEFAULT_PORT = 5038;
32 private static final String DEFAULT_USERNAME = "admin";
33 private static final String DEFAULT_PASSWORD = "admin";
34
35 private String hostname;
36 private int port;
37 private String username;
38 private String password;
39
40 /***
41 * Creates a new ManagerConnectionFactory.
42 */
43 public ManagerConnectionFactory()
44 {
45 this.hostname = DEFAULT_HOSTNAME;
46 this.port = DEFAULT_PORT;
47 this.username = DEFAULT_USERNAME;
48 this.password = DEFAULT_PASSWORD;
49 }
50
51 /***
52 * Sets the default hostname.<br>
53 * Default is "localhost".
54 *
55 * @param hostname the default hostname
56 * @since 0.2
57 */
58 public void setHostname(String hostname)
59 {
60 this.hostname = hostname;
61 }
62
63 /***
64 * Sets the default port.<br>
65 * Default is 5038.
66 *
67 * @param port the default port
68 * @since 0.2
69 */
70 public void setPort(int port)
71 {
72 this.port = port;
73 }
74
75 /***
76 * Sets the default username.<br>
77 * Default is "admin".
78 *
79 * @param username the default username
80 * @since 0.2
81 */
82 public void setUsername(String username)
83 {
84 this.username = username;
85 }
86
87 /***
88 * Sets the default password.<br>
89 * Default is "admin".
90 *
91 * @param username the default password
92 * @since 0.2
93 */
94 public void setPassword(String password)
95 {
96 this.password = password;
97 }
98
99 /***
100 * Returns a new ManagerConnection with the default values for hostname,
101 * port, username and password. It uses either the built-in defaults
102 * ("localhost", 5038, "admin", "admin") or the custom default values you
103 * set via {@link #setHostname(String)}, {@link #setPort(int)},
104 * {@link #setUsername(String)} and {@link #setPassword(String)}.
105 *
106 * @return the created connection to the Asterisk call manager
107 * @throws IOException if the connection cannot be established.
108 * @since 0.2
109 */
110 public ManagerConnection getManagerConnection() throws IOException
111 {
112 return new DefaultManagerConnection(this.hostname, this.port,
113 this.username, this.password);
114 }
115
116 /***
117 * Returns a new ManagerConnection to an Asterisk server running on default
118 * host ("localhost" if you didn't change that via
119 * {@link #setHostname(String)}) with the call manager interface listening
120 * on the default port (5038 if you didn't change that via
121 * {@link #setPort(int)}).
122 *
123 * @param username the username as specified in Asterisk's
124 * <code>manager.conf</code>
125 * @param password the password as specified in Asterisk's
126 * <code>manager.conf</code>
127 * @return the created connection to the Asterisk call manager
128 * @throws IOException if the connection cannot be established.
129 */
130 public ManagerConnection getManagerConnection(String username,
131 String password) throws IOException
132 {
133 return new DefaultManagerConnection(this.hostname, this.port, username,
134 password);
135 }
136
137 /***
138 * Returns a new ManagerConnection to an Asterisk server running on given
139 * host with the call manager interface listening on the default port (5038
140 * if you didn't change that via {@link #setPort(int)}).
141 *
142 * @param hostname the name of the host the Asterisk server is running on
143 * @param username the username as specified in Asterisk's
144 * <code>manager.conf</code>
145 * @param password the password as specified in Asterisk's
146 * <code>manager.conf</code>
147 * @return the created connection to the Asterisk call manager
148 * @throws IOException if the connection cannot be established.
149 */
150 public ManagerConnection getManagerConnection(String hostname,
151 String username, String password) throws IOException
152 {
153 return new DefaultManagerConnection(hostname, this.port, username,
154 password);
155 }
156
157 /***
158 * Returns a new ManagerConnection to an Asterisk server running on given
159 * host with the call manager interface listening on the given port.
160 *
161 * @param hostname the name of the host the Asterisk server is running on
162 * @param port the port the call manager interface is listening on
163 * @param username the username as specified in Asterisk's
164 * <code>manager.conf</code>
165 * @param password the password as specified in Asterisk's
166 * <code>manager.conf</code>
167 * @return the created connection to the Asterisk call manager
168 * @throws IOException if the connection cannot be established.
169 */
170 public ManagerConnection getManagerConnection(String hostname, int port,
171 String username, String password) throws IOException
172 {
173 return new DefaultManagerConnection(hostname, port, username, password);
174 }
175 }