001    /**
002     * Copyright 2010-2013 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.SvnService;
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            boolean singleton = true;
029    
030            @Override
031            public ScmService getObject() {
032                    Assert.hasText(url, "URL has no text");
033                    // scm:svn:https://svn.kuali.org/repos/student/trunk
034                    String[] tokens = StringUtils.split(url, ":");
035                    String scmType = tokens[1].toUpperCase();
036                    ScmType type = ScmType.valueOf(scmType);
037                    switch (type) {
038                    case SVN:
039                            return new SvnService();
040                    case GIT:
041                            throw new IllegalArgumentException("GIT support is coming soon!");
042                    default:
043                            throw new IllegalArgumentException("SCM type [" + scmType + "] is unknown");
044                    }
045            }
046    
047            @Override
048            public Class<ScmService> getObjectType() {
049                    return ScmService.class;
050            }
051    
052            @Override
053            public boolean isSingleton() {
054                    return singleton;
055            }
056    
057            public String getUrl() {
058                    return url;
059            }
060    
061            public void setUrl(String url) {
062                    this.url = url;
063            }
064    
065            public void setSingleton(boolean singleton) {
066                    this.singleton = singleton;
067            }
068    
069    }