View Javadoc
1   /**
2    * Copyright 2005-2014 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 org.apache.commons.beanutils.BeanUtils;
19  import org.kuali.rice.krad.datadictionary.FieldOverride;
20  
21  import java.lang.reflect.InvocationTargetException;
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  public class FieldOverrideForValueReplaceImpl implements FieldOverride {
29  
30      private String propertyName;
31      private Object value;
32  
33      public String getPropertyName() {
34          return propertyName;
35      }
36  
37      public void setPropertyName(String propertyName) {
38          this.propertyName = propertyName;
39      }
40  
41      public Object getValue() {
42          return value;
43      }
44  
45      public void setValue(Object value) {
46          this.value = value;
47      }
48  
49      public Object performFieldOverride(Object bean, Object property) {
50          try {
51              BeanUtils.setProperty(bean, this.getPropertyName(), this.getValue());
52          } catch (IllegalAccessException e) {
53              throw new RuntimeException(e);
54          } catch (InvocationTargetException e) {
55              throw new RuntimeException(e);
56          }
57  
58          return getValue();
59      }
60  }