1 package org.apache.commons.digester3;
2
3 /*
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
19 * under the License.
20 */
21
22
23 /**
24 * <p>
25 * Rule implementation that calls a method on the (top-1) (parent) object, passing the top object (child) as an
26 * argument. It is commonly used to establish parent-child relationships.
27 * </p>
28 * <p>
29 * This rule now supports more flexible method matching by default. It is possible that this may break (some) code
30 * written against release 1.1.1 or earlier. See {@link #isExactMatch()} for more details.
31 * </p>
32 * <p>
33 * Note that while CallMethodRule uses commons-beanutils' data-conversion functionality (ConvertUtils class) to convert
34 * parameter values into the appropriate type for the parameter to the called method, this rule does not. Needing to use
35 * ConvertUtils functionality when building parent-child relationships is expected to be very rare; however if you do
36 * need this then instead of using this rule, create a CallMethodRule specifying targetOffset of 1 in the constructor.
37 * </p>
38 */
39 public class SetNextRule
40 extends AbstractMethodRule
41 {
42
43 // ----------------------------------------------------------- Constructors
44
45 /**
46 * Construct a "set next" rule with the specified method name. The method's argument type is assumed to be the class
47 * of the child object.
48 *
49 * @param methodName Method name of the parent method to call
50 */
51 public SetNextRule( String methodName )
52 {
53 super( methodName );
54 }
55
56 /**
57 * Construct a "set next" rule with the specified method name.
58 *
59 * @param methodName Method name of the parent method to call
60 * @param paramType Java class name of the parent method's argument (if you wish to use a primitive type,
61 * specify the corresonding Java wrapper class instead, such as <code>java.lang.Boolean</code>
62 * for a <code>boolean</code> parameter)
63 */
64 public SetNextRule( String methodName, String paramType )
65 {
66 super( methodName, paramType );
67 }
68
69 /**
70 * Construct a "set next" rule with the specified method name.
71 *
72 * @param methodName Method name of the parent method to call
73 * @param paramType Java class of the parent method's argument (if you wish to use a primitive type, specify the
74 * corresonding Java wrapper class instead, such as <code>java.lang.Boolean</code> for a
75 * <code>boolean</code> parameter)
76 */
77 public SetNextRule( String methodName, Class<?> paramType )
78 {
79 super( methodName, paramType );
80 }
81
82 /**
83 * {@inheritDoc}
84 */
85 @Override
86 protected Object getChild()
87 {
88 return getDigester().peek( 0 );
89 }
90
91 /**
92 * {@inheritDoc}
93 */
94 @Override
95 protected Object getParent()
96 {
97 return getDigester().peek( 1 );
98 }
99
100 }