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