1
22
23 package com.liferay.portal.wsrp;
24
25 import com.liferay.util.CollectionFactory;
26
27 import java.util.Iterator;
28 import java.util.Map;
29
30 import oasis.names.tc.wsrp.v1.types.RegistrationContext;
31 import oasis.names.tc.wsrp.v1.types.RegistrationData;
32
33 import org.apache.wsrp4j.exception.WSRPException;
34 import org.apache.wsrp4j.log.LogManager;
35 import org.apache.wsrp4j.log.Logger;
36 import org.apache.wsrp4j.producer.ConsumerRegistry;
37 import org.apache.wsrp4j.producer.Registration;
38 import org.apache.wsrp4j.producer.driver.RegistrationImpl;
39 import org.apache.wsrp4j.producer.provider.DescriptionHandler;
40 import org.apache.wsrp4j.producer.provider.Provider;
41 import org.apache.wsrp4j.util.HandleGenerator;
42 import org.apache.wsrp4j.util.HandleGeneratorFactoryImpl;
43
44
50 public class ConsumerRegistryImpl implements ConsumerRegistry {
51
52 public ConsumerRegistryImpl(Provider provider) throws WSRPException {
53 String MN = "Constructor";
54 if (_logger.isLogging(Logger.TRACE_HIGH)) {
55 _logger.entry(Logger.TRACE_HIGH, MN);
56 }
57
58 this._provider = provider;
59
60 if (provider != null) {
61
62 DescriptionHandler descrHandler = null;
63
64 if ((descrHandler = provider.getDescriptionHandler()) != null) {
65 _requiresRegistration = descrHandler.isRegistrationRequired();
66 }
67 }
68
69 _genFactory = new HandleGeneratorFactoryImpl();
70 _generator = _genFactory.getHandleGenerator();
71
72 _registrations = CollectionFactory.getSyncHashMap();
73
74 if (_logger.isLogging(Logger.TRACE_MEDIUM)) {
76 _logger.text(Logger.TRACE_MEDIUM, MN,
77 "ConsumerRegistry successfully constructed.");
78 }
79
80 if (_logger.isLogging(Logger.TRACE_HIGH)) {
81 _logger.exit(Logger.TRACE_HIGH, MN);
82 }
83
84 }
85
86
92 public boolean isRegistrationRequired() {
93
94 return this._requiresRegistration;
95
96 }
97
98
109 public Registration register(RegistrationData registrationData)
110 throws WSRPException {
111
112 String MN = "register";
113 if (_logger.isLogging(Logger.TRACE_HIGH)) {
114 _logger.entry(Logger.TRACE_HIGH, MN);
115 }
116
117 Registration newRegistration = new RegistrationImpl();
118
119 RegistrationContext newContext = new RegistrationContext();
120
121 newContext.setRegistrationHandle(_generator.generateHandle());
122 newContext.setRegistrationState(null);
123 newContext.setExtensions(null);
124
125 newRegistration.setRegistrationData(registrationData);
127 newRegistration.setRegistrationContext(newContext);
128
129 _registrations.put(newContext.getRegistrationHandle(), newRegistration);
131
132 if (_logger.isLogging(Logger.TRACE_MEDIUM)) {
133 _logger.text(Logger.TRACE_MEDIUM, MN,
134 "Consumer with registration handle: "
135 + newContext.getRegistrationHandle()
136 + " is registered");
137 }
138
139 if (_logger.isLogging(Logger.TRACE_HIGH)) {
140 _logger.exit(Logger.TRACE_HIGH, MN);
141 }
142
143 return newRegistration;
144 }
145
146
154 public Registration get(String regHandle) {
155 return (Registration) _registrations.get(regHandle);
156 }
157
158
165 public Iterator getAll() {
166 return _registrations.values().iterator();
167 }
168
169
176 public void deregister(String regHandle) {
177
178 String MN = "deregister";
179 if (_logger.isLogging(Logger.TRACE_HIGH)) {
180 _logger.entry(Logger.TRACE_HIGH, MN);
181 }
182
183 _registrations.remove(regHandle);
184
185 if (_logger.isLogging(Logger.TRACE_MEDIUM)) {
186 _logger.text(Logger.TRACE_MEDIUM, MN,
187 "Consumer with registration handle: " + regHandle
188 + " is now deregistered.");
189 }
190
191 if (_logger.isLogging(Logger.TRACE_HIGH)) {
192 _logger.exit(Logger.TRACE_HIGH, MN);
193 }
194 }
195
196
205 public boolean check(String regHandle) {
206
207 String MN = "check";
208 if (_logger.isLogging(Logger.TRACE_HIGH)) {
209 _logger.entry(Logger.TRACE_HIGH, MN);
210 }
211
212 boolean regExists = false;
214 if (_registrations.get(regHandle) != null) {
215 regExists = true;
216
217 if (_logger.isLogging(Logger.TRACE_MEDIUM)) {
218 _logger.text(Logger.TRACE_MEDIUM, MN,
219 "Consumer with registration handle: " + regHandle
220 + " is registered");
221 }
222 }
223
224 if (_logger.isLogging(Logger.TRACE_HIGH)) {
225 _logger.exit(Logger.TRACE_HIGH, MN);
226 }
227 return regExists;
228 }
229
230 private HandleGeneratorFactoryImpl _genFactory = null;
232
233 private HandleGenerator _generator = null;
235
236 private boolean _requiresRegistration = false;
238
239 private Provider _provider = null;
241
242 private Map _registrations = null;
244
245 private Logger _logger = LogManager.getLogManager().getLogger(
247 this.getClass());
248
249 }