1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   *
13   */
14  
15  package com.liferay.portal.pop;
16  
17  import com.liferay.portal.kernel.log.Log;
18  import com.liferay.portal.kernel.log.LogFactoryUtil;
19  import com.liferay.portal.kernel.pop.MessageListener;
20  import com.liferay.portal.kernel.pop.MessageListenerException;
21  
22  import javax.mail.Message;
23  
24  /**
25   * <a href="MessageListenerWrapper.java.html"><b><i>View Source</i></b></a>
26   *
27   * @author Brian Wing Shun Chan
28   */
29  public class MessageListenerWrapper implements MessageListener {
30  
31      public MessageListenerWrapper(MessageListener listener) {
32          _listener = listener;
33      }
34  
35      public boolean accept(String from, String recipient, Message message) {
36          if (_log.isDebugEnabled()) {
37              _log.debug("Listener " + _listener.getClass().getName());
38              _log.debug("From " + from);
39              _log.debug("Recipient " + recipient);
40          }
41  
42          boolean value = _listener.accept(from, recipient, message);
43  
44          if (_log.isDebugEnabled()) {
45              _log.debug("Accept " + value);
46          }
47  
48          return value;
49      }
50  
51      public void deliver(String from, String recipient, Message message)
52          throws MessageListenerException {
53  
54          if (_log.isDebugEnabled()) {
55              _log.debug("Listener " + _listener.getClass().getName());
56              _log.debug("From " + from);
57              _log.debug("Recipient " + recipient);
58              _log.debug("Message " + message);
59          }
60  
61          _listener.deliver(from, recipient, message);
62      }
63  
64      public String getId() {
65          return _listener.getId();
66      }
67  
68      public boolean equals(Object obj) {
69          if (obj == null) {
70              return false;
71          }
72  
73          MessageListenerWrapper listener = null;
74  
75          try {
76              listener = (MessageListenerWrapper)obj;
77          }
78          catch (ClassCastException cce) {
79              return false;
80          }
81  
82          String id = listener.getId();
83  
84          return getId().equals(id);
85      }
86  
87      public int hashCode() {
88          return _listener.getId().hashCode();
89      }
90  
91      private static Log _log = LogFactoryUtil.getLog(
92          MessageListenerWrapper.class);
93  
94      private MessageListener _listener;
95  
96  }