View Javadoc
1   /**
2    * Copyright 2005-2015 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.apache.commons.beanutils.PropertyUtils;
20  import org.apache.log4j.Logger;
21  import org.kuali.rice.krad.datadictionary.BeanOverride;
22  import org.kuali.rice.krad.datadictionary.FieldOverride;
23  
24  import java.lang.reflect.InvocationTargetException;
25  import java.util.List;
26  
27  /**
28   * The base implementation of the BeanOverride interface.
29   *
30   * @author Kuali Rice Team (rice.collab@kuali.org)
31   */
32  public class BeanOverrideImpl implements BeanOverride {
33      private static final Logger LOG = Logger.getLogger(BeanOverrideImpl.class);
34      private String beanName;
35      private List<FieldOverride> fieldOverrides;
36  
37      /**
38       * @see org.kuali.rice.krad.datadictionary.BeanOverride#getFieldOverrides()
39       */
40      public List<FieldOverride> getFieldOverrides() {
41          return this.fieldOverrides;
42      }
43  
44      public void setFieldOverrides(List<FieldOverride> fieldOverirdes) {
45          this.fieldOverrides = fieldOverirdes;
46      }
47  
48      /**
49       * @see org.kuali.rice.krad.datadictionary.BeanOverride#getBeanName()
50       */
51      public String getBeanName() {
52          return this.beanName;
53      }
54  
55      public void setBeanName(String beanName) {
56          this.beanName = beanName;
57      }
58  
59      /**
60       * @see org.kuali.rice.krad.datadictionary.BeanOverride#performOverride(java.lang.Object)
61       */
62      public void performOverride(Object bean) {
63          try {
64              for (FieldOverride fieldOverride : fieldOverrides) {
65                  Object property = PropertyUtils.getProperty(bean, fieldOverride.getPropertyName());
66                  Object newProperty = fieldOverride.performFieldOverride(bean, property);
67                  BeanUtils.setProperty(bean, fieldOverride.getPropertyName(), newProperty);
68              }
69          } catch (IllegalAccessException e) {
70              throw new RuntimeException(e);
71          } catch (InvocationTargetException e) {
72              throw new RuntimeException(e);
73  
74          } catch (NoSuchMethodException e) {
75              throw new RuntimeException(e);
76          }
77      }
78  }