1 package org.apache.commons.digester3.binder; 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 import org.apache.commons.digester3.BeanPropertySetterRule; 23 24 /** 25 * Builder chained when invoking {@link LinkedRuleBuilder#setBeanProperty()}. 26 */ 27 public final class BeanPropertySetterBuilder 28 extends AbstractBackToLinkedRuleBuilder<BeanPropertySetterRule> 29 { 30 31 private String propertyName; 32 33 private String attribute; 34 35 BeanPropertySetterBuilder( String keyPattern, String namespaceURI, RulesBinder mainBinder, 36 LinkedRuleBuilder mainBuilder ) 37 { 38 super( keyPattern, namespaceURI, mainBinder, mainBuilder ); 39 } 40 41 /** 42 * Sets the name of property to set. 43 * 44 * @param propertyName The name of property to set 45 * @return this builder instance 46 */ 47 public BeanPropertySetterBuilder withName( /* @Nullable */String propertyName ) 48 { 49 this.propertyName = propertyName; 50 return this; 51 } 52 53 /** 54 * Sets the attribute name from which the property name has to be extracted. 55 * 56 * @param attribute The attribute name from which extracting the name of property to set 57 * @return this builder instance 58 */ 59 public BeanPropertySetterBuilder extractPropertyNameFromAttribute( String attribute ) 60 { 61 if ( attribute == null ) 62 { 63 reportError( "setBeanProperty().extractPropertyNameFromAttribute( String )", 64 "Attribute name can not be null" ); 65 } 66 this.attribute = attribute; 67 return this; 68 } 69 70 /** 71 * {@inheritDoc} 72 */ 73 @Override 74 protected BeanPropertySetterRule createRule() 75 { 76 BeanPropertySetterRule rule = new BeanPropertySetterRule( propertyName ); 77 rule.setPropertyNameFromAttribute( attribute ); 78 return rule; 79 } 80 81 }