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  
24  
25  
26  public class CopyStringProcessor implements PropertyProcessor {
27  
28  	Object bean;
29  	String beanProperty;
30  	String propertyKey;
31  
32  	public CopyStringProcessor() {
33  		this(null, null, null);
34  	}
35  
36  	public CopyStringProcessor(Object bean, String beanProperty, String propertyKey) {
37  		super();
38  		this.bean = bean;
39  		this.beanProperty = beanProperty;
40  		this.propertyKey = propertyKey;
41  	}
42  
43  	@Override
44  	public void process(Properties properties) {
45  		copyProperty(bean, beanProperty, properties, propertyKey);
46  	}
47  
48  	protected void copyProperty(Object bean, String beanProperty, Properties properties, String propertyKey) {
49  		try {
50  			String value = properties.getProperty(propertyKey);
51  			BeanUtils.copyProperty(bean, beanProperty, value);
52  		} catch (InvocationTargetException e) {
53  			throw new IllegalArgumentException(e);
54  		} catch (IllegalAccessException e) {
55  			throw new IllegalArgumentException(e);
56  		}
57  	}
58  
59  	public Object getBean() {
60  		return bean;
61  	}
62  
63  	public void setBean(Object bean) {
64  		this.bean = bean;
65  	}
66  
67  	public String getBeanProperty() {
68  		return beanProperty;
69  	}
70  
71  	public void setBeanProperty(String beanProperty) {
72  		this.beanProperty = beanProperty;
73  	}
74  
75  	public String getPropertyKey() {
76  		return propertyKey;
77  	}
78  
79  	public void setPropertyKey(String propertyKey) {
80  		this.propertyKey = propertyKey;
81  	}
82  
83  }