1 16 17 18 package org.apache.commons.modeler.modules; 19 20 import java.io.InputStream ; 21 import java.net.URL ; 22 import java.util.ArrayList ; 23 import java.util.List ; 24 25 import org.apache.commons.digester.Digester; 26 import org.apache.commons.logging.Log; 27 import org.apache.commons.logging.LogFactory; 28 import org.apache.commons.modeler.Registry; 29 30 public class MbeansDescriptorsDigesterSource extends ModelerSource 31 { 32 private static Log log = 33 LogFactory.getLog(MbeansDescriptorsDigesterSource.class); 34 35 Registry registry; 36 String location; 37 String type; 38 Object source; 39 List mbeans=new ArrayList (); 40 41 public void setRegistry(Registry reg) { 42 this.registry=reg; 43 } 44 45 public void setLocation( String loc ) { 46 this.location=loc; 47 } 48 49 53 public void setType( String type ) { 54 this.type=type; 55 } 56 57 public void setSource( Object source ) { 58 this.source=source; 59 } 60 61 public List loadDescriptors( Registry registry, String location, 62 String type, Object source) 63 throws Exception 64 { 65 setRegistry(registry); 66 setLocation(location); 67 setType(type); 68 setSource(source); 69 execute(); 70 return mbeans; 71 } 72 73 public void execute() throws Exception { 74 if( registry==null ) registry=Registry.getRegistry(); 75 76 InputStream stream=(InputStream )source; 77 78 long t1=System.currentTimeMillis(); 79 80 Digester digester = new Digester(); 81 digester.setNamespaceAware(false); 82 digester.setValidating(false); 83 URL url = registry.getClass().getResource 84 ("/org/apache/commons/modeler/mbeans-descriptors.dtd"); 85 digester.register 86 ("-//Apache Software Foundation//DTD Model MBeans Configuration File", 87 url.toString()); 88 89 digester.push(mbeans); 91 92 digester.addObjectCreate 94 ("mbeans-descriptors/mbean", 95 "org.apache.commons.modeler.ManagedBean"); 96 digester.addSetProperties 97 ("mbeans-descriptors/mbean"); 98 digester.addSetNext 99 ("mbeans-descriptors/mbean", 100 "add", 101 "java.lang.Object"); 102 103 digester.addObjectCreate 104 ("mbeans-descriptors/mbean/attribute", 105 "org.apache.commons.modeler.AttributeInfo"); 106 digester.addSetProperties 107 ("mbeans-descriptors/mbean/attribute"); 108 digester.addSetNext 109 ("mbeans-descriptors/mbean/attribute", 110 "addAttribute", 111 "org.apache.commons.modeler.AttributeInfo"); 112 113 digester.addObjectCreate 114 ("mbeans-descriptors/mbean/attribute/descriptor/field", 115 "org.apache.commons.modeler.FieldInfo"); 116 digester.addSetProperties 117 ("mbeans-descriptors/mbean/attribute/descriptor/field"); 118 digester.addSetNext 119 ("mbeans-descriptors/mbean/attribute/descriptor/field", 120 "addField", 121 "org.apache.commons.modeler.FieldInfo"); 122 123 digester.addObjectCreate 124 ("mbeans-descriptors/mbean/constructor", 125 "org.apache.commons.modeler.ConstructorInfo"); 126 digester.addSetProperties 127 ("mbeans-descriptors/mbean/constructor"); 128 digester.addSetNext 129 ("mbeans-descriptors/mbean/constructor", 130 "addConstructor", 131 "org.apache.commons.modeler.ConstructorInfo"); 132 133 digester.addObjectCreate 134 ("mbeans-descriptors/mbean/constructor/descriptor/field", 135 "org.apache.commons.modeler.FieldInfo"); 136 digester.addSetProperties 137 ("mbeans-descriptors/mbean/constructor/descriptor/field"); 138 digester.addSetNext 139 ("mbeans-descriptors/mbean/constructor/descriptor/field", 140 "addField", 141 "org.apache.commons.modeler.FieldInfo"); 142 143 digester.addObjectCreate 144 ("mbeans-descriptors/mbean/constructor/parameter", 145 "org.apache.commons.modeler.ParameterInfo"); 146 digester.addSetProperties 147 ("mbeans-descriptors/mbean/constructor/parameter"); 148 digester.addSetNext 149 ("mbeans-descriptors/mbean/constructor/parameter", 150 "addParameter", 151 "org.apache.commons.modeler.ParameterInfo"); 152 153 digester.addObjectCreate 154 ("mbeans-descriptors/mbean/descriptor/field", 155 "org.apache.commons.modeler.FieldInfo"); 156 digester.addSetProperties 157 ("mbeans-descriptors/mbean/descriptor/field"); 158 digester.addSetNext 159 ("mbeans-descriptors/mbean/descriptor/field", 160 "addField", 161 "org.apache.commons.modeler.FieldInfo"); 162 163 digester.addObjectCreate 164 ("mbeans-descriptors/mbean/notification", 165 "org.apache.commons.modeler.NotificationInfo"); 166 digester.addSetProperties 167 ("mbeans-descriptors/mbean/notification"); 168 digester.addSetNext 169 ("mbeans-descriptors/mbean/notification", 170 "addNotification", 171 "org.apache.commons.modeler.NotificationInfo"); 172 173 digester.addObjectCreate 174 ("mbeans-descriptors/mbean/notification/descriptor/field", 175 "org.apache.commons.modeler.FieldInfo"); 176 digester.addSetProperties 177 ("mbeans-descriptors/mbean/notification/descriptor/field"); 178 digester.addSetNext 179 ("mbeans-descriptors/mbean/notification/descriptor/field", 180 "addField", 181 "org.apache.commons.modeler.FieldInfo"); 182 183 digester.addCallMethod 184 ("mbeans-descriptors/mbean/notification/notification-type", 185 "addNotifType", 0); 186 187 digester.addObjectCreate 188 ("mbeans-descriptors/mbean/operation", 189 "org.apache.commons.modeler.OperationInfo"); 190 digester.addSetProperties 191 ("mbeans-descriptors/mbean/operation"); 192 digester.addSetNext 193 ("mbeans-descriptors/mbean/operation", 194 "addOperation", 195 "org.apache.commons.modeler.OperationInfo"); 196 197 digester.addObjectCreate 198 ("mbeans-descriptors/mbean/operation/descriptor/field", 199 "org.apache.commons.modeler.FieldInfo"); 200 digester.addSetProperties 201 ("mbeans-descriptors/mbean/operation/descriptor/field"); 202 digester.addSetNext 203 ("mbeans-descriptors/mbean/operation/descriptor/field", 204 "addField", 205 "org.apache.commons.modeler.FieldInfo"); 206 207 digester.addObjectCreate 208 ("mbeans-descriptors/mbean/operation/parameter", 209 "org.apache.commons.modeler.ParameterInfo"); 210 digester.addSetProperties 211 ("mbeans-descriptors/mbean/operation/parameter"); 212 digester.addSetNext 213 ("mbeans-descriptors/mbean/operation/parameter", 214 "addParameter", 215 "org.apache.commons.modeler.ParameterInfo"); 216 217 try { 219 digester.parse(stream); 220 } catch (Exception e) { 221 log.error("Error digesting Registry data", e); 222 throw e; 223 } 224 long t2=System.currentTimeMillis(); 225 log.info("Loaded registry information (digester) " + ( t2 - t1 ) + " ms"); 227 } 228 } 229 | Popular Tags |