KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > velocity > tools > view > ToolboxRuleSet


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

16
17 package org.apache.velocity.tools.view;
18
19 import org.apache.commons.digester.Digester;
20 import org.apache.commons.digester.RuleSetBase;
21 import org.apache.velocity.tools.view.DataInfo;
22 import org.apache.velocity.tools.view.ViewToolInfo;
23
24 /**
25  * <p>The set of Digester rules required to parse a toolbox
26  * configuration file (<code>toolbox.xml</code>) for the
27  * XMLToolboxManager class.</p>
28  *
29  * @author <a HREF="mailto:nathan@esha.com">Nathan Bubna</a>
30  * @since VelocityTools 1.1
31  * @version $Id: ToolboxRuleSet.java,v 1.3 2004/02/18 20:08:29 nbubna Exp $
32  */

33 public class ToolboxRuleSet extends RuleSetBase
34 {
35
36     /**
37      * <p>Add the set of Rule instances defined in this RuleSet to the
38      * specified <code>Digester</code> instance, associating them with
39      * our namespace URI (if any). This method should only be called
40      * by a Digester instance. These rules assume that an instance of
41      * <code>org.apache.velocity.tools.view.ToolboxManager</code> is pushed
42      * onto the evaluation stack before parsing begins.</p>
43      *
44      * @param digester Digester instance to which the new Rule instances
45      * should be added.
46      */

47     public void addRuleInstances(Digester digester)
48     {
49         addToolRules(digester);
50         addDataRules(digester);
51     }
52
53
54     /**
55      * Add rules for digesting tool elements.
56      */

57     protected void addToolRules(Digester digester)
58     {
59         digester.addObjectCreate("toolbox/tool", getToolInfoClass());
60         digester.addBeanPropertySetter("toolbox/tool/key", "key");
61         digester.addBeanPropertySetter("toolbox/tool/class", "classname");
62         digester.addSetNext("toolbox/tool", "addTool");
63     }
64
65
66     /**
67      * Add rules for digesting data elements.
68      */

69     protected void addDataRules(Digester digester)
70     {
71         digester.addObjectCreate("toolbox/data", getDataInfoClass());
72         digester.addSetProperties("toolbox/data");
73         digester.addBeanPropertySetter("toolbox/data/key", "key");
74         digester.addBeanPropertySetter("toolbox/data/value", "value");
75         digester.addSetNext("toolbox/data", "addTool");
76     }
77
78
79     /**
80      * Return the bean class to be created for tool elements.
81      */

82     protected Class JavaDoc getToolInfoClass()
83     {
84         return ViewToolInfo.class;
85     }
86
87
88     /**
89      * Return the bean class to be created for data elements.
90      */

91     protected Class JavaDoc getDataInfoClass()
92     {
93         return DataInfo.class;
94     }
95
96 }
97
Popular Tags