KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > maven > project > validation > ModelValidationResult


1 package org.apache.maven.project.validation;
2
3 /*
4  * Copyright 2001-2005 The Apache Software Foundation.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18
19 import java.util.ArrayList JavaDoc;
20 import java.util.Collections JavaDoc;
21 import java.util.List JavaDoc;
22
23 /**
24  * @author <a HREF="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
25  * @version $Id: ModelValidationResult.java 191634 2005-06-21 06:49:49Z brett $
26  */

27 public class ModelValidationResult
28 {
29     /** */
30     private final static String JavaDoc NEWLINE = System.getProperty( "line.separator" );
31
32     /** */
33     private List JavaDoc messages;
34
35     public ModelValidationResult()
36     {
37         messages = new ArrayList JavaDoc();
38     }
39
40     public int getMessageCount()
41     {
42         return messages.size();
43     }
44
45     public String JavaDoc getMessage( int i )
46     {
47         return messages.get( i ).toString();
48     }
49
50     public List JavaDoc getMessages()
51     {
52         return Collections.unmodifiableList( messages );
53     }
54
55     public void addMessage( String JavaDoc message )
56     {
57         messages.add( message );
58     }
59
60     public String JavaDoc toString()
61     {
62         return render( "" );
63     }
64
65     public String JavaDoc render( String JavaDoc indentation )
66     {
67         if ( messages.size() == 0 )
68         {
69             return indentation + "There were no validation errors.";
70         }
71
72         StringBuffer JavaDoc message = new StringBuffer JavaDoc();
73
74 // if ( messages.size() == 1 )
75
// {
76
// message.append( "There was 1 validation error: " );
77
// }
78
// else
79
// {
80
// message.append( "There was " + messages.size() + " validation errors: " + NEWLINE );
81
// }
82
//
83
for ( int i = 0; i < messages.size(); i++ )
84         {
85             message.append( indentation + "[" + i + "] " + messages.get( i ).toString() + NEWLINE );
86         }
87
88         return message.toString();
89     }
90 }
91
Popular Tags