1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.common.util.property.processor;
17
18 import java.lang.reflect.InvocationTargetException;
19 import java.util.Properties;
20
21 import org.apache.commons.beanutils.BeanUtils;
22
23 public class CopyStringProcessor implements PropertyProcessor {
24
25 Object bean;
26 String beanProperty;
27 String propertyKey;
28
29 public CopyStringProcessor() {
30 this(null, null, null);
31 }
32
33 public CopyStringProcessor(Object bean, String beanProperty, String propertyKey) {
34 super();
35 this.bean = bean;
36 this.beanProperty = beanProperty;
37 this.propertyKey = propertyKey;
38 }
39
40 @Override
41 public void process(Properties properties) {
42 copyProperty(bean, beanProperty, properties, propertyKey);
43 }
44
45 protected void copyProperty(Object bean, String beanProperty, Properties properties, String propertyKey) {
46 try {
47 String value = properties.getProperty(propertyKey);
48 BeanUtils.copyProperty(bean, beanProperty, value);
49 } catch (InvocationTargetException e) {
50 throw new IllegalArgumentException(e);
51 } catch (IllegalAccessException e) {
52 throw new IllegalArgumentException(e);
53 }
54 }
55
56 public Object getBean() {
57 return bean;
58 }
59
60 public void setBean(Object bean) {
61 this.bean = bean;
62 }
63
64 public String getBeanProperty() {
65 return beanProperty;
66 }
67
68 public void setBeanProperty(String beanProperty) {
69 this.beanProperty = beanProperty;
70 }
71
72 public String getPropertyKey() {
73 return propertyKey;
74 }
75
76 public void setPropertyKey(String propertyKey) {
77 this.propertyKey = propertyKey;
78 }
79
80 }