View Javadoc

1   /*
2    * Copyright  2000-2004 The Apache Software Foundation
3    *
4    *  Licensed under the Apache License, Version 2.0 (the "License"); 
5    *  you may not use this file except in compliance with the License.
6    *  You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   *  Unless required by applicable law or agreed to in writing, software
11   *  distributed under the License is distributed on an "AS IS" BASIS,
12   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   *  See the License for the specific language governing permissions and
14   *  limitations under the License. 
15   *
16   */
17  package org.apache.bcel.verifier;
18  
19  /***
20   * A VerificationResult is what a PassVerifier returns
21   * after verifying.
22   *
23   * @version $Id: VerificationResult.java 386056 2006-03-15 11:31:56Z tcurdt $
24   * @author Enver Haase
25   *
26   */
27  public class VerificationResult {
28  
29      /***
30       * Constant to indicate verification has not been tried yet.
31       * This happens if some earlier verification pass did not return VERIFIED_OK.
32       */
33      public static final int VERIFIED_NOTYET = 0;
34      /*** Constant to indicate verification was passed. */
35      public static final int VERIFIED_OK = 1;
36      /*** Constant to indicate verfication failed. */
37      public static final int VERIFIED_REJECTED = 2;
38      /***
39       * This string is the canonical message for verifications that have not been tried yet.
40       * This happens if some earlier verification pass did not return VERIFIED_OK.
41       */
42      private static final String VERIFIED_NOTYET_MSG = "Not yet verified.";
43      /*** This string is the canonical message for passed verification passes. */
44      private static final String VERIFIED_OK_MSG = "Passed verification.";
45      /***
46       * Canonical VerificationResult for not-yet-tried verifications.
47       * This happens if some earlier verification pass did not return VERIFIED_OK.
48       */
49      public static final VerificationResult VR_NOTYET = new VerificationResult(VERIFIED_NOTYET,
50              VERIFIED_NOTYET_MSG);
51      /*** Canonical VerificationResult for passed verifications. */
52      public static final VerificationResult VR_OK = new VerificationResult(VERIFIED_OK,
53              VERIFIED_OK_MSG);
54      /*** The numeric status. */
55      private int numeric;
56      /*** The detailed message. */
57      private String detailMessage;
58  
59  
60      /*** The usual constructor. */
61      public VerificationResult(int status, String message) {
62          numeric = status;
63          detailMessage = message;
64      }
65  
66  
67      /*** Returns one one the VERIFIED_OK, VERIFIED_NOTYET, VERIFIED_REJECTED constants. */
68      public int getStatus() {
69          return numeric;
70      }
71  
72  
73      /*** Returns a detailed message. */
74      public String getMessage() {
75          return detailMessage;
76      }
77  
78  
79      /*** @return a hash code value for the object.
80       */
81      public int hashCode() {
82          return numeric ^ detailMessage.hashCode();
83      }
84  
85  
86      /***
87       * Returns if two VerificationResult instances are equal.
88       */
89      public boolean equals( Object o ) {
90          if (!(o instanceof VerificationResult)) {
91              return false;
92          }
93          VerificationResult other = (VerificationResult) o;
94          return ((other.numeric == this.numeric) && (other.detailMessage.equals(this.detailMessage)));
95      }
96  
97  
98      /***
99       * Returns a String representation of the VerificationResult.
100      */
101     public String toString() {
102         String ret = "";
103         if (numeric == VERIFIED_NOTYET) {
104             ret = "VERIFIED_NOTYET";
105         }
106         if (numeric == VERIFIED_OK) {
107             ret = "VERIFIED_OK";
108         }
109         if (numeric == VERIFIED_REJECTED) {
110             ret = "VERIFIED_REJECTED";
111         }
112         ret += "\n" + detailMessage + "\n";
113         return ret;
114     }
115 }