1   /**
2    * Copyright (c) 2000-2009 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   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
12   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
14   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
15   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
16   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
17   * SOFTWARE.
18   */
19  
20  package com.liferay.portal.pop;
21  
22  import com.liferay.portal.kernel.log.Log;
23  import com.liferay.portal.kernel.log.LogFactoryUtil;
24  import com.liferay.portal.kernel.pop.MessageListener;
25  import com.liferay.portal.kernel.pop.MessageListenerException;
26  
27  import javax.mail.Message;
28  
29  /**
30   * <a href="MessageListenerWrapper.java.html"><b><i>View Source</i></b></a>
31   *
32   * @author Brian Wing Shun Chan
33   *
34   */
35  public class MessageListenerWrapper implements MessageListener {
36  
37      public MessageListenerWrapper(MessageListener listener) {
38          _listener = listener;
39      }
40  
41      public boolean accept(String from, String recipient, Message message) {
42          if (_log.isDebugEnabled()) {
43              _log.debug("Listener " + _listener.getClass().getName());
44              _log.debug("From " + from);
45              _log.debug("Recipient " + recipient);
46          }
47  
48          boolean value = _listener.accept(from, recipient, message);
49  
50          if (_log.isDebugEnabled()) {
51              _log.debug("Accept " + value);
52          }
53  
54          return value;
55      }
56  
57      public void deliver(String from, String recipient, Message message)
58          throws MessageListenerException {
59  
60          if (_log.isDebugEnabled()) {
61              _log.debug("Listener " + _listener.getClass().getName());
62              _log.debug("From " + from);
63              _log.debug("Recipient " + recipient);
64              _log.debug("Message " + message);
65          }
66  
67          _listener.deliver(from, recipient, message);
68      }
69  
70      public String getId() {
71          return _listener.getId();
72      }
73  
74      public boolean equals(Object obj) {
75          if (obj == null) {
76              return false;
77          }
78  
79          MessageListenerWrapper listener = null;
80  
81          try {
82              listener = (MessageListenerWrapper)obj;
83          }
84          catch (ClassCastException cce) {
85              return false;
86          }
87  
88          String id = listener.getId();
89  
90          return getId().equals(id);
91      }
92  
93      private static Log _log =
94          LogFactoryUtil.getLog(MessageListenerWrapper.class);
95  
96      private MessageListener _listener;
97  
98  }