KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > activemq > filter > DestinationFilter


1 /**
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one or more
4  * contributor license agreements. See the NOTICE file distributed with
5  * this work for additional information regarding copyright ownership.
6  * The ASF licenses this file to You under the Apache License, Version 2.0
7  * (the "License"); you may not use this file except in compliance with
8  * the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18
19 package org.apache.activemq.filter;
20
21 import java.io.IOException JavaDoc;
22
23 import javax.jms.JMSException JavaDoc;
24
25 import org.apache.activemq.command.ActiveMQDestination;
26 import org.apache.activemq.util.JMSExceptionSupport;
27
28
29 /**
30  * Represents a filter which only operates on Destinations
31  *
32  * @version $Revision: 1.3 $
33  */

34 public abstract class DestinationFilter implements BooleanExpression {
35     
36     public static final String JavaDoc ANY_DESCENDENT = ">";
37     public static final String JavaDoc ANY_CHILD = "*";
38
39     public Object JavaDoc evaluate(MessageEvaluationContext message) throws JMSException JavaDoc {
40         return matches(message) ? Boolean.TRUE : Boolean.FALSE;
41     }
42     
43     public boolean matches(MessageEvaluationContext message) throws JMSException JavaDoc {
44         try {
45             if( message.isDropped() )
46                 return false;
47             return matches(message.getMessage().getDestination());
48         } catch (IOException JavaDoc e) {
49             throw JMSExceptionSupport.create(e);
50         }
51     }
52
53     public abstract boolean matches(ActiveMQDestination destination);
54
55     public static DestinationFilter parseFilter(ActiveMQDestination destination) {
56         if (destination.isComposite()) {
57             return new CompositeDestinationFilter(destination);
58         }
59         String JavaDoc[] paths = DestinationPath.getDestinationPaths(destination);
60         int idx = paths.length - 1;
61         if (idx >= 0) {
62             String JavaDoc lastPath = paths[idx];
63             if (lastPath.equals(ANY_DESCENDENT)) {
64                 return new PrefixDestinationFilter(paths);
65             }
66             else {
67                 while (idx >= 0) {
68                     lastPath = paths[idx--];
69                     if (lastPath.equals(ANY_CHILD)) {
70                         return new WildcardDestinationFilter(paths);
71                     }
72                 }
73             }
74         }
75
76         // if none of the paths contain a wildcard then use equality
77
return new SimpleDestinationFilter(destination);
78     }
79 }
80
Popular Tags