View Javadoc

1   /**
2    * Copyright 2005-2013 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.krad.datadictionary.impl;
17  
18  import java.lang.reflect.InvocationTargetException;
19  
20  import org.apache.commons.beanutils.BeanUtils;
21  import org.kuali.rice.krad.datadictionary.FieldOverride;
22  
23  /**
24   * A Field Override used to replace value elements from a Data Dictionary bean. 
25   * 
26   * @author Kuali Rice Team (rice.collab@kuali.org)
27   * 
28   */
29  public class FieldOverrideForValueReplaceImpl implements FieldOverride{
30  	
31  	private String propertyName;
32  	private Object value;
33  
34  	public String getPropertyName() {
35  		return propertyName;
36  	}
37  
38  	public void setPropertyName(String propertyName) {
39  		this.propertyName = propertyName;
40  	}
41  
42  	public Object getValue() {
43  		return value;
44  	}
45  
46  	public void setValue(Object value) {
47  		this.value = value;
48  	}
49  
50  	public Object performFieldOverride(Object bean, Object property) {
51  		try {
52  			BeanUtils.setProperty(bean, this.getPropertyName(), this.getValue());
53  		} catch (IllegalAccessException e) {
54  			throw new RuntimeException(e);
55  		} catch (InvocationTargetException e) {
56  			throw new RuntimeException(e);
57  		}
58  
59  		return getValue();
60  	}
61  }