1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
package org.apache.ws.scout.registry.infomodel; |
18 | |
|
19 | |
import java.util.ArrayList; |
20 | |
import java.util.Collection; |
21 | |
import java.util.HashSet; |
22 | |
import java.util.Iterator; |
23 | |
import java.util.Set; |
24 | |
|
25 | |
import javax.xml.registry.JAXRException; |
26 | |
import javax.xml.registry.LifeCycleManager; |
27 | |
import javax.xml.registry.UnsupportedCapabilityException; |
28 | |
import javax.xml.registry.infomodel.Organization; |
29 | |
import javax.xml.registry.infomodel.PostalAddress; |
30 | |
import javax.xml.registry.infomodel.Service; |
31 | |
import javax.xml.registry.infomodel.TelephoneNumber; |
32 | |
import javax.xml.registry.infomodel.User; |
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
public class OrganizationImpl extends RegistryObjectImpl implements Organization |
43 | |
{ |
44 | |
private User primaryContact; |
45 | 0 | private Set<User> users = new HashSet<User>(); |
46 | 0 | private Set<TelephoneNumber> telephoneNumbers = new HashSet<TelephoneNumber>(); |
47 | 0 | private Collection<Service> services = new ArrayList<Service>(); |
48 | |
|
49 | |
public OrganizationImpl(LifeCycleManager lifeCycleManager) |
50 | |
{ |
51 | 0 | super(lifeCycleManager); |
52 | 0 | } |
53 | |
|
54 | |
public User getPrimaryContact() throws JAXRException |
55 | |
{ |
56 | |
|
57 | |
|
58 | |
|
59 | |
|
60 | |
|
61 | |
|
62 | |
|
63 | 0 | return primaryContact; |
64 | |
} |
65 | |
|
66 | |
public void setPrimaryContact(User user) throws JAXRException |
67 | |
{ |
68 | 0 | if (user == null) |
69 | |
{ |
70 | 0 | throw new IllegalArgumentException("primaryContact must not be null"); |
71 | |
} |
72 | |
|
73 | |
|
74 | |
|
75 | |
|
76 | |
|
77 | 0 | primaryContact = user; |
78 | |
|
79 | 0 | if (!users.contains(user)) { |
80 | 0 | addUser(user); |
81 | |
} |
82 | 0 | } |
83 | |
|
84 | |
public void addUser(User user) throws JAXRException |
85 | |
{ |
86 | 0 | doPrimaryContactHack(user); |
87 | |
|
88 | 0 | users.add(user); |
89 | 0 | ((UserImpl) user).setOrganization(this); |
90 | 0 | } |
91 | |
|
92 | |
|
93 | |
|
94 | |
|
95 | |
|
96 | |
|
97 | |
|
98 | |
|
99 | |
private void doPrimaryContactHack(User user) { |
100 | |
|
101 | 0 | if (primaryContact == null && users.size() == 0) { |
102 | 0 | primaryContact = user; |
103 | |
} |
104 | 0 | } |
105 | |
|
106 | |
public void addUsers(Collection collection) throws JAXRException |
107 | |
{ |
108 | |
|
109 | 0 | for (Iterator iterator = collection.iterator(); iterator.hasNext();) |
110 | |
{ |
111 | 0 | User user = (User) iterator.next(); |
112 | 0 | addUser(user); |
113 | 0 | } |
114 | 0 | } |
115 | |
|
116 | |
public Collection<User> getUsers() throws JAXRException |
117 | |
{ |
118 | 0 | return users; |
119 | |
} |
120 | |
|
121 | |
public void removeUser(User user) throws JAXRException |
122 | |
{ |
123 | 0 | if (user != null) { |
124 | 0 | users.remove(user); |
125 | |
} |
126 | |
|
127 | |
|
128 | |
|
129 | |
|
130 | |
|
131 | |
|
132 | 0 | if (!users.contains(primaryContact)) { |
133 | 0 | primaryContact = null; |
134 | |
} |
135 | 0 | } |
136 | |
|
137 | |
public void removeUsers(Collection collection) throws JAXRException |
138 | |
{ |
139 | 0 | if (collection != null) { |
140 | 0 | users.removeAll(collection); |
141 | |
} |
142 | |
|
143 | |
|
144 | |
|
145 | |
|
146 | |
|
147 | |
|
148 | 0 | if (!users.contains(primaryContact)) { |
149 | 0 | primaryContact = null; |
150 | |
} |
151 | |
|
152 | 0 | } |
153 | |
|
154 | |
public Collection<TelephoneNumber> getTelephoneNumbers(String phoneType) throws JAXRException |
155 | |
{ |
156 | |
Set<TelephoneNumber> filteredNumbers; |
157 | 0 | if (phoneType == null) |
158 | |
{ |
159 | 0 | filteredNumbers = telephoneNumbers; |
160 | |
} else |
161 | |
{ |
162 | 0 | filteredNumbers = new HashSet<TelephoneNumber>(telephoneNumbers.size()); |
163 | 0 | for (Iterator i = telephoneNumbers.iterator(); i.hasNext();) |
164 | |
{ |
165 | 0 | TelephoneNumber number = (TelephoneNumber) i.next(); |
166 | 0 | if (phoneType.equals(number.getType())) |
167 | |
{ |
168 | 0 | filteredNumbers.add(number); |
169 | |
} |
170 | 0 | } |
171 | |
} |
172 | 0 | return filteredNumbers; |
173 | |
} |
174 | |
|
175 | |
public void setTelephoneNumbers(Collection collection) throws JAXRException |
176 | |
{ |
177 | |
|
178 | 0 | Set<TelephoneNumber> numbers = new HashSet<TelephoneNumber>(collection.size()); |
179 | 0 | for (Object number : collection) { |
180 | 0 | numbers.add((TelephoneNumber) number); |
181 | |
} |
182 | 0 | this.telephoneNumbers = numbers; |
183 | 0 | } |
184 | |
|
185 | |
public void addService(Service service) throws JAXRException |
186 | |
{ |
187 | 0 | services.add(service); |
188 | |
|
189 | |
|
190 | |
|
191 | |
|
192 | |
|
193 | |
|
194 | 0 | service.setProvidingOrganization(this); |
195 | 0 | } |
196 | |
|
197 | |
public void addServices(Collection collection) throws JAXRException |
198 | |
{ |
199 | |
|
200 | 0 | for (Iterator iterator = collection.iterator(); iterator.hasNext();) |
201 | |
{ |
202 | 0 | Service service = (Service) iterator.next(); |
203 | |
|
204 | 0 | addService(service); |
205 | 0 | } |
206 | 0 | } |
207 | |
|
208 | |
public Collection<Service> getServices() throws JAXRException |
209 | |
{ |
210 | 0 | return services; |
211 | |
} |
212 | |
|
213 | |
public void removeService(Service service) throws JAXRException |
214 | |
{ |
215 | 0 | services.remove(service); |
216 | 0 | } |
217 | |
|
218 | |
public void removeServices(Collection collection) throws JAXRException |
219 | |
{ |
220 | 0 | services.removeAll(collection); |
221 | 0 | } |
222 | |
|
223 | |
|
224 | |
|
225 | |
|
226 | |
|
227 | |
public Organization getParentOrganization() throws JAXRException |
228 | |
{ |
229 | 0 | throw new UnsupportedCapabilityException("Level 1 feature"); |
230 | |
} |
231 | |
|
232 | |
public Collection<Organization> getDescendantOrganizations() throws JAXRException |
233 | |
{ |
234 | 0 | throw new UnsupportedCapabilityException("Level 1 feature"); |
235 | |
} |
236 | |
|
237 | |
public Organization getRootOrganization() throws JAXRException |
238 | |
{ |
239 | 0 | throw new UnsupportedCapabilityException("Level 1 feature"); |
240 | |
} |
241 | |
|
242 | |
public void addChildOrganization(Organization organization) throws JAXRException |
243 | |
{ |
244 | 0 | throw new UnsupportedCapabilityException("Level 1 feature"); |
245 | |
} |
246 | |
|
247 | |
public void addChildOrganizations(Collection collection) throws JAXRException |
248 | |
{ |
249 | 0 | throw new UnsupportedCapabilityException("Level 1 feature"); |
250 | |
} |
251 | |
|
252 | |
public int getChildOrganizationCount() throws JAXRException |
253 | |
{ |
254 | 0 | throw new UnsupportedCapabilityException("Level 1 feature"); |
255 | |
} |
256 | |
|
257 | |
public Collection<Organization> getChildOrganizations() throws JAXRException |
258 | |
{ |
259 | 0 | throw new UnsupportedCapabilityException("Level 1 feature"); |
260 | |
} |
261 | |
|
262 | |
public void removeChildOrganization(Organization organization) throws JAXRException |
263 | |
{ |
264 | 0 | throw new UnsupportedCapabilityException("Level 1 feature"); |
265 | |
} |
266 | |
|
267 | |
public void removeChildOrganizations(Collection collection) throws JAXRException |
268 | |
{ |
269 | 0 | throw new UnsupportedCapabilityException("Level 1 feature"); |
270 | |
} |
271 | |
|
272 | |
public PostalAddress getPostalAddress() throws JAXRException |
273 | |
{ |
274 | 0 | throw new UnsupportedCapabilityException("Level 1 feature"); |
275 | |
} |
276 | |
|
277 | |
public void setPostalAddress(PostalAddress postalAddress) throws JAXRException |
278 | |
{ |
279 | 0 | throw new UnsupportedCapabilityException("Level 1 feature"); |
280 | |
} |
281 | |
} |