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