View Javadoc

1   /**
2    * Copyright 2010-2012 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.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  }