001: /**
002: * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
003: *
004: * Permission is hereby granted, free of charge, to any person obtaining a copy
005: * of this software and associated documentation files (the "Software"), to deal
006: * in the Software without restriction, including without limitation the rights
007: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
008: * copies of the Software, and to permit persons to whom the Software is
009: * furnished to do so, subject to the following conditions:
010: *
011: * The above copyright notice and this permission notice shall be included in
012: * all copies or substantial portions of the Software.
013: *
014: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
015: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
016: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
017: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
018: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
019: * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
020: * SOFTWARE.
021: */package com.liferay.portal.pop;
022:
023: import com.liferay.portal.kernel.pop.MessageListener;
024: import com.liferay.portal.kernel.pop.MessageListenerException;
025:
026: import javax.mail.Message;
027:
028: import org.apache.commons.logging.Log;
029: import org.apache.commons.logging.LogFactory;
030:
031: /**
032: * <a href="MessageListenerWrapper.java.html"><b><i>View Source</i></b></a>
033: *
034: * @author Brian Wing Shun Chan
035: *
036: */
037: public class MessageListenerWrapper implements MessageListener {
038:
039: public MessageListenerWrapper(MessageListener listener) {
040: _listener = listener;
041: }
042:
043: public boolean accept(String from, String recipient) {
044: if (_log.isDebugEnabled()) {
045: _log.debug("Listener " + _listener.getClass().getName());
046: _log.debug("From " + from);
047: _log.debug("Recipient " + recipient);
048: }
049:
050: boolean value = _listener.accept(from, recipient);
051:
052: if (_log.isDebugEnabled()) {
053: _log.debug("Accept " + value);
054: }
055:
056: return value;
057: }
058:
059: public void deliver(String from, String recipient, Message message)
060: throws MessageListenerException {
061:
062: if (_log.isDebugEnabled()) {
063: _log.debug("Listener " + _listener.getClass().getName());
064: _log.debug("From " + from);
065: _log.debug("Recipient " + recipient);
066: _log.debug("Message " + message);
067: }
068:
069: _listener.deliver(from, recipient, message);
070: }
071:
072: public String getId() {
073: return _listener.getId();
074: }
075:
076: public boolean equals(Object obj) {
077: if (obj == null) {
078: return false;
079: }
080:
081: MessageListenerWrapper listener = null;
082:
083: try {
084: listener = (MessageListenerWrapper) obj;
085: } catch (ClassCastException cce) {
086: return false;
087: }
088:
089: String id = listener.getId();
090:
091: if (getId().equals(id)) {
092: return true;
093: } else {
094: return false;
095: }
096: }
097:
098: private static Log _log = LogFactory
099: .getLog(MessageListenerWrapper.class);
100:
101: private MessageListener _listener;
102:
103: }
|