001/**
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  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 */
017package org.apache.activemq.advisory;
018
019import org.apache.activemq.broker.region.virtual.CompositeDestination;
020import org.apache.activemq.broker.region.virtual.VirtualDestination;
021import org.apache.activemq.broker.region.virtual.VirtualTopic;
022import org.apache.activemq.command.ActiveMQDestination;
023import org.apache.activemq.command.ActiveMQQueue;
024import org.apache.activemq.filter.DestinationFilter;
025
026/**
027 * This class will use a destination filter to see if the activeMQ destination matches
028 * the given virtual destination
029 *
030 */
031public class DestinationFilterVirtualDestinationMatcher implements VirtualDestinationMatcher {
032
033    /* (non-Javadoc)
034     * @see org.apache.activemq.advisory.VirtualDestinationMatcher#matches(org.apache.activemq.broker.region.virtual.VirtualDestination)
035     */
036    @Override
037    public boolean matches(VirtualDestination virtualDestination, ActiveMQDestination activeMQDest) {
038        if (virtualDestination instanceof CompositeDestination) {
039            DestinationFilter filter = DestinationFilter.parseFilter(virtualDestination.getMappedDestinations());
040            if (filter.matches(activeMQDest)) {
041                return true;
042            }
043        } else if (virtualDestination instanceof VirtualTopic) {
044            DestinationFilter filter = DestinationFilter.parseFilter(new ActiveMQQueue(((VirtualTopic) virtualDestination).getPrefix() + DestinationFilter.ANY_DESCENDENT));
045            if (filter.matches(activeMQDest)) {
046                return true;
047            }
048        }
049
050        return false;
051    }
052
053}