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 public RuleParam() { 048 } 049 050 public RuleParam(Rule rule, String key, String description, String type) { 051 this.rule = rule; 052 this.key = key; 053 this.description = description; 054 this.type = type; 055 } 056 057 public Rule getRule() { 058 return rule; 059 } 060 061 public void setRule(Rule rule) { 062 this.rule = rule; 063 } 064 065 public String getKey() { 066 return key; 067 } 068 069 public void setKey(String key) { 070 this.key = key; 071 } 072 073 public String getDescription() { 074 return description; 075 } 076 077 public void setDescription(String description) { 078 this.description = StringUtils.defaultString(description, ""); 079 } 080 081 public String getType() { 082 return type; 083 } 084 085 public void setType(String type) { 086 this.type = type; 087 } 088 089 @Override 090 public boolean equals(Object obj) { 091 if (!(obj instanceof RuleParam)) { 092 return false; 093 } 094 if (this == obj) { 095 return true; 096 } 097 RuleParam other = (RuleParam) obj; 098 return new EqualsBuilder() 099 .append(rule, other.getRule()) 100 .append(key, other.getKey()).isEquals(); 101 } 102 103 @Override 104 public int hashCode() { 105 return new HashCodeBuilder(17, 37) 106 .append(rule) 107 .append(key) 108 .toHashCode(); 109 } 110 111 @Override 112 public String toString() { 113 return new ToStringBuilder(this) 114 .append("id", getId()) 115 .append("key", key) 116 .append("desc", description) 117 .append("type", type) 118 .toString(); 119 } 120 }