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