1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
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      private static Log _log = LogFactoryUtil.getLog(
88          MessageListenerWrapper.class);
89  
90      private MessageListener _listener;
91  
92  }