001 /* 002 * Sonar, open source software quality management tool. 003 * Copyright (C) 2008-2011 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 */ 020 package org.sonar.api.rules; 021 022 import org.apache.commons.lang.builder.EqualsBuilder; 023 import org.apache.commons.lang.builder.HashCodeBuilder; 024 import org.apache.commons.lang.builder.ToStringBuilder; 025 import org.hibernate.annotations.Cache; 026 import org.hibernate.annotations.CacheConcurrencyStrategy; 027 import org.hibernate.annotations.Immutable; 028 import org.sonar.api.database.BaseIdentifiable; 029 import org.sonar.check.IsoCategory; 030 031 import javax.persistence.Column; 032 import javax.persistence.Entity; 033 import javax.persistence.Table; 034 035 /** 036 * @deprecated since 2.5 See http://jira.codehaus.org/browse/SONAR-2007 037 */ 038 @Deprecated 039 @Immutable 040 @Cache(usage = CacheConcurrencyStrategy.READ_ONLY) 041 @Entity 042 @Table(name = "rules_categories") 043 public class RulesCategory extends BaseIdentifiable { 044 045 @Column(name = "name", updatable = false, nullable = false) 046 private String name; 047 048 @Column(name = "description", updatable = false, nullable = true) 049 private String description; 050 051 /** 052 * Creates a RuleCategory based on the category name 053 * 054 * @param name the category name 055 */ 056 public RulesCategory(String name) { 057 this.name = name; 058 } 059 060 /** 061 * Creates a category based on the category name and description 062 * 063 * @param name the category name 064 * @param description the category description 065 */ 066 public RulesCategory(String name, String description) { 067 this.name = name; 068 this.description = description; 069 } 070 071 /** 072 * Creates an empty category 073 */ 074 public RulesCategory() { 075 } 076 077 /** 078 * @return the category name 079 */ 080 public String getName() { 081 return name; 082 } 083 084 /** 085 * Sets the category name 086 * 087 * @param name the name 088 */ 089 public void setName(String name) { 090 this.name = name; 091 } 092 093 /** 094 * @return the category description 095 */ 096 public String getDescription() { 097 return description; 098 } 099 100 /** 101 * Sets the cay description 102 * 103 * @param description the description 104 */ 105 public void setDescription(String description) { 106 this.description = description; 107 } 108 109 @Override 110 public boolean equals(Object obj) { 111 if (!(obj instanceof RulesCategory)) { 112 return false; 113 } 114 if (this == obj) { 115 return true; 116 } 117 RulesCategory other = (RulesCategory) obj; 118 return new EqualsBuilder() 119 .append(name, other.getName()).isEquals(); 120 } 121 122 @Override 123 public int hashCode() { 124 return new HashCodeBuilder(17, 37) 125 .append(name) 126 .toHashCode(); 127 } 128 129 @Override 130 public String toString() { 131 return new ToStringBuilder(this) 132 .append("id", getId()) 133 .append("name", name) 134 .append("desc", description) 135 .toString(); 136 } 137 138 public IsoCategory toIsoCategory() { 139 if (name.equals(Iso9126RulesCategories.EFFICIENCY.getName())) { 140 return IsoCategory.Efficiency; 141 } 142 if (name.equals(Iso9126RulesCategories.MAINTAINABILITY.getName())) { 143 return IsoCategory.Maintainability; 144 } 145 if (name.equals(Iso9126RulesCategories.PORTABILITY.getName())) { 146 return IsoCategory.Portability; 147 } 148 if (name.equals(Iso9126RulesCategories.RELIABILITY.getName())) { 149 return IsoCategory.Reliability; 150 } 151 if (name.equals(Iso9126RulesCategories.USABILITY.getName())) { 152 return IsoCategory.Usability; 153 } 154 return null; 155 } 156 157 public static RulesCategory fromIsoCategory(IsoCategory iso) { 158 if (iso == IsoCategory.Efficiency) { 159 return Iso9126RulesCategories.EFFICIENCY; 160 } 161 if (iso == IsoCategory.Maintainability) { 162 return Iso9126RulesCategories.MAINTAINABILITY; 163 } 164 if (iso == IsoCategory.Portability) { 165 return Iso9126RulesCategories.PORTABILITY; 166 } 167 if (iso == IsoCategory.Reliability) { 168 return Iso9126RulesCategories.RELIABILITY; 169 } 170 if (iso == IsoCategory.Usability) { 171 return Iso9126RulesCategories.USABILITY; 172 } 173 return null; 174 } 175 }