KickJava   Java API By Example, From Geeks To Geeks.

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


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.Set JavaDoc;
21 import java.util.Map JavaDoc;
22 import java.util.HashMap JavaDoc;
23 import java.util.Iterator JavaDoc;
24
25 public class GroupPropertiesViewFilter extends PropertiesViewFilter {
26
27     /**
28      * Creates a group properties filter that is able to filter the display result based on a group prefix
29      * @param next - the next query filter
30      */

31     public GroupPropertiesViewFilter(QueryFilter next) {
32         super(next);
33     }
34
35     /**
36      * Creates a group properties filter that is able to filter the display result based on a group prefix
37      * @param groupView - the group filter to use
38      * @param next - the next query filter
39      */

40     public GroupPropertiesViewFilter(Set JavaDoc groupView, QueryFilter next) {
41         super(groupView, next);
42     }
43
44     /**
45      * Filter the properties that matches the group prefix only.
46      * @param data - map data to filter
47      * @return - filtered map data
48      */

49     protected Map JavaDoc filterView(Map JavaDoc data) {
50         // If no view specified, display all attributes
51
if (viewFilter == null || viewFilter.isEmpty()) {
52             return data;
53         }
54
55         Map JavaDoc newData;
56         try {
57             // Lets try to use the same class as the original
58
newData = (Map JavaDoc)data.getClass().newInstance();
59         } catch (Exception JavaDoc e) {
60             // Lets use a default HashMap
61
newData = new HashMap JavaDoc();
62         }
63
64         // Filter the keys to view
65
for (Iterator JavaDoc i=data.keySet().iterator(); i.hasNext();) {
66             String JavaDoc key = (String JavaDoc)i.next();
67
68             // Checks if key matches any of the group filter
69
for (Iterator JavaDoc j=viewFilter.iterator(); j.hasNext();) {
70                 String JavaDoc group = (String JavaDoc)j.next();
71                 if (key.startsWith(group)) {
72                     newData.put(key, data.get(key));
73                     break;
74                 }
75             }
76         }
77
78         return newData;
79     }
80 }
81
Popular Tags