1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 package eteg.sinon.core;
24
25 import java.util.ArrayList;
26 import java.util.List;
27 import java.util.Properties;
28
29 /***
30 * Class that represents the configurations of a {@link Collector}.
31 *
32 * @author <a href="mailto:thiagohp at users.sourceforge.net">Thiago H. de Paula Figueiredo</a>
33 * @author Last modified by $Author: thiagohp $
34 * @version $Revision: 1.2 $
35 * @see Collector
36 */
37 public class CollectorConfiguration {
38
39 /***
40 * Default timeout value: 10000 milliseconds.
41 */
42 private static final int DEFAULT_TIMEOUT = 10000;
43
44 /***
45 * Default retries value: 1.
46 */
47 private static final int DEFAULT_RETRIES = 1;
48
49 /***
50 * HTTP headers to be sent to Web sites.
51 */
52 private Properties httpHeaders;
53
54 /***
55 * List of security configurations.
56 */
57 private List securityConfigurations;
58
59 /***
60 * Fully qualified name of the class that implements the think time.
61 */
62 private String thinkTimeImplementationClassName;
63
64 /***
65 * Properties used as think time configurations.
66 */
67 private Properties thinkTimeProperties;
68
69 /***
70 * Connection timeout in milliseconds.
71 */
72 private int timeout;
73
74 /***
75 * Maximum number of download attempts of a given page.
76 */
77 private int retries;
78
79 /***
80 * Constructor without parameters.
81 */
82 public CollectorConfiguration() {
83
84 securityConfigurations = new ArrayList();
85 httpHeaders = new Properties();
86 thinkTimeImplementationClassName = null;
87 thinkTimeProperties = new Properties();
88 timeout = DEFAULT_TIMEOUT;
89 retries = DEFAULT_RETRIES;
90
91 }
92
93 /***
94 * Returns the value of the <code>thinkTimeImplementationClassName</code>
95 * property.
96 * @return a <code>String</code>.
97 */
98 public String getThinkTimeImplementationClassName() {
99 return thinkTimeImplementationClassName;
100 }
101
102 /***
103 * Sets the value of the <code>thinkTimeImplementationClassName</code>
104 * property.
105 * @param thinkTimeImplementationClassName the new
106 * <code>thinkTimeImplementationClassName</code> value.
107 */
108 public void setThinkTimeImplementationClassName(
109 String thinkTimeImplementationClassName) {
110
111 this.thinkTimeImplementationClassName =
112 thinkTimeImplementationClassName;
113
114 }
115
116 /***
117 * Adds a (<code>name</code>, <code>value</code>) pair in the
118 * think time configurations.
119 * @param name a <code>String</code> containing the configuration name.
120 * @param value a <code>String</code> containing the configuration value.
121 */
122 public void setThinkTimeProperty(String name, String value) {
123 thinkTimeProperties.setProperty(name, value);
124 }
125
126 /***
127 * Adds a (<code>name</code>, <code>value</code>) pair in the set of
128 * HTTP headers sent to the Web site.
129 * @param name a <code>String</code> containing the configuration name.
130 * @param value a <code>String</code> containing the configuration value.
131 */
132 public void setHTTPHeader(String name, String value) {
133 httpHeaders.setProperty(name, value);
134 }
135
136 /***
137 * Returns the value associated with a given HTTP header.
138 * @param name a <code>String</code> containing the name of the HTTP header.
139 * @return a <code>String</code> containing the value associated with
140 * the HTTP header or <code>null</code> if there is no such HTTP header.
141 */
142 public String getHTTPHeader(String name) {
143 return httpHeaders.getProperty(name);
144 }
145
146 /***
147 * Adds a {@link SecurityConfiguration} to this object.
148 * @param configuration a {@link SecurityConfiguration} instance.
149 */
150 public void addSecurityConfiguration(SecurityConfiguration configuration) {
151 securityConfigurations.add(configuration);
152 }
153
154 /***
155 * Returns the value of the <code>securityConfigurations</code> property.
156 * @return a a {@link SecurityConfiguration} array.
157 */
158 public SecurityConfiguration[] getSecurityConfigurations() {
159
160 SecurityConfiguration[] configurations =
161 new SecurityConfiguration[securityConfigurations.size()];
162
163 securityConfigurations.toArray(configurations);
164
165 return configurations;
166
167 }
168
169 /***
170 * Returns the {@link SecurityConfiguration} whose identifier is
171 * <code>id</code>.
172 * @param id a <code>String</code>.
173 * @return a {@link SecurityConfiguration} instance or <code>null</code> if
174 * there is no {@link SecurityConfiguration} whose identifier is
175 * <code>id</code>.
176 * @throws IllegalArgumentException if <code>id</code> is
177 * <code>null</code>.
178 */
179 public SecurityConfiguration getSecurityConfiguration(String id) {
180
181 final int size = securityConfigurations.size();
182 SecurityConfiguration configuration;
183
184 for (int i = 0; i < size; i++) {
185
186 configuration =
187 (SecurityConfiguration) securityConfigurations.get(i);
188
189 if (id.equals(configuration.getId())) {
190 return configuration;
191 }
192
193 }
194
195 return null;
196
197 }
198
199 /***
200 * Returns the value of the <code>httpHeaders</code> property.
201 * @return a <code>String</code>.
202 */
203 public Properties getHttpHeaders() {
204 return httpHeaders;
205 }
206
207 /***
208 * Returns the value of the <code>thinkTimeProperties</code> property.
209 * @return a <code>Properties</code> instance.
210 */
211 public Properties getThinkTimeProperties() {
212 return thinkTimeProperties;
213 }
214
215 /***
216 * Returns the value of the <code>timeout</code> property.
217 * @return an <code>int</code>.
218 */
219 public int getTimeout() {
220 return timeout;
221 }
222
223 /***
224 * Sets the value of the <code>timeout</code> property.
225 * @param timeout the new <code>timeout</code> value.
226 */
227 public void setTimeout(int timeout) {
228 this.timeout = timeout;
229 }
230
231 /***
232 * Returns the value of the <code>retries</code> property.
233 * @return an <code>int</code>.
234 */
235 public int getRetries() {
236 return retries;
237 }
238
239 /***
240 * Sets the value of the <code>retries</code> property.
241 * @param retries the new <code>retries</code> value.
242 */
243 public void setRetries(int retries) {
244 this.retries = retries;
245 }
246
247 }