001: package org.apache.maven.settings.validation;
002:
003: /*
004: * Licensed to the Apache Software Foundation (ASF) under one
005: * or more contributor license agreements. See the NOTICE file
006: * distributed with this work for additional information
007: * regarding copyright ownership. The ASF licenses this file
008: * to you under the Apache License, Version 2.0 (the
009: * "License"); you may not use this file except in compliance
010: * with the License. You may obtain a copy of the License at
011: *
012: * http://www.apache.org/licenses/LICENSE-2.0
013: *
014: * Unless required by applicable law or agreed to in writing,
015: * software distributed under the License is distributed on an
016: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017: * KIND, either express or implied. See the License for the
018: * specific language governing permissions and limitations
019: * under the License.
020: */
021:
022: import java.util.ArrayList;
023: import java.util.Collections;
024: import java.util.List;
025:
026: /**
027: * @author <a href="mailto:trygvis@inamo.no">Trygve Laugstøl</a>
028: * @author Milos Kleint
029: */
030: public final class SettingsValidationResult {
031: private final static String NEWLINE = System
032: .getProperty("line.separator");
033:
034: private List messages;
035:
036: /**
037: * Default constructor
038: */
039: public SettingsValidationResult() {
040: messages = new ArrayList();
041: }
042:
043: /**
044: * @return
045: */
046: public int getMessageCount() {
047: return messages.size();
048: }
049:
050: /**
051: * @param i
052: * @return
053: */
054: public String getMessage(int i) {
055: return messages.get(i).toString();
056: }
057:
058: /**
059: * @return
060: */
061: public List getMessages() {
062: return Collections.unmodifiableList(messages);
063: }
064:
065: /**
066: * @param message
067: */
068: public void addMessage(String message) {
069: messages.add(message);
070: }
071:
072: /**
073: * @see java.lang.Object#toString()
074: */
075: public String toString() {
076: return render("");
077: }
078:
079: /**
080: * @param indentation
081: * @return
082: */
083: public String render(String indentation) {
084: if (messages.size() == 0) {
085: return indentation + "There were no validation errors.";
086: }
087:
088: StringBuffer message = new StringBuffer();
089:
090: // if ( messages.size() == 1 )
091: // {
092: // message.append( "There was 1 validation error: " );
093: // }
094: // else
095: // {
096: // message.append( "There was " + messages.size() + " validation errors: " + NEWLINE );
097: // }
098: //
099: for (int i = 0; i < messages.size(); i++) {
100: message.append(indentation + "[" + i + "] "
101: + messages.get(i).toString() + NEWLINE);
102: }
103:
104: return message.toString();
105: }
106: }
|