KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tomcat > util > modeler > modules > MbeansDescriptorsDigesterSource


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18
19 package org.apache.tomcat.util.modeler.modules;
20
21 import java.io.InputStream JavaDoc;
22 import java.net.URL JavaDoc;
23 import java.util.ArrayList JavaDoc;
24 import java.util.List JavaDoc;
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 JavaDoc location;
38     String JavaDoc type;
39     Object JavaDoc source;
40     List JavaDoc mbeans=new ArrayList JavaDoc();
41     
42     protected static Digester createDigester(Registry registry) {
43
44         Digester digester = new Digester();
45         digester.setNamespaceAware(false);
46         digester.setValidating(false);
47         URL JavaDoc 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         // Configure the parsing rules
54
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         /*digester.addObjectCreate
75             ("mbeans-descriptors/mbean/attribute/descriptor/field",
76             "org.apache.tomcat.util.modeler.FieldInfo");
77         digester.addSetProperties
78             ("mbeans-descriptors/mbean/attribute/descriptor/field");
79         digester.addSetNext
80             ("mbeans-descriptors/mbean/attribute/descriptor/field",
81                 "addField",
82             "org.apache.tomcat.util.modeler.FieldInfo");
83         
84         digester.addObjectCreate
85             ("mbeans-descriptors/mbean/constructor",
86             "org.apache.tomcat.util.modeler.ConstructorInfo");
87         digester.addSetProperties
88             ("mbeans-descriptors/mbean/constructor");
89         digester.addSetNext
90             ("mbeans-descriptors/mbean/constructor",
91                 "addConstructor",
92             "org.apache.tomcat.util.modeler.ConstructorInfo");
93         
94         digester.addObjectCreate
95             ("mbeans-descriptors/mbean/constructor/descriptor/field",
96             "org.apache.tomcat.util.modeler.FieldInfo");
97         digester.addSetProperties
98             ("mbeans-descriptors/mbean/constructor/descriptor/field");
99         digester.addSetNext
100             ("mbeans-descriptors/mbean/constructor/descriptor/field",
101                 "addField",
102             "org.apache.tomcat.util.modeler.FieldInfo");
103         
104         digester.addObjectCreate
105             ("mbeans-descriptors/mbean/constructor/parameter",
106             "org.apache.tomcat.util.modeler.ParameterInfo");
107         digester.addSetProperties
108             ("mbeans-descriptors/mbean/constructor/parameter");
109         digester.addSetNext
110             ("mbeans-descriptors/mbean/constructor/parameter",
111                 "addParameter",
112             "org.apache.tomcat.util.modeler.ParameterInfo");
113         
114         digester.addObjectCreate
115             ("mbeans-descriptors/mbean/descriptor/field",
116             "org.apache.tomcat.util.modeler.FieldInfo");
117         digester.addSetProperties
118             ("mbeans-descriptors/mbean/descriptor/field");
119         digester.addSetNext
120             ("mbeans-descriptors/mbean/descriptor/field",
121                 "addField",
122             "org.apache.tomcat.util.modeler.FieldInfo");
123         */

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 JavaDoc loc ) {
187         this.location=loc;
188     }
189
190     /** Used if a single component is loaded
191      *
192      * @param type
193      */

194     public void setType( String JavaDoc type ) {
195        this.type=type;
196     }
197
198     public void setSource( Object JavaDoc source ) {
199         this.source=source;
200     }
201
202     public List JavaDoc loadDescriptors( Registry registry, String JavaDoc location,
203                                  String JavaDoc type, Object JavaDoc source)
204             throws Exception JavaDoc
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 JavaDoc {
215         if (registry == null) {
216             registry = Registry.getRegistry(null, null);
217         }
218
219         InputStream JavaDoc stream = (InputStream JavaDoc) source;
220
221         Digester digester = createDigester(registry);
222         // Push our registry object onto the stack
223
digester.push(mbeans);
224         
225         // Process the input file to configure our registry
226
try {
227             digester.parse(stream);
228         } catch (Exception JavaDoc e) {
229             log.error("Error digesting Registry data", e);
230             throw e;
231         } finally {
232             digester.reset();
233         }
234             
235     }
236 }
237
Popular Tags