KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > activemq > console > filter > WildcardTransformFilter


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 package org.apache.activemq.console.filter;
19
20 import java.util.Iterator JavaDoc;
21 import java.util.ArrayList JavaDoc;
22 import java.util.List JavaDoc;
23
24 public abstract class WildcardTransformFilter extends AbstractQueryFilter {
25
26     /**
27      * Creates a wildcard transform filter that is able to convert a wildcard expression (determined by isWildcardQuery)
28      * to a another query type (use transformWildcardQuery).
29      * @param next - the next query filter
30      */

31     protected WildcardTransformFilter(QueryFilter next) {
32         super(next);
33     }
34
35     /**
36      * Converts the query list to set of different queries
37      * @param queries - query list to transform
38      * @return - result of the query
39      * @throws Exception
40      */

41     public List JavaDoc query(List JavaDoc queries) throws Exception JavaDoc {
42         List JavaDoc newQueries = new ArrayList JavaDoc();
43
44         for (Iterator JavaDoc i=queries.iterator(); i.hasNext();) {
45             String JavaDoc queryToken = (String JavaDoc)i.next();
46
47             // Transform the wildcard query
48
if (isWildcardQuery(queryToken)) {
49                 // Transform the value part only
50
newQueries.add(transformWildcardQuery(queryToken));
51
52             // Maintain the query as is
53
} else {
54                 newQueries.add(queryToken);
55             }
56         }
57
58         return next.query(newQueries);
59     }
60
61     /**
62      * Use to determine is a query string is a wildcard query
63      * @param query - query string
64      * @return true, if the query string is a wildcard query, false otherwise
65      */

66     protected abstract boolean isWildcardQuery(String JavaDoc query);
67
68     /**
69      * Use to transform a wildcard query string to another query format
70      * @param query - query string to transform
71      * @return transformed query
72      */

73     protected abstract String JavaDoc transformWildcardQuery(String JavaDoc query);
74 }
75
Popular Tags