View Javadoc

1   /*
2    * Sonar, entreprise quality control tool.
3    * Copyright (C) 2007-2008 Hortis-GRC SA
4    * mailto:be_agile HAT hortis DOT ch
5    *
6    * Sonar is free software; you can redistribute it and/or
7    * modify it under the terms of the GNU Lesser General Public
8    * License as published by the Free Software Foundation; either
9    * version 3 of the License, or (at your option) any later version.
10   *
11   * Sonar is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14   * Lesser General Public License for more details.
15   *
16   * You should have received a copy of the GNU Lesser General Public
17   * License along with Sonar; if not, write to the Free Software
18   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02
19   */
20  package org.sonar.commons.rules;
21  
22  import ch.hortis.sonar.model.Rule;
23  import org.apache.commons.lang.builder.EqualsBuilder;
24  import org.apache.commons.lang.builder.HashCodeBuilder;
25  import org.apache.commons.lang.builder.ToStringBuilder;
26  
27  import javax.persistence.*;
28  
29  @Entity
30  @Table(name = "rules_parameters")
31  public class RuleParam {
32  
33    @Id
34    @Column(name = "id")
35    @SequenceGenerator(name = "RULES_PARAMETERS_SEQ", sequenceName = "RULES_PARAMETERS_SEQ")
36    @GeneratedValue(strategy = GenerationType.AUTO, generator = "RULES_PARAMETERS_SEQ")
37    private Integer id;
38  
39    @ManyToOne(fetch = FetchType.LAZY)
40    @JoinColumn(name = "rule_id")
41    private Rule rule;
42  
43    @Column(name = "name", updatable = true, nullable = false, length = 128)
44    private String key;
45  
46    @Column(name = "description", updatable = true, nullable = true, length = 4000)
47    private String description;
48  
49    @Column(name = "param_type", updatable = true, nullable = false, length = 512)
50    private String type;
51  
52    @Column(name = "default_value", updatable = true, nullable = true, length = 4000)
53    private String defaultValue;
54  
55  
56    public RuleParam() {
57    }
58  
59    public RuleParam(Rule rule, String key, String description, String type, String defaultValue) {
60      this.rule = rule;
61      this.key = key;
62      this.description = description;
63      this.type = type;
64      this.defaultValue = defaultValue;
65    }
66  
67    public Integer getId() {
68      return id;
69    }
70  
71    public void setId(Integer id) {
72      this.id = id;
73    }
74  
75    public Rule getRule() {
76      return rule;
77    }
78  
79    public void setRule(Rule rule) {
80      this.rule = rule;
81    }
82  
83    public String getKey() {
84      return key;
85    }
86  
87    public void setKey(String key) {
88      this.key = key;
89    }
90  
91    public String getDescription() {
92      return description;
93    }
94  
95    public void setDescription(String description) {
96      this.description = description;
97    }
98  
99    public String getType() {
100     return type;
101   }
102 
103   public void setType(String type) {
104     this.type = type;
105   }
106 
107   public String getDefaultValue() {
108     return defaultValue;
109   }
110 
111   public void setDefaultValue(String defaultValue) {
112     this.defaultValue = defaultValue;
113   }
114 
115   public boolean equals(Object obj) {
116     if (!(obj instanceof RuleParam)) {
117       return false;
118     }
119     if (this == obj) {
120       return true;
121     }
122     RuleParam other = (RuleParam) obj;
123     return new EqualsBuilder()
124         .append(rule, other.getRule())
125         .append(key, other.getKey()).isEquals();
126   }
127 
128   public int hashCode() {
129     return new HashCodeBuilder(17, 37)
130         .append(rule)
131         .append(key)
132         .toHashCode();
133   }
134 
135   public String toString() {
136     return new ToStringBuilder(this)
137         .append("id", id)
138         .append("key",key)
139         .append("desc", description)
140         .append("type", type)
141         .append("default", defaultValue)
142         .toString();
143   }
144 }