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