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.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  		// scm:svn:https://svn.kuali.org/repos/student/trunk
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  }