1 17 18 19 package org.apache.tomcat.util.modeler.modules; 20 21 import java.io.InputStream ; 22 import java.net.URL ; 23 import java.util.ArrayList ; 24 import java.util.List ; 25 26 import org.apache.tomcat.util.digester.Digester; 27 import org.apache.tomcat.util.modeler.Registry; 28 import org.apache.commons.logging.Log; 29 import org.apache.commons.logging.LogFactory; 30 31 public class MbeansDescriptorsDigesterSource extends ModelerSource 32 { 33 private static Log log = 34 LogFactory.getLog(MbeansDescriptorsDigesterSource.class); 35 36 Registry registry; 37 String location; 38 String type; 39 Object source; 40 List mbeans=new ArrayList (); 41 42 protected static Digester createDigester(Registry registry) { 43 44 Digester digester = new Digester(); 45 digester.setNamespaceAware(false); 46 digester.setValidating(false); 47 URL url = Registry.getRegistry(null, null).getClass().getResource 48 ("/org/apache/tomcat/util/modeler/mbeans-descriptors.dtd"); 49 digester.register 50 ("-//Apache Software Foundation//DTD Model MBeans Configuration File", 51 url.toString()); 52 53 digester.addObjectCreate 55 ("mbeans-descriptors/mbean", 56 "org.apache.tomcat.util.modeler.ManagedBean"); 57 digester.addSetProperties 58 ("mbeans-descriptors/mbean"); 59 digester.addSetNext 60 ("mbeans-descriptors/mbean", 61 "add", 62 "java.lang.Object"); 63 64 digester.addObjectCreate 65 ("mbeans-descriptors/mbean/attribute", 66 "org.apache.tomcat.util.modeler.AttributeInfo"); 67 digester.addSetProperties 68 ("mbeans-descriptors/mbean/attribute"); 69 digester.addSetNext 70 ("mbeans-descriptors/mbean/attribute", 71 "addAttribute", 72 "org.apache.tomcat.util.modeler.AttributeInfo"); 73 74 124 digester.addObjectCreate 125 ("mbeans-descriptors/mbean/notification", 126 "org.apache.tomcat.util.modeler.NotificationInfo"); 127 digester.addSetProperties 128 ("mbeans-descriptors/mbean/notification"); 129 digester.addSetNext 130 ("mbeans-descriptors/mbean/notification", 131 "addNotification", 132 "org.apache.tomcat.util.modeler.NotificationInfo"); 133 134 digester.addObjectCreate 135 ("mbeans-descriptors/mbean/notification/descriptor/field", 136 "org.apache.tomcat.util.modeler.FieldInfo"); 137 digester.addSetProperties 138 ("mbeans-descriptors/mbean/notification/descriptor/field"); 139 digester.addSetNext 140 ("mbeans-descriptors/mbean/notification/descriptor/field", 141 "addField", 142 "org.apache.tomcat.util.modeler.FieldInfo"); 143 144 digester.addCallMethod 145 ("mbeans-descriptors/mbean/notification/notification-type", 146 "addNotifType", 0); 147 148 digester.addObjectCreate 149 ("mbeans-descriptors/mbean/operation", 150 "org.apache.tomcat.util.modeler.OperationInfo"); 151 digester.addSetProperties 152 ("mbeans-descriptors/mbean/operation"); 153 digester.addSetNext 154 ("mbeans-descriptors/mbean/operation", 155 "addOperation", 156 "org.apache.tomcat.util.modeler.OperationInfo"); 157 158 digester.addObjectCreate 159 ("mbeans-descriptors/mbean/operation/descriptor/field", 160 "org.apache.tomcat.util.modeler.FieldInfo"); 161 digester.addSetProperties 162 ("mbeans-descriptors/mbean/operation/descriptor/field"); 163 digester.addSetNext 164 ("mbeans-descriptors/mbean/operation/descriptor/field", 165 "addField", 166 "org.apache.tomcat.util.modeler.FieldInfo"); 167 168 digester.addObjectCreate 169 ("mbeans-descriptors/mbean/operation/parameter", 170 "org.apache.tomcat.util.modeler.ParameterInfo"); 171 digester.addSetProperties 172 ("mbeans-descriptors/mbean/operation/parameter"); 173 digester.addSetNext 174 ("mbeans-descriptors/mbean/operation/parameter", 175 "addParameter", 176 "org.apache.tomcat.util.modeler.ParameterInfo"); 177 178 return digester; 179 180 } 181 182 public void setRegistry(Registry reg) { 183 this.registry=reg; 184 } 185 186 public void setLocation( String loc ) { 187 this.location=loc; 188 } 189 190 194 public void setType( String type ) { 195 this.type=type; 196 } 197 198 public void setSource( Object source ) { 199 this.source=source; 200 } 201 202 public List loadDescriptors( Registry registry, String location, 203 String type, Object source) 204 throws Exception 205 { 206 setRegistry(registry); 207 setLocation(location); 208 setType(type); 209 setSource(source); 210 execute(); 211 return mbeans; 212 } 213 214 public void execute() throws Exception { 215 if (registry == null) { 216 registry = Registry.getRegistry(null, null); 217 } 218 219 InputStream stream = (InputStream ) source; 220 221 Digester digester = createDigester(registry); 222 digester.push(mbeans); 224 225 try { 227 digester.parse(stream); 228 } catch (Exception e) { 229 log.error("Error digesting Registry data", e); 230 throw e; 231 } finally { 232 digester.reset(); 233 } 234 235 } 236 } 237 | Popular Tags |