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
025 import javax.persistence.*;
026
027 @Entity
028 @Table(name = "active_rule_parameters")
029 public class ActiveRuleParam implements Cloneable {
030
031
032 @Id
033 @Column(name = "id")
034 @GeneratedValue
035 private Integer id;
036
037 @ManyToOne(fetch = FetchType.LAZY)
038 @JoinColumn(name = "active_rule_id")
039 private ActiveRule activeRule;
040
041 @ManyToOne(fetch = FetchType.LAZY, optional = true)
042 @JoinColumn(name = "rules_parameter_id")
043 private RuleParam ruleParam;
044
045 @Column(name = "value", updatable = false, nullable = true, length = 4000)
046 private String value;
047
048 public Integer getId() {
049 return id;
050 }
051
052 /**
053 * @deprecated visibility should be decreased to protected or package
054 */
055 @Deprecated
056 void setId(Integer id) {
057 this.id = id;
058 }
059
060 /**
061 * @deprecated visibility should be decreased to protected or package
062 */
063 @Deprecated
064 public ActiveRuleParam() {
065 }
066
067 /**
068 * @deprecated visibility should be decreased to protected or package
069 */
070 @Deprecated
071 public ActiveRuleParam(ActiveRule activeRule, RuleParam ruleParam, String value) {
072 this.activeRule = activeRule;
073 this.ruleParam = ruleParam;
074 this.value = value;
075 }
076
077 public ActiveRule getActiveRule() {
078 return activeRule;
079 }
080
081 /**
082 * @deprecated visibility should be decreased to protected or package
083 */
084 @Deprecated
085 public void setActiveRule(ActiveRule activeRule) {
086 this.activeRule = activeRule;
087 }
088
089 public RuleParam getRuleParam() {
090 return ruleParam;
091 }
092
093 /**
094 * @deprecated visibility should be decreased to protected or package
095 */
096 @Deprecated
097 public void setRuleParam(RuleParam ruleParam) {
098 this.ruleParam = ruleParam;
099 }
100
101 public String getValue() {
102 return value;
103 }
104
105 public void setValue(String value) {
106 this.value = value;
107 }
108
109 public String getKey() {
110 return ruleParam.getKey();
111 }
112
113 @Override
114 public boolean equals(Object obj) {
115 if (!(obj instanceof RuleParam)) {
116 return false;
117 }
118 if (this == obj) {
119 return true;
120 }
121 RuleParam other = (RuleParam) obj;
122 return new EqualsBuilder()
123 .append(getId(), other.getKey()).isEquals();
124 }
125
126 @Override
127 public int hashCode() {
128 return new HashCodeBuilder(17, 37)
129 .append(getId())
130 .toHashCode();
131 }
132
133 @Override
134 public Object clone() {
135 return new ActiveRuleParam(getActiveRule(), getRuleParam(), getValue());
136 }
137
138 }