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