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 "set parent" method on the top (child) object, passing the (top-1) (parent) object
26 * as an argument.
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 */
33 public class SetTopRule
34 extends AbstractMethodRule
35 {
36
37 // ----------------------------------------------------------- Constructors
38
39 /**
40 * Construct a "set top" rule with the specified method name. The method's argument type is assumed to be the class
41 * of the child object.
42 *
43 * @param methodName Method name of the parent method to call
44 */
45 public SetTopRule( String methodName )
46 {
47 super( methodName );
48 }
49
50 /**
51 * Construct a "set top" rule with the specified method name.
52 *
53 * @param methodName Method name of the parent method to call
54 * @param paramType Java class name of the parent method's argument (if you wish to use a primitive type,
55 * specify the corresonding Java wrapper class instead, such as <code>java.lang.Boolean</code>
56 * for a <code>boolean</code> parameter)
57 */
58 public SetTopRule( String methodName, String paramType )
59 {
60 super( methodName, paramType );
61 }
62
63 /**
64 * Construct a "set top" rule with the specified method name.
65 *
66 * @param methodName Method name of the parent method to call
67 * @param paramType Java class of the parent method's argument (if you wish to use a primitive type, specify the
68 * corresonding Java wrapper class instead, such as <code>java.lang.Boolean</code> for a
69 * <code>boolean</code> parameter)
70 */
71 public SetTopRule( String methodName, Class<?> paramType )
72 {
73 super( methodName, paramType );
74 }
75
76 /**
77 * {@inheritDoc}
78 */
79 @Override
80 protected Object getChild()
81 {
82 return getDigester().peek( 1 );
83 }
84
85 /**
86 * {@inheritDoc}
87 */
88 @Override
89 protected Object getParent()
90 {
91 return getDigester().peek( 0 );
92 }
93
94 }