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
28 /***
29 * Class that represents a Sinon collector.
30 *
31 * @author <a href="mailto:thiagohp at users.sourceforge.net">Thiago H. de Paula Figueiredo</a>
32 * @author Last modified by $Author: thiagohp $
33 * @version $Revision: 1.2 $
34 */
35 public class Collector {
36
37 /***
38 * Collector identifier.
39 */
40 private String id;
41
42 /***
43 * Global configurations of this collector.
44 */
45 private CollectorConfiguration configuration;
46
47 /***
48 * List of catalogs of this collector.
49 * Lista de catálogos deste coletor.
50 */
51 private List catalogs;
52
53 /***
54 * Catalog state listener class name.
55 */
56 private String catalogStateListenerClassName;
57
58 /***
59 * Constructor without parameters.
60 */
61 public Collector() {
62 catalogs = new ArrayList();
63 }
64
65 /***
66 * Returns the value of the <code>id</code> property.
67 * @return a <code>String</code>.
68 */
69 public String getId() {
70 return id;
71 }
72
73 /***
74 * Sets the value of the <code>id</code> property.
75 * @param id the new <code>id</code> value.
76 */
77 public void setId(String id) {
78 this.id = id;
79 }
80
81 /***
82 * Returns the value of the <code>configurations</code> property.
83 * @return a {@link CollectorConfiguration} instance.
84 */
85 public CollectorConfiguration getConfiguration() {
86 return configuration;
87 }
88
89 /***
90 * Sets the value of the <code>configuration</code> property.
91 * @param configuration a {@link CollectorConfiguration} instance.
92 */
93 public void setConfiguration(CollectorConfiguration configuration) {
94 this.configuration = configuration;
95 }
96
97 /***
98 * Adds a {@link Catalog} to this collector.
99 * @param catalog a {@link Catalog} instance.
100 */
101 public void addCatalog(Catalog catalog) {
102 catalogs.add(catalog);
103 }
104
105 /***
106 * Removes a {@link Catalog} to this collector.
107 * @param catalog a {@link Catalog} instance.
108 */
109 public void removeCatalog(Catalog catalog) {
110 catalogs.remove(catalog);
111 }
112
113 /***
114 * Returns the value of the <code>catalogs</code> property.
115 * @return a {@link Catalog} array.
116 */
117 public Catalog[] getCatalogs() {
118
119 Catalog[] catalog = new Catalog[catalogs.size()];
120
121 catalogs.toArray(catalog);
122
123 return catalog;
124
125 }
126
127 /***
128 * Returns the {@link Catalog} whose identifier is <code>id</code>.
129 * @param id a <code>String</code>.
130 * @return a {@link Catalog} instance or <code>null</code> if
131 * there is no {@link Catalog} whose identifier is <code>id</code>.
132 * @throws IllegalArgumentException if <code>id</code> is
133 * <code>null</code>.
134 */
135 public Catalog getCatalog(String id) {
136
137 final int size = catalogs.size();
138 Catalog catalog;
139
140 for (int i = 0; i < size; i++) {
141
142 catalog = (Catalog) catalogs.get(i);
143
144 if (id.equals(catalog.getId())) {
145 return catalog;
146 }
147
148 }
149
150 return null;
151
152 }
153
154 /***
155 * Returns the value of the <code>catalogStateListenerClassName</code>
156 * property.
157 * @return a <code>String</code>.
158 */
159 public String getCatalogStateListenerClassName() {
160 return catalogStateListenerClassName;
161 }
162
163 /***
164 * Sets the value of the <code>catalogStateListenerClassName</code>
165 * property.
166 * @param catalogStateListenerClassName the new
167 * <code>catalogStateListenerClassName</code> value.
168 */
169 public void setCatalogStateListenerClassName(
170 String catalogStateListenerClassName) {
171
172 this.catalogStateListenerClassName = catalogStateListenerClassName;
173
174 }
175
176 }