1 22 package org.jboss.system.filterfactory; 23 24 import java.util.Set ; 25 import java.util.Vector ; 26 27 import javax.management.Notification ; 28 import javax.management.NotificationFilter ; 29 30 import org.jboss.deployment.DeploymentInfo; 31 import org.jboss.mx.util.JBossNotificationFilterSupport; 32 import org.jboss.system.NotificationFilterFactory; 33 import org.jboss.util.collection.CollectionsFactory; 34 import org.w3c.dom.Element ; 35 import org.w3c.dom.Node ; 36 import org.w3c.dom.NodeList ; 37 38 78 public class DeploymentInfoNotificationFilterFactory 79 implements NotificationFilterFactory 80 { 81 83 84 public static final String ENABLE_ELEMENT = "enable"; 85 public static final String ENABLE_TYPE_ATTRIBUTE = "type"; 86 public static final String ENABLE_SHORTNAME_ATTRIBUTE = "short-name"; 87 88 91 public DeploymentInfoNotificationFilterFactory() 92 { 93 } 95 96 99 public NotificationFilter createNotificationFilter(Element filterConfig) 100 throws Exception 101 { 102 DeploymentInfoNotificationFilter filter = new DeploymentInfoNotificationFilter(); 104 105 NodeList filterChildren = filterConfig.getChildNodes(); 108 109 for (int i = 0; i < filterChildren.getLength(); i++) 110 { 111 Node filterChildNode = filterChildren.item(i); 112 113 if (filterChildNode.getNodeName().equals(ENABLE_ELEMENT)) 115 { 116 if (((Element )filterChildNode).hasAttribute(ENABLE_TYPE_ATTRIBUTE)) 118 { 119 String type = ((Element )filterChildNode).getAttribute(ENABLE_TYPE_ATTRIBUTE); 120 filter.enableType(type); 122 } 123 else if (((Element )filterChildNode).hasAttribute(ENABLE_SHORTNAME_ATTRIBUTE)) 124 { 125 String shortName = ((Element )filterChildNode).getAttribute(ENABLE_SHORTNAME_ATTRIBUTE); 126 filter.enableShortName(shortName); 128 } 129 else 130 { 131 throw new Exception ("'" + ENABLE_ELEMENT + "' element must have a '" 132 + ENABLE_TYPE_ATTRIBUTE + "' or a '" + ENABLE_SHORTNAME_ATTRIBUTE + "' attribute"); 133 } 134 } 135 } 136 return filter; 138 } 139 140 149 public static class DeploymentInfoNotificationFilter extends JBossNotificationFilterSupport 150 { 151 private static final long serialVersionUID = -5067618040005609685L; 152 153 154 private Set enabledShortNames; 155 156 158 163 public DeploymentInfoNotificationFilter() 164 { 165 super(); 166 enabledShortNames = CollectionsFactory.createCopyOnWriteSet(); 167 } 168 169 172 public void disableAllShortNames() 173 { 174 enabledShortNames.clear(); 175 } 176 177 182 public void disableShortName(String name) 183 { 184 enabledShortNames.remove(name); 185 } 186 187 193 public void enableShortName(String name) throws IllegalArgumentException 194 { 195 if (name == null) 196 { 197 throw new IllegalArgumentException ("null shortName"); 198 } 199 enabledShortNames.add(name); 200 } 201 202 210 public Vector getEnabledShortNames() 211 { 212 return new Vector (enabledShortNames); 213 } 214 215 218 public String toString() 219 { 220 StringBuffer sb = new StringBuffer (100); 221 222 sb.append(getClass().getName()).append(':'); 223 sb.append(" enabledTypes=").append(getEnabledTypes()); 224 sb.append(" enabledShortNames=").append(getEnabledShortNames()); 225 226 return sb.toString(); 227 } 228 229 231 238 public boolean isNotificationEnabled(Notification notification) 239 { 240 if (super.isNotificationEnabled(notification) == false) 242 { 243 return false; 244 } 245 246 DeploymentInfo di = (DeploymentInfo)notification.getUserData(); 250 String shortName = di.shortName; 251 252 return enabledShortNames.contains(shortName); 254 } 255 } 256 } 257 | Popular Tags |