001 /**
002 * Copyright 2010-2012 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package org.kuali.common.util.spring;
017
018 import org.codehaus.plexus.util.StringUtils;
019 import org.kuali.common.util.service.ScmService;
020 import org.kuali.common.util.service.ScmType;
021 import org.kuali.common.util.service.SubversionService;
022 import org.springframework.beans.factory.FactoryBean;
023 import org.springframework.util.Assert;
024
025 public class ScmServiceFactoryBean implements FactoryBean<ScmService> {
026
027 String url;
028
029 @Override
030 public ScmService getObject() throws Exception {
031 Assert.notNull(url, "URL is null");
032 // scm:svn:https://svn.kuali.org/repos/student/trunk
033 String[] tokens = StringUtils.split(url, ":");
034 String scmType = tokens[1].toUpperCase();
035 ScmType type = ScmType.valueOf(scmType);
036 switch (type) {
037 case SVN:
038 return new SubversionService();
039 case GIT:
040 throw new IllegalArgumentException("GIT support is coming soon!");
041 default:
042 throw new IllegalArgumentException("SCM type [" + scmType + "] is unknown");
043 }
044 }
045
046 @Override
047 public Class<ScmService> getObjectType() {
048 return ScmService.class;
049 }
050
051 @Override
052 public boolean isSingleton() {
053 return false;
054 }
055
056 public String getUrl() {
057 return url;
058 }
059
060 public void setUrl(String url) {
061 this.url = url;
062 }
063
064 }