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.utils;
021
022 import java.util.ArrayList;
023 import java.util.List;
024
025 public final class ValidationMessages {
026
027 private List<Message> errors = new ArrayList<Message>();
028 private List<Message> warnings = new ArrayList<Message>();
029 private List<Message> infos = new ArrayList<Message>();
030
031 public boolean hasErrors() {
032 return !errors.isEmpty();
033 }
034 public List<Message> getErrors() {
035 return errors;
036 }
037
038 public List<Message> getWarnings() {
039 return warnings;
040 }
041
042 public List<Message> getInfos() {
043 return infos;
044 }
045
046 public ValidationMessages addError(String key, String label) {
047 errors.add(new Message(key, label));
048 return this;
049 }
050
051 public ValidationMessages addWarning(String key, String label) {
052 warnings.add(new Message(key, label));
053 return this;
054 }
055
056 public ValidationMessages addInfo(String key, String label) {
057 infos.add(new Message(key, label));
058 return this;
059 }
060
061 public static final class Message {
062 private String key;
063 private String label;
064
065 private Message(String key, String label) {
066 this.key = key;
067 this.label = label;
068 }
069
070 public String getKey() {
071 return key;
072 }
073
074 public String getLabel() {
075 return label;
076 }
077 }
078 }