KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > admin > util > ValidatorResult


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23 package com.sun.enterprise.admin.util;
24
25 // JDK includes
26
import java.io.Serializable JavaDoc;
27
28
29 /**
30     Represents the result of validation by an IValidator.
31  */

32 public class ValidatorResult implements Serializable JavaDoc
33 {
34     private final boolean mValid;
35     private final String JavaDoc mMsg; // may be null
36

37     // don't new up a new ValidatorResult every time an object is valid;
38
// instead use this prebuilt one over and over.
39
public static final ValidatorResult kValid = new ValidatorResult();
40
41     /**
42         Constructor intended for non-public use by Assert.
43      */

44     public ValidatorResult( boolean valid, String JavaDoc msg )
45     {
46         mValid = valid;
47
48         // keep message only if invalid (convenience for caller)
49
mMsg = valid ? null : msg;
50     }
51
52     /**
53         Constructor indicates validation succeeded.
54      */

55     protected ValidatorResult( )
56     {
57         mValid = true;
58         mMsg = null;
59     }
60
61     /**
62         Return True if valid, false otherwise.
63
64         @returns true if valid, false otherwise
65      */

66     public boolean isValid()
67     {
68         return( mValid );
69     }
70
71     /**
72         Return a String describing the validation failure. A null will
73         be returned if there was no failure.
74
75         @returns validation failure String (may be null if no failure)
76      */

77     public String JavaDoc getString()
78     {
79         return( mMsg );
80     }
81
82     /**
83         Represent as a String
84      */

85     public String JavaDoc toString()
86     {
87         String JavaDoc result = null;
88
89         if ( mValid )
90         {
91             result = "valid";
92         }
93         else
94         {
95             result = "INVALID = " + getString();
96         }
97
98         return( result );
99     }
100 }
Popular Tags