001 /**
002 *
003 * Copyright 2004 Protique Ltd
004 *
005 * Licensed under the Apache License, Version 2.0 (the "License");
006 * you may not use this file except in compliance with the License.
007 * You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 *
017 **/
018
019 package org.activemq.filter;
020
021 import org.activemq.message.ActiveMQMessage;
022
023 import javax.jms.JMSException;
024 import javax.jms.Message;
025
026
027 /**
028 * Checks that messages are not filtered by NoLocal
029 *
030 * @version $Revision: 1.1.1.1 $
031 */
032 public class NoLocalFilter implements Filter {
033
034 private String clientId;
035
036 /**
037 * Construct a NoLocalFilter
038 *
039 * @param newClientId
040 */
041 public NoLocalFilter(String newClientId) {
042 this.clientId = newClientId;
043 }
044
045 /**
046 * ensure messages are filtered if they have the same clientId
047 * as the filter
048 *
049 * @param message - the message to match
050 * @return true if the message has a different clientId to the filter
051 * @throws JMSException
052 */
053 public boolean matches(Message message) throws JMSException {
054 if (message != null && message instanceof ActiveMQMessage) {
055 ActiveMQMessage activeMQMessage = (ActiveMQMessage) message;
056
057 if (clientId.equals(activeMQMessage.getJMSClientID())) {
058 return false;
059 }
060 }
061 return true;
062 }
063
064 public boolean isWildcard() {
065 return false;
066 }
067 }