KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > catalina > startup > SetNextNamingRule


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

18
19
20 package org.apache.catalina.startup;
21
22 import org.apache.catalina.Context;
23 import org.apache.catalina.deploy.NamingResources;
24 import org.apache.tomcat.util.IntrospectionUtils;
25 import org.apache.tomcat.util.digester.Rule;
26
27
28 /**
29  * <p>Rule implementation that calls a method on the (top-1) (parent)
30  * object, passing the top object (child) as an argument. It is
31  * commonly used to establish parent-child relationships.</p>
32  *
33  * <p>This rule now supports more flexible method matching by default.
34  * It is possible that this may break (some) code
35  * written against release 1.1.1 or earlier.
36  * </p>
37  */

38
39 public class SetNextNamingRule extends Rule {
40
41
42     // ----------------------------------------------------------- Constructors
43

44     
45     /**
46      * Construct a "set next" rule with the specified method name.
47      *
48      * @param methodName Method name of the parent method to call
49      * @param paramType Java class of the parent method's argument
50      * (if you wish to use a primitive type, specify the corresonding
51      * Java wrapper class instead, such as <code>java.lang.Boolean</code>
52      * for a <code>boolean</code> parameter)
53      */

54     public SetNextNamingRule(String JavaDoc methodName,
55                        String JavaDoc paramType) {
56
57         this.methodName = methodName;
58         this.paramType = paramType;
59
60     }
61
62
63     // ----------------------------------------------------- Instance Variables
64

65
66     /**
67      * The method name to call on the parent object.
68      */

69     protected String JavaDoc methodName = null;
70
71
72     /**
73      * The Java class name of the parameter type expected by the method.
74      */

75     protected String JavaDoc paramType = null;
76
77
78     // --------------------------------------------------------- Public Methods
79

80
81     /**
82      * Process the end of this element.
83      */

84     public void end() throws Exception JavaDoc {
85
86         // Identify the objects to be used
87
Object JavaDoc child = digester.peek(0);
88         Object JavaDoc parent = digester.peek(1);
89
90         NamingResources namingResources = null;
91         if (parent instanceof Context) {
92             namingResources = ((Context) parent).getNamingResources();
93         } else {
94             namingResources = (NamingResources) parent;
95         }
96         
97         // Call the specified method
98
IntrospectionUtils.callMethod1(namingResources, methodName,
99                 child, paramType, digester.getClassLoader());
100
101     }
102
103
104     /**
105      * Render a printable version of this Rule.
106      */

107     public String JavaDoc toString() {
108
109         StringBuffer JavaDoc sb = new StringBuffer JavaDoc("SetNextRule[");
110         sb.append("methodName=");
111         sb.append(methodName);
112         sb.append(", paramType=");
113         sb.append(paramType);
114         sb.append("]");
115         return (sb.toString());
116
117     }
118
119
120 }
121
Popular Tags