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.impex;
17  
18  import java.io.File;
19  import java.lang.reflect.InvocationTargetException;
20  
21  import org.apache.commons.beanutils.BeanUtils;
22  import org.kuali.common.impex.service.ImpexContext;
23  import org.kuali.common.impex.service.ImpexUtils;
24  import org.springframework.beans.factory.FactoryBean;
25  
26  public class ImpexContextCloningFactoryBean implements FactoryBean<ImpexContext> {
27  
28  	ImpexContext sourceContext;
29  	String include;
30  	String artifactId;
31  	File finalDirectory;
32  	boolean copyDataFiles;
33  	String schemaFileInclude;
34  
35  	@Override
36  	public ImpexContext getObject() throws Exception {
37  		ImpexContext context = ImpexUtils.clone(sourceContext, include, artifactId);
38  		copyProperties(context, this);
39  		return context;
40  	}
41  
42  	protected void copyProperties(ImpexContext dest, ImpexContextCloningFactoryBean orig) {
43  		try {
44  			BeanUtils.copyProperties(dest, orig);
45  		} catch (IllegalAccessException e) {
46  			throw new IllegalArgumentException(e);
47  		} catch (InvocationTargetException e) {
48  			throw new IllegalArgumentException(e);
49  		}
50  	}
51  
52  	@Override
53  	public Class<ImpexContext> getObjectType() {
54  		return ImpexContext.class;
55  	}
56  
57  	@Override
58  	public boolean isSingleton() {
59  		return false;
60  	}
61  
62  	public ImpexContext getSourceContext() {
63  		return sourceContext;
64  	}
65  
66  	public void setSourceContext(ImpexContext sourceContext) {
67  		this.sourceContext = sourceContext;
68  	}
69  
70  	public String getInclude() {
71  		return include;
72  	}
73  
74  	public void setInclude(String include) {
75  		this.include = include;
76  	}
77  
78  	public String getArtifactId() {
79  		return artifactId;
80  	}
81  
82  	public void setArtifactId(String artifactId) {
83  		this.artifactId = artifactId;
84  	}
85  
86  	public File getFinalDirectory() {
87  		return finalDirectory;
88  	}
89  
90  	public void setFinalDirectory(File scmBaseDirectory) {
91  		this.finalDirectory = scmBaseDirectory;
92  	}
93  
94  	public boolean isCopyDataFiles() {
95  		return copyDataFiles;
96  	}
97  
98  	public void setCopyDataFiles(boolean copyDataFiles) {
99  		this.copyDataFiles = copyDataFiles;
100 	}
101 
102 	public String getSchemaFileInclude() {
103 		return schemaFileInclude;
104 	}
105 
106 	public void setSchemaFileInclude(String schemaFileInclude) {
107 		this.schemaFileInclude = schemaFileInclude;
108 	}
109 }