001package org.apache.commons.digester3; 002 003/* 004 * Licensed to the Apache Software Foundation (ASF) under one 005 * or more contributor license agreements. See the NOTICE file 006 * distributed with this work for additional information 007 * regarding copyright ownership. The ASF licenses this file 008 * to you under the Apache License, Version 2.0 (the 009 * "License"); you may not use this file except in compliance 010 * with the License. You may obtain a copy of the License at 011 * 012 * http://www.apache.org/licenses/LICENSE-2.0 013 * 014 * Unless required by applicable law or agreed to in writing, 015 * software distributed under the License is distributed on an 016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 017 * KIND, either express or implied. See the License for the 018 * specific language governing permissions and limitations 019 * under the License. 020 */ 021 022 023/** 024 * <p> 025 * Rule implementation that calls a "set parent" method on the top (child) object, passing the (top-1) (parent) object 026 * as an argument. 027 * </p> 028 * <p> 029 * This rule now supports more flexible method matching by default. It is possible that this may break (some) code 030 * written against release 1.1.1 or earlier. See {@link #isExactMatch()} for more details. 031 * </p> 032 */ 033public class SetTopRule 034 extends AbstractMethodRule 035{ 036 037 // ----------------------------------------------------------- Constructors 038 039 /** 040 * Construct a "set top" rule with the specified method name. The method's argument type is assumed to be the class 041 * of the child object. 042 * 043 * @param methodName Method name of the parent method to call 044 */ 045 public SetTopRule( String methodName ) 046 { 047 super( methodName ); 048 } 049 050 /** 051 * Construct a "set top" rule with the specified method name. 052 * 053 * @param methodName Method name of the parent method to call 054 * @param paramType Java class name of the parent method's argument (if you wish to use a primitive type, 055 * specify the corresonding Java wrapper class instead, such as <code>java.lang.Boolean</code> 056 * for a <code>boolean</code> parameter) 057 */ 058 public SetTopRule( String methodName, String paramType ) 059 { 060 super( methodName, paramType ); 061 } 062 063 /** 064 * Construct a "set top" rule with the specified method name. 065 * 066 * @param methodName Method name of the parent method to call 067 * @param paramType Java class of the parent method's argument (if you wish to use a primitive type, specify the 068 * corresonding Java wrapper class instead, such as <code>java.lang.Boolean</code> for a 069 * <code>boolean</code> parameter) 070 */ 071 public SetTopRule( String methodName, Class<?> paramType ) 072 { 073 super( methodName, paramType ); 074 } 075 076 /** 077 * {@inheritDoc} 078 */ 079 @Override 080 protected Object getChild() 081 { 082 return getDigester().peek( 1 ); 083 } 084 085 /** 086 * {@inheritDoc} 087 */ 088 @Override 089 protected Object getParent() 090 { 091 return getDigester().peek( 0 ); 092 } 093 094}