001    /*
002     * Copyright (C) 2010 Evgeny Mandrikov
003     *
004     * Sonar-IDE is free software; you can redistribute it and/or
005     * modify it under the terms of the GNU Lesser General Public
006     * License as published by the Free Software Foundation; either
007     * version 3 of the License, or (at your option) any later version.
008     *
009     * Sonar-IDE is distributed in the hope that it will be useful,
010     * but WITHOUT ANY WARRANTY; without even the implied warranty of
011     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
012     * Lesser General Public License for more details.
013     *
014     * You should have received a copy of the GNU Lesser General Public
015     * License along with Sonar-IDE; if not, write to the Free Software
016     * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02
017     */
018    
019    package org.sonar.ide.shared;
020    
021    import java.util.HashMap;
022    import java.util.Map;
023    
024    /**
025     * @author Jérémie Lagarde
026     */
027    public abstract class AbstractProjectProperties<MODEL> {
028    
029      private static final String                           P_SONAR_SERVER_URL   = "sonarServerUrl";
030      private static final String                           P_PROJECT_GROUPID    = "projectGroupId";
031      private static final String                           P_PROJECT_ARTIFACTID = "projectArtifactId";
032      private static final String                           P_PROJECT_BRANCH     = "projectBranch";
033    
034      private static Map<String, AbstractProjectProperties> projectPropertiesMap = new HashMap<String, AbstractProjectProperties>();
035    
036      private MODEL                                         project              = null;
037    
038      protected AbstractProjectProperties(MODEL project) {
039        this.project = project;
040        projectPropertiesMap.put(this.getProjectName(), this);
041        load();
042      }
043    
044      public abstract void save();
045      public abstract void load();
046    
047      public String getUrl() {
048        return getProperty(P_SONAR_SERVER_URL, "");
049      }
050    
051      public void setUrl(String url) {
052        setProperty(P_SONAR_SERVER_URL, url);
053      }
054    
055      public String getGroupId() {
056        return getProperty(P_PROJECT_GROUPID, "");
057      }
058    
059      public void setGroupId(String groupId) {
060        setProperty(P_PROJECT_GROUPID, groupId);
061      }
062    
063      public String getArtifactId() {
064        return getProperty(P_PROJECT_ARTIFACTID, getProjectName());
065      }
066    
067      public void setArtifactId(String artifactId) {
068        setProperty(P_PROJECT_ARTIFACTID, artifactId);
069      }
070    
071      public String getBranch() {
072        return getProperty(P_PROJECT_BRANCH, "");
073      }
074    
075      public void setBranch(String branch) {
076        setProperty(P_PROJECT_BRANCH, branch);
077      }
078    
079      protected MODEL getProject() {
080        return project;
081      }
082    
083      protected static AbstractProjectProperties find(String name) {
084        return projectPropertiesMap.get(name);
085      }
086    
087      protected abstract String getProjectName();
088    
089      protected abstract String getProperty(String value, String defaultValue);
090    
091      protected abstract void setProperty(String type, String value);
092    
093    }