001/* 002 * Sonar, open source software quality management tool. 003 * Copyright (C) 2008-2012 SonarSource 004 * mailto:contact AT sonarsource DOT com 005 * 006 * Sonar is free software; you can redistribute it and/or 007 * modify it under the terms of the GNU Lesser General Public 008 * License as published by the Free Software Foundation; either 009 * version 3 of the License, or (at your option) any later version. 010 * 011 * Sonar is distributed in the hope that it will be useful, 012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 014 * Lesser General Public License for more details. 015 * 016 * You should have received a copy of the GNU Lesser General Public 017 * License along with Sonar; if not, write to the Free Software 018 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 019 */ 020package org.sonar.api.rules; 021 022import org.apache.commons.lang.StringUtils; 023import org.apache.commons.lang.builder.ToStringBuilder; 024import org.apache.commons.lang.builder.ToStringStyle; 025import org.sonar.api.ServerExtension; 026 027import java.util.List; 028 029/** 030 * @since 2.3 031 */ 032public abstract class RuleRepository implements ServerExtension { 033 034 private String key; 035 private String language; 036 private String name; 037 038 protected RuleRepository(String key, String language) { 039 this.key = key; 040 this.language = language; 041 } 042 043 public final String getKey() { 044 return key; 045 } 046 047 public final String getLanguage() { 048 return language; 049 } 050 051 public final String getName() { 052 return name; 053 } 054 055 public final String getName(boolean useKeyIfEmpty) { 056 if (useKeyIfEmpty) { 057 return StringUtils.defaultIfEmpty(name, key); 058 } 059 return name; 060 } 061 062 public final RuleRepository setName(String s) { 063 this.name = s; 064 return this; 065 } 066 067 public abstract List<Rule> createRules(); 068 069 @Override 070 public String toString() { 071 return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE) 072 .append("key", key) 073 .append("language", language) 074 .append("name", name) 075 .toString(); 076 } 077}