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.StringUtils;
023 import org.apache.commons.lang.builder.EqualsBuilder;
024 import org.apache.commons.lang.builder.HashCodeBuilder;
025 import org.apache.commons.lang.builder.ToStringBuilder;
026 import org.sonar.api.database.BaseIdentifiable;
027
028 import javax.persistence.*;
029
030 @Entity
031 @Table(name = "rules_parameters")
032 public class RuleParam extends BaseIdentifiable {
033
034 @ManyToOne(fetch = FetchType.LAZY)
035 @JoinColumn(name = "rule_id")
036 private Rule rule;
037
038 @Column(name = "name", updatable = true, nullable = false, length = 128)
039 private String key;
040
041 @Column(name = "description", updatable = true, nullable = false, length = 4000)
042 private String description;
043
044 @Column(name = "param_type", updatable = true, nullable = false, length = 512)
045 private String type;
046
047 // only for backward compatibility with sonar 1.4.
048 // See StandardRulesXmlParser
049 //private String defaultValue;
050
051 public RuleParam() {
052 }
053
054 public RuleParam(Rule rule, String key, String description, String type) {
055 this.rule = rule;
056 this.key = key;
057 this.description = description;
058 this.type = type;
059 }
060
061 public Rule getRule() {
062 return rule;
063 }
064
065 public void setRule(Rule rule) {
066 this.rule = rule;
067 }
068
069 public String getKey() {
070 return key;
071 }
072
073 public void setKey(String key) {
074 this.key = key;
075 }
076
077 public String getDescription() {
078 return description;
079 }
080
081 public void setDescription(String description) {
082 this.description = StringUtils.defaultString(description, "");
083 }
084
085 public String getType() {
086 return type;
087 }
088
089 public void setType(String type) {
090 this.type = type;
091 }
092
093 @Override
094 public boolean equals(Object obj) {
095 if (!(obj instanceof RuleParam)) {
096 return false;
097 }
098 if (this == obj) {
099 return true;
100 }
101 RuleParam other = (RuleParam) obj;
102 return new EqualsBuilder()
103 .append(rule, other.getRule())
104 .append(key, other.getKey()).isEquals();
105 }
106
107 @Override
108 public int hashCode() {
109 return new HashCodeBuilder(17, 37)
110 .append(rule)
111 .append(key)
112 .toHashCode();
113 }
114
115 @Override
116 public String toString() {
117 return new ToStringBuilder(this)
118 .append("id", getId())
119 .append("key", key)
120 .append("desc", description)
121 .append("type", type)
122 .toString();
123 }
124 }