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     */
017    package org.apache.activemq.filter;
018    
019    import javax.annotation.PostConstruct;
020    import org.apache.activemq.command.ActiveMQDestination;
021    import org.apache.activemq.command.ActiveMQQueue;
022    import org.apache.activemq.command.ActiveMQTopic;
023    
024    /**
025     * A base class for entry objects used to construct a destination based policy
026     * map.
027     * 
028     * @version $Revision: 1.1 $
029     * @org.apache.xbean.XBean
030     */
031    public abstract class DestinationMapEntry implements Comparable {
032    
033        private ActiveMQDestination destination;
034    
035        public int compareTo(Object that) {
036            if (that instanceof DestinationMapEntry) {
037                DestinationMapEntry thatEntry = (DestinationMapEntry)that;
038                return ActiveMQDestination.compare(destination, thatEntry.destination);
039            } else if (that == null) {
040                return 1;
041            } else {
042                return getClass().getName().compareTo(that.getClass().getName());
043            }
044        }
045    
046        /**
047         * A helper method to set the destination from a configuration file
048         */
049        public void setQueue(String name) {
050            setDestination(new ActiveMQQueue(name));
051        }
052    
053        /**
054         * A helper method to set the destination from a configuration file
055         */
056        public void setTopic(String name) {
057            setDestination(new ActiveMQTopic(name));
058        }
059    
060        public ActiveMQDestination getDestination() {
061            return destination;
062        }
063    
064        public void setDestination(ActiveMQDestination destination) {
065            this.destination = destination;
066        }
067    
068        /**
069         *
070         * @throws Exception
071         * @org.apache.xbean.InitMethod
072         */
073        @PostConstruct
074        public void afterPropertiesSet() throws Exception {
075            if (destination == null) {
076                throw new IllegalArgumentException("You must specify the 'destination' property");
077            }
078        }
079    
080        public Object getValue() {
081            return this;
082        }
083    }