1   
2   
3   
4   
5   
6   
7   
8   
9   
10  
11  
12  
13  
14  
15  
16  package org.kuali.common.util.spring;
17  
18  import org.codehaus.plexus.util.StringUtils;
19  import org.kuali.common.util.service.ScmService;
20  import org.kuali.common.util.service.ScmType;
21  import org.kuali.common.util.service.SubversionService;
22  import org.springframework.beans.factory.FactoryBean;
23  import org.springframework.util.Assert;
24  
25  public class ScmServiceFactoryBean implements FactoryBean<ScmService> {
26  
27  	String url;
28  
29  	@Override
30  	public ScmService getObject() throws Exception {
31  		Assert.notNull(url, "URL is null");
32  		
33  		String[] tokens = StringUtils.split(url, ":");
34  		String scmType = tokens[1].toUpperCase();
35  		ScmType type = ScmType.valueOf(scmType);
36  		switch (type) {
37  		case SVN:
38  			return new SubversionService();
39  		case GIT:
40  			throw new IllegalArgumentException("GIT support is coming soon!");
41  		default:
42  			throw new IllegalArgumentException("SCM type [" + scmType + "] is unknown");
43  		}
44  	}
45  
46  	@Override
47  	public Class<ScmService> getObjectType() {
48  		return ScmService.class;
49  	}
50  
51  	@Override
52  	public boolean isSingleton() {
53  		return false;
54  	}
55  
56  	public String getUrl() {
57  		return url;
58  	}
59  
60  	public void setUrl(String url) {
61  		this.url = url;
62  	}
63  
64  }