You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

RuleParam.java 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. /*
  2. * Sonar, open source software quality management tool.
  3. * Copyright (C) 2009 SonarSource SA
  4. * mailto:contact AT sonarsource DOT com
  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.api.rules;
  21. import org.apache.commons.lang.StringUtils;
  22. import org.apache.commons.lang.builder.EqualsBuilder;
  23. import org.apache.commons.lang.builder.HashCodeBuilder;
  24. import org.apache.commons.lang.builder.ToStringBuilder;
  25. import javax.persistence.*;
  26. @Entity
  27. @Table(name = "rules_parameters")
  28. public class RuleParam {
  29. @Id
  30. @Column(name = "id")
  31. @GeneratedValue
  32. private Integer id;
  33. @ManyToOne(fetch = FetchType.EAGER)
  34. @JoinColumn(name = "rule_id")
  35. private Rule rule;
  36. @Column(name = "name", updatable = true, nullable = false, length = 128)
  37. private String key;
  38. @Column(name = "description", updatable = true, nullable = true, length = 4000)
  39. private String description;
  40. @Column(name = "param_type", updatable = true, nullable = true, length = 512)
  41. private String type = "s";
  42. @Column(name = "default_value", updatable = true, nullable = true, length = 4000)
  43. private String defaultValue;
  44. /**
  45. * @deprecated since 2.3 use the factory method Rule.setParameter()
  46. */
  47. @Deprecated
  48. public RuleParam() {
  49. }
  50. /**
  51. * @deprecated since 2.3 use the factory method setParameter()
  52. */
  53. @Deprecated
  54. public RuleParam(Rule rule, String key, String description, String type) {
  55. this.rule = rule;
  56. this.key = key;
  57. this.description = description;
  58. this.type = type;
  59. }
  60. public Rule getRule() {
  61. return rule;
  62. }
  63. RuleParam setRule(Rule rule) {
  64. this.rule = rule;
  65. return this;
  66. }
  67. public String getKey() {
  68. return key;
  69. }
  70. public RuleParam setKey(String key) {
  71. this.key = key;
  72. return this;
  73. }
  74. public String getDescription() {
  75. return description;
  76. }
  77. public RuleParam setDescription(String s) {
  78. this.description = StringUtils.defaultString(s, "");
  79. return this;
  80. }
  81. public String getType() {
  82. return type;
  83. }
  84. public RuleParam setType(String type) {
  85. this.type = type;
  86. return this;
  87. }
  88. public String getDefaultValue() {
  89. return defaultValue;
  90. }
  91. public Boolean getDefaultValueAsBoolean() {
  92. if (defaultValue!=null) {
  93. return Boolean.parseBoolean(defaultValue);
  94. }
  95. return null;
  96. }
  97. public Integer getDefaultValueAsInteger() {
  98. if (defaultValue!=null) {
  99. return Integer.parseInt(defaultValue);
  100. }
  101. return null;
  102. }
  103. public RuleParam setDefaultValue(String s) {
  104. this.defaultValue = s;
  105. return this;
  106. }
  107. @Override
  108. public boolean equals(Object obj) {
  109. if (!(obj instanceof RuleParam)) {
  110. return false;
  111. }
  112. if (this == obj) {
  113. return true;
  114. }
  115. RuleParam other = (RuleParam) obj;
  116. return new EqualsBuilder()
  117. //.append(rule, other.getRule())
  118. .append(key, other.getKey()).isEquals();
  119. }
  120. @Override
  121. public int hashCode() {
  122. return new HashCodeBuilder(17, 37)
  123. //.append(rule)
  124. .append(key)
  125. .toHashCode();
  126. }
  127. @Override
  128. public String toString() {
  129. return new ToStringBuilder(this)
  130. .append("id", id)
  131. .append("key", key)
  132. .append("desc", description)
  133. .append("type", type)
  134. .toString();
  135. }
  136. }