001: /* $Id: SetNextNamingRule.java 467222 2006-10-24 03:17:11Z markt $
002: *
003: * Licensed to the Apache Software Foundation (ASF) under one or more
004: * contributor license agreements. See the NOTICE file distributed with
005: * this work for additional information regarding copyright ownership.
006: * The ASF licenses this file to You under the Apache License, Version 2.0
007: * (the "License"); you may not use this file except in compliance with
008: * the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing, software
013: * distributed under the License is distributed on an "AS IS" BASIS,
014: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015: * See the License for the specific language governing permissions and
016: * limitations under the License.
017: */
018:
019: package org.apache.catalina.startup;
020:
021: import org.apache.catalina.Context;
022: import org.apache.catalina.deploy.NamingResources;
023: import org.apache.tomcat.util.IntrospectionUtils;
024: import org.apache.tomcat.util.digester.Rule;
025:
026: /**
027: * <p>Rule implementation that calls a method on the (top-1) (parent)
028: * object, passing the top object (child) as an argument. It is
029: * commonly used to establish parent-child relationships.</p>
030: *
031: * <p>This rule now supports more flexible method matching by default.
032: * It is possible that this may break (some) code
033: * written against release 1.1.1 or earlier.
034: * </p>
035: */
036:
037: public class SetNextNamingRule extends Rule {
038:
039: // ----------------------------------------------------------- Constructors
040:
041: /**
042: * Construct a "set next" rule with the specified method name.
043: *
044: * @param methodName Method name of the parent method to call
045: * @param paramType Java class of the parent method's argument
046: * (if you wish to use a primitive type, specify the corresonding
047: * Java wrapper class instead, such as <code>java.lang.Boolean</code>
048: * for a <code>boolean</code> parameter)
049: */
050: public SetNextNamingRule(String methodName, String paramType) {
051:
052: this .methodName = methodName;
053: this .paramType = paramType;
054:
055: }
056:
057: // ----------------------------------------------------- Instance Variables
058:
059: /**
060: * The method name to call on the parent object.
061: */
062: protected String methodName = null;
063:
064: /**
065: * The Java class name of the parameter type expected by the method.
066: */
067: protected String paramType = null;
068:
069: // --------------------------------------------------------- Public Methods
070:
071: /**
072: * Process the end of this element.
073: */
074: public void end() throws Exception {
075:
076: // Identify the objects to be used
077: Object child = digester.peek(0);
078: Object parent = digester.peek(1);
079:
080: NamingResources namingResources = null;
081: if (parent instanceof Context) {
082: namingResources = ((Context) parent).getNamingResources();
083: } else {
084: namingResources = (NamingResources) parent;
085: }
086:
087: // Call the specified method
088: IntrospectionUtils.callMethod1(namingResources, methodName,
089: child, paramType, digester.getClassLoader());
090:
091: }
092:
093: /**
094: * Render a printable version of this Rule.
095: */
096: public String toString() {
097:
098: StringBuffer sb = new StringBuffer("SetNextRule[");
099: sb.append("methodName=");
100: sb.append(methodName);
101: sb.append(", paramType=");
102: sb.append(paramType);
103: sb.append("]");
104: return (sb.toString());
105:
106: }
107:
108: }
|