1 17 18 19 package org.apache.tomcat.util.modeler.modules; 20 21 import java.io.InputStream ; 22 import java.util.ArrayList ; 23 import java.util.List ; 24 25 import org.apache.commons.logging.Log; 26 import org.apache.commons.logging.LogFactory; 27 import org.apache.tomcat.util.DomUtil; 28 import org.apache.tomcat.util.modeler.AttributeInfo; 29 import org.apache.tomcat.util.modeler.ManagedBean; 30 import org.apache.tomcat.util.modeler.NotificationInfo; 31 import org.apache.tomcat.util.modeler.OperationInfo; 32 import org.apache.tomcat.util.modeler.ParameterInfo; 33 import org.apache.tomcat.util.modeler.Registry; 34 import org.w3c.dom.Document ; 35 import org.w3c.dom.Node ; 36 37 38 public class MbeansDescriptorsDOMSource extends ModelerSource 39 { 40 private static Log log = LogFactory.getLog(MbeansDescriptorsDOMSource.class); 41 42 Registry registry; 43 String location; 44 String type; 45 Object source; 46 List mbeans=new ArrayList (); 47 48 public void setRegistry(Registry reg) { 49 this.registry=reg; 50 } 51 52 public void setLocation( String loc ) { 53 this.location=loc; 54 } 55 56 60 public void setType( String type ) { 61 this.type=type; 62 } 63 64 public void setSource( Object source ) { 65 this.source=source; 66 } 67 68 public List loadDescriptors( Registry registry, String location, 69 String type, Object source) 70 throws Exception 71 { 72 setRegistry(registry); 73 setLocation(location); 74 setType(type); 75 setSource(source); 76 execute(); 77 return mbeans; 78 } 79 80 public void execute() throws Exception { 81 if( registry==null ) registry=Registry.getRegistry(); 82 83 try { 84 InputStream stream=(InputStream )source; 85 long t1=System.currentTimeMillis(); 86 Document doc=DomUtil.readXml(stream); 87 Node descriptorsN=doc.getDocumentElement(); 89 if( descriptorsN == null ) { 91 log.error("No descriptors found"); 92 return; 93 } 94 95 Node firstMbeanN=null; 96 if( "mbean".equals( descriptorsN.getNodeName() ) ) { 97 firstMbeanN=descriptorsN; 98 } else { 99 firstMbeanN=DomUtil.getChild(descriptorsN, "mbean"); 100 } 101 102 if( firstMbeanN==null ) { 103 log.error(" No mbean tags "); 104 return; 105 } 106 107 for (Node mbeanN = firstMbeanN; mbeanN != null; 109 mbeanN= DomUtil.getNext(mbeanN)) 110 { 111 112 ManagedBean managed=new ManagedBean(); 114 DomUtil.setAttributes(managed, mbeanN); 115 Node firstN; 116 117 130 131 firstN=DomUtil.getChild( mbeanN, "attribute"); 133 for (Node descN = firstN; descN != null; 134 descN = DomUtil.getNext( descN )) 135 { 136 137 AttributeInfo ai=new AttributeInfo(); 139 DomUtil.setAttributes(ai, descN); 140 141 155 156 managed.addAttribute( ai ); 158 if (log.isTraceEnabled()) { 159 log.trace("Create attribute " + ai); 160 } 161 162 } 163 164 205 206 firstN=DomUtil.getChild( mbeanN, "notification"); 208 for (Node descN = firstN; descN != null; 209 descN = DomUtil.getNext( descN )) 210 { 211 212 NotificationInfo ni=new NotificationInfo(); 214 DomUtil.setAttributes(ni, descN); 215 216 229 230 Node firstParamN=DomUtil.getChild( descN, "notification-type"); 232 for (Node paramN = firstParamN; paramN != null; 233 paramN = DomUtil.getNext(paramN)) 234 { 235 ni.addNotifType( DomUtil.getContent(paramN) ); 236 } 237 238 managed.addNotification( ni ); 240 if (log.isTraceEnabled()) { 241 log.trace("Created notification " + ni); 242 } 243 244 } 245 246 firstN=DomUtil.getChild( mbeanN, "operation"); 248 for (Node descN = firstN; descN != null; 249 descN = DomUtil.getNext( descN )) 250 251 { 252 253 OperationInfo oi=new OperationInfo(); 255 DomUtil.setAttributes(oi, descN); 256 257 270 271 Node firstParamN=DomUtil.getChild( descN, "parameter"); 273 for (Node paramN = firstParamN; paramN != null; 274 paramN = DomUtil.getNext(paramN)) 275 { 276 ParameterInfo pi=new ParameterInfo(); 277 DomUtil.setAttributes(pi, paramN); 278 if( log.isTraceEnabled()) 279 log.trace("Add param " + pi.getName()); 280 oi.addParameter( pi ); 281 } 282 283 managed.addOperation( oi ); 285 if( log.isTraceEnabled()) { 286 log.trace("Create operation " + oi); 287 } 288 289 } 290 291 mbeans.add( managed ); 294 295 } 296 297 long t2=System.currentTimeMillis(); 298 log.debug( "Reading descriptors ( dom ) " + (t2-t1)); 299 } catch( Exception ex ) { 300 log.error( "Error reading descriptors ", ex); 301 } 302 } 303 } 304 | Popular Tags |