001 // Copyright 2004, 2005 The Apache Software Foundation 002 // 003 // Licensed under the Apache License, Version 2.0 (the "License"); 004 // you may not use this file except in compliance with the License. 005 // You may obtain a copy of the License at 006 // 007 // http://www.apache.org/licenses/LICENSE-2.0 008 // 009 // Unless required by applicable law or agreed to in writing, software 010 // distributed under the License is distributed on an "AS IS" BASIS, 011 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 012 // See the License for the specific language governing permissions and 013 // limitations under the License. 014 015 package org.apache.tapestry.bean; 016 017 import org.apache.hivemind.ApplicationRuntimeException; 018 import org.apache.hivemind.impl.BaseLocatable; 019 import org.apache.hivemind.util.PropertyUtils; 020 import org.apache.tapestry.Tapestry; 021 022 /** 023 * Base class for initializing a property of a JavaBean. 024 * 025 * @author Howard Lewis Ship 026 * @since 1.0.5 027 */ 028 029 public abstract class AbstractBeanInitializer extends BaseLocatable implements IBeanInitializer 030 { 031 protected String _propertyName; 032 033 public String getPropertyName() 034 { 035 return _propertyName; 036 } 037 038 /** @since 3.0 * */ 039 040 public void setPropertyName(String propertyName) 041 { 042 _propertyName = propertyName; 043 } 044 045 protected void setBeanProperty(Object bean, Object value) 046 { 047 try 048 { 049 PropertyUtils.write(bean, _propertyName, value); 050 } 051 catch (ApplicationRuntimeException ex) 052 { 053 String message = Tapestry.format( 054 "AbstractBeanInitializer.unable-to-set-property", 055 _propertyName, 056 bean, 057 value); 058 059 throw new ApplicationRuntimeException(message, getLocation(), ex); 060 } 061 062 } 063 }