001/*
002 * Sonar, open source software quality management tool.
003 * Copyright (C) 2008-2012 SonarSource
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 */
020package org.sonar.plugins.pmd.xml;
021
022import java.util.ArrayList;
023import java.util.List;
024
025public class PmdRule {
026
027  private String ref;
028
029  private String priority;
030
031  private String name;
032
033  private String message;
034
035  private List<PmdProperty> properties = new ArrayList<PmdProperty>();
036
037  private String clazz;
038
039  public PmdRule(String ref) {
040    this(ref, null);
041  }
042
043  public PmdRule(String ref, String priority) {
044    this.ref = ref;
045    this.priority = priority;
046  }
047
048  public String getRef() {
049    return ref;
050  }
051
052  public void setProperties(List<PmdProperty> properties) {
053    this.properties = properties;
054  }
055
056  public List<PmdProperty> getProperties() {
057    return properties;
058  }
059
060  public PmdProperty getProperty(String propertyName) {
061    for (PmdProperty prop : properties) {
062      if (propertyName.equals(prop.getName())) {
063        return prop;
064      }
065    }
066    return null;
067  }
068
069  public int compareTo(String o) {
070    return o.compareTo(ref);
071  }
072
073  public String getPriority() {
074    return priority;
075  }
076
077  public void setPriority(String priority) {
078    this.priority = priority;
079  }
080
081  public void addProperty(PmdProperty property) {
082    if (properties == null) {
083      properties = new ArrayList<PmdProperty>();
084    }
085    properties.add(property);
086  }
087
088  public void setName(String name) {
089    this.name = name;
090  }
091
092  public String getName() {
093    return name;
094  }
095
096  public void setMessage(String message) {
097    this.message = message;
098  }
099
100  public String getMessage() {
101    return message;
102  }
103
104  public void setClazz(String clazz) {
105    this.clazz = clazz;
106  }
107
108  public String getClazz() {
109    return clazz;
110  }
111
112  public void setRef(String ref) {
113    this.ref = ref;
114  }
115
116  public void removeProperty(String propertyName) {
117    PmdProperty prop = getProperty(propertyName);
118    properties.remove(prop);
119  }
120
121  public boolean hasProperties() {
122    return properties != null && !properties.isEmpty();
123  }
124}