1 16 17 18 package org.apache.commons.modeler; 19 20 21 import java.util.HashSet ; 22 23 import javax.management.AttributeChangeNotification ; 24 import javax.management.Notification ; 25 import javax.management.NotificationFilter ; 26 27 28 37 38 public class BaseAttributeFilter implements NotificationFilter { 39 40 41 43 44 51 public BaseAttributeFilter(String name) { 52 53 super(); 54 if (name != null) 55 addAttribute(name); 56 57 } 58 59 60 62 63 67 private HashSet names = new HashSet (); 68 69 70 72 73 78 public void addAttribute(String name) { 79 80 synchronized (names) { 81 names.add(name); 82 } 83 84 } 85 86 87 91 public void clear() { 92 93 synchronized (names) { 94 names.clear(); 95 } 96 97 } 98 99 100 105 public String [] getNames() { 106 107 synchronized (names) { 108 return ((String []) names.toArray(new String [names.size()])); 109 } 110 111 } 112 113 114 124 public boolean isNotificationEnabled(Notification notification) { 125 126 if (notification == null) 127 return (false); 128 if (!(notification instanceof AttributeChangeNotification )) 129 return (false); 130 AttributeChangeNotification acn = 131 (AttributeChangeNotification ) notification; 132 if (!AttributeChangeNotification.ATTRIBUTE_CHANGE.equals(acn.getType())) 133 return (false); 134 synchronized (names) { 135 if (names.size() < 1) 136 return (true); 137 else 138 return (names.contains(acn.getAttributeName())); 139 } 140 141 } 142 143 144 150 public void removeAttribute(String name) { 151 152 synchronized (names) { 153 names.remove(name); 154 } 155 156 } 157 158 159 } 160 | Popular Tags |