1 18 package org.apache.activemq.console.filter; 19 20 import java.util.Set ; 21 import java.util.Iterator ; 22 import java.util.Map ; 23 import java.util.HashMap ; 24 import java.util.Collection ; 25 import java.util.ArrayList ; 26 import java.util.List ; 27 28 public class PropertiesViewFilter implements QueryFilter { 29 protected QueryFilter next; 30 protected Set viewFilter; 31 32 36 public PropertiesViewFilter(QueryFilter next) { 37 this(null, next); 38 } 39 40 45 public PropertiesViewFilter(Set viewFilter, QueryFilter next) { 46 this.next = next; 47 this.viewFilter = viewFilter; 48 } 49 50 55 public List query(String query) throws Exception { 56 return filterViewCollection(next.query(query), viewFilter); 57 } 58 59 65 public List query(List queries) throws Exception { 66 return filterViewCollection(next.query(queries), viewFilter); 67 } 68 69 75 protected List filterViewCollection(Collection result, Set viewFilter) { 76 List newCollection = new ArrayList (); 78 79 for (Iterator i=result.iterator(); i.hasNext();) { 80 newCollection.add(filterView((Map )i.next())); 81 } 82 83 return newCollection; 84 } 85 86 91 protected Map filterView(Map data) { 92 if (viewFilter == null || viewFilter.isEmpty()) { 94 return data; 95 } 96 97 Map newData; 98 try { 99 newData = (Map )data.getClass().newInstance(); 101 } catch (Exception e) { 102 newData = new HashMap (); 104 } 105 106 for (Iterator i=viewFilter.iterator(); i.hasNext();) { 108 Object key = i.next(); 109 Object val = data.get(key); 110 111 if (val != null) { 112 newData.put(key, val); 113 } 114 } 115 116 return newData; 117 } 118 119 } 120 | Popular Tags |