All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.kuali.core.db.torque.FilteredPropertyCopier Maven / Gradle / Ivy

package org.kuali.core.db.torque;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.apache.commons.beanutils.BeanUtils;
import org.kuali.core.db.torque.StringFilter;

public class FilteredPropertyCopier {
	List includeProperties = new ArrayList();
	List excludeProperties = new ArrayList();

	public FilteredPropertyCopier() {
		super();
		addExclude("class");
	}

	public void addExclude(String property) {
		excludeProperties.add(property);
	}

	public void addInclude(String property) {
		includeProperties.add(property);
	}

	public List getIncludeProperties() {
		return includeProperties;
	}

	public void setIncludeProperties(List includeProperties) {
		this.includeProperties = includeProperties;
	}

	public List getExcludeProperties() {
		return excludeProperties;
	}

	public void setExcludeProperties(List excludeProperties) {
		this.excludeProperties = excludeProperties;
	}

	@SuppressWarnings("unchecked")
	public void copyProperties(Object dest, Object origin) throws PropertyHandlingException {
		try {
			Map description = BeanUtils.describe(origin);
			StringFilter filterer = new StringFilter(getIncludeProperties(), getExcludeProperties());
			filterer.filter(description.keySet().iterator());
			for (String property : description.keySet()) {
				BeanUtils.copyProperty(dest, property, description.get(property));
			}
		} catch (Exception e) {
			throw new PropertyHandlingException("Error copying properties", e);
		}
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy