| MessageListenerWrapper.java |
1 /**
2 * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 * SOFTWARE.
21 */
22
23 package com.liferay.portal.pop;
24
25 import com.liferay.portal.kernel.pop.MessageListener;
26 import com.liferay.portal.kernel.pop.MessageListenerException;
27
28 import javax.mail.Message;
29
30 import org.apache.commons.logging.Log;
31 import org.apache.commons.logging.LogFactory;
32
33 /**
34 * <a href="MessageListenerWrapper.java.html"><b><i>View Source</i></b></a>
35 *
36 * @author Brian Wing Shun Chan
37 *
38 */
39 public class MessageListenerWrapper implements MessageListener {
40
41 public MessageListenerWrapper(MessageListener listener) {
42 _listener = listener;
43 }
44
45 public boolean accept(String from, String recipient) {
46 if (_log.isDebugEnabled()) {
47 _log.debug("Listener " + _listener.getClass().getName());
48 _log.debug("From " + from);
49 _log.debug("Recipient " + recipient);
50 }
51
52 boolean value = _listener.accept(from, recipient);
53
54 if (_log.isDebugEnabled()) {
55 _log.debug("Accept " + value);
56 }
57
58 return value;
59 }
60
61 public void deliver(String from, String recipient, Message message)
62 throws MessageListenerException {
63
64 if (_log.isDebugEnabled()) {
65 _log.debug("Listener " + _listener.getClass().getName());
66 _log.debug("From " + from);
67 _log.debug("Recipient " + recipient);
68 _log.debug("Message " + message);
69 }
70
71 _listener.deliver(from, recipient, message);
72 }
73
74 public String getId() {
75 return _listener.getId();
76 }
77
78 public boolean equals(Object obj) {
79 if (obj == null) {
80 return false;
81 }
82
83 MessageListenerWrapper listener = null;
84
85 try {
86 listener = (MessageListenerWrapper)obj;
87 }
88 catch (ClassCastException cce) {
89 return false;
90 }
91
92 String id = listener.getId();
93
94 if (getId().equals(id)) {
95 return true;
96 }
97 else {
98 return false;
99 }
100 }
101
102 private static Log _log = LogFactory.getLog(MessageListenerWrapper.class);
103
104 private MessageListener _listener;
105
106 }