KickJava   Java API By Example, From Geeks To Geeks.

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


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.ArrayList JavaDoc;
21 import java.util.Iterator JavaDoc;
22 import java.util.List JavaDoc;
23
24 public abstract class ResultTransformFilter implements QueryFilter {
25     private QueryFilter next;
26
27     /**
28      * Contructs a query filter that transform the format of the query result
29      * @param next - the query filter to retrieve the results from
30      */

31     protected ResultTransformFilter(QueryFilter next) {
32         this.next = next;
33     }
34
35     /**
36      * Transforms the queried results to a collection of different objects
37      * @param query - the query string
38      * @return collections of transformed objects
39      * @throws Exception
40      */

41     public List JavaDoc query(String JavaDoc query) throws Exception JavaDoc {
42         return transformList(next.query(query));
43     }
44
45     /**
46      * Transforms the queried results to a collection of different objects
47      * @param queries - the query map
48      * @return collections of transformed objects
49      * @throws Exception
50      */

51     public List JavaDoc query(List JavaDoc queries) throws Exception JavaDoc {
52         return transformList(next.query(queries));
53     }
54
55     /**
56      * Transforms a collection to a collection of different objects.
57      * @param result - the collection to transform
58      * @return collection of properties objects
59      */

60     protected List JavaDoc transformList(List JavaDoc result) throws Exception JavaDoc {
61         List JavaDoc props = new ArrayList JavaDoc();
62
63         for (Iterator JavaDoc i=result.iterator(); i.hasNext();) {
64             props.add(transformElement(i.next()));
65         }
66
67         return props;
68     }
69
70     /**
71      * Transform a result object
72      * @param obj - the object instance to transform
73      * @return the transformed object
74      */

75     protected abstract Object JavaDoc transformElement(Object JavaDoc obj) throws Exception JavaDoc;
76
77 }
78
Popular Tags