001 /* 002 * Sonar, open source software quality management tool. 003 * Copyright (C) 2009 SonarSource SA 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 * A class to hold rules category 037 */ 038 @Immutable 039 @Cache(usage = CacheConcurrencyStrategy.READ_ONLY) 040 @Entity 041 @Table(name = "rules_categories") 042 public class RulesCategory extends BaseIdentifiable { 043 044 @Column(name = "name", updatable = false, nullable = false) 045 private String name; 046 047 @Column(name = "description", updatable = false, nullable = true) 048 private String description; 049 050 /** 051 * Creates a RuleCategory based on the category name 052 * 053 * @param name the category name 054 */ 055 public RulesCategory(String name) { 056 this.name = name; 057 } 058 059 /** 060 * Creates a category based on the category name and description 061 * 062 * @param name the category name 063 * @param description the category description 064 */ 065 public RulesCategory(String name, String description) { 066 this.name = name; 067 this.description = description; 068 } 069 070 /** 071 * Creates an empty category 072 */ 073 public RulesCategory() { 074 } 075 076 /** 077 * @return the category name 078 */ 079 public String getName() { 080 return name; 081 } 082 083 /** 084 * Sets the category name 085 * 086 * @param name the name 087 */ 088 public void setName(String name) { 089 this.name = name; 090 } 091 092 /** 093 * @return the category description 094 */ 095 public String getDescription() { 096 return description; 097 } 098 099 /** 100 * Sets the cay description 101 * @param description the description 102 */ 103 public void setDescription(String description) { 104 this.description = description; 105 } 106 107 @Override 108 public boolean equals(Object obj) { 109 if (!(obj instanceof RulesCategory)) { 110 return false; 111 } 112 if (this == obj) { 113 return true; 114 } 115 RulesCategory other = (RulesCategory) obj; 116 return new EqualsBuilder() 117 .append(name, other.getName()).isEquals(); 118 } 119 120 @Override 121 public int hashCode() { 122 return new HashCodeBuilder(17, 37) 123 .append(name) 124 .toHashCode(); 125 } 126 127 @Override 128 public String toString() { 129 return new ToStringBuilder(this) 130 .append("id", getId()) 131 .append("name", name) 132 .append("desc", description) 133 .toString(); 134 } 135 136 public IsoCategory toIsoCategory() { 137 if (name.equals(Iso9126RulesCategories.EFFICIENCY.getName())) { 138 return IsoCategory.Efficiency; 139 } 140 if (name.equals(Iso9126RulesCategories.MAINTAINABILITY.getName())) { 141 return IsoCategory.Maintainability; 142 } 143 if (name.equals(Iso9126RulesCategories.PORTABILITY.getName())) { 144 return IsoCategory.Portability; 145 } 146 if (name.equals(Iso9126RulesCategories.RELIABILITY.getName())) { 147 return IsoCategory.Reliability; 148 } 149 if (name.equals(Iso9126RulesCategories.USABILITY.getName())) { 150 return IsoCategory.Usability; 151 } 152 return null; 153 } 154 }