001: /*
002: * Copyright 2000-2004 The Apache Software Foundation
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: *
016: */
017: package org.apache.bcel.verifier;
018:
019: /**
020: * A VerificationResult is what a PassVerifier returns
021: * after verifying.
022: *
023: * @version $Id: VerificationResult.java 386056 2006-03-15 11:31:56Z tcurdt $
024: * @author Enver Haase
025: *
026: */
027: public class VerificationResult {
028:
029: /**
030: * Constant to indicate verification has not been tried yet.
031: * This happens if some earlier verification pass did not return VERIFIED_OK.
032: */
033: public static final int VERIFIED_NOTYET = 0;
034: /** Constant to indicate verification was passed. */
035: public static final int VERIFIED_OK = 1;
036: /** Constant to indicate verfication failed. */
037: public static final int VERIFIED_REJECTED = 2;
038: /**
039: * This string is the canonical message for verifications that have not been tried yet.
040: * This happens if some earlier verification pass did not return VERIFIED_OK.
041: */
042: private static final String VERIFIED_NOTYET_MSG = "Not yet verified.";
043: /** This string is the canonical message for passed verification passes. */
044: private static final String VERIFIED_OK_MSG = "Passed verification.";
045: /**
046: * Canonical VerificationResult for not-yet-tried verifications.
047: * This happens if some earlier verification pass did not return VERIFIED_OK.
048: */
049: public static final VerificationResult VR_NOTYET = new VerificationResult(
050: VERIFIED_NOTYET, VERIFIED_NOTYET_MSG);
051: /** Canonical VerificationResult for passed verifications. */
052: public static final VerificationResult VR_OK = new VerificationResult(
053: VERIFIED_OK, VERIFIED_OK_MSG);
054: /** The numeric status. */
055: private int numeric;
056: /** The detailed message. */
057: private String detailMessage;
058:
059: /** The usual constructor. */
060: public VerificationResult(int status, String message) {
061: numeric = status;
062: detailMessage = message;
063: }
064:
065: /** Returns one one the VERIFIED_OK, VERIFIED_NOTYET, VERIFIED_REJECTED constants. */
066: public int getStatus() {
067: return numeric;
068: }
069:
070: /** Returns a detailed message. */
071: public String getMessage() {
072: return detailMessage;
073: }
074:
075: /** @return a hash code value for the object.
076: */
077: public int hashCode() {
078: return numeric ^ detailMessage.hashCode();
079: }
080:
081: /**
082: * Returns if two VerificationResult instances are equal.
083: */
084: public boolean equals(Object o) {
085: if (!(o instanceof VerificationResult)) {
086: return false;
087: }
088: VerificationResult other = (VerificationResult) o;
089: return ((other.numeric == this .numeric) && (other.detailMessage
090: .equals(this .detailMessage)));
091: }
092:
093: /**
094: * Returns a String representation of the VerificationResult.
095: */
096: public String toString() {
097: String ret = "";
098: if (numeric == VERIFIED_NOTYET) {
099: ret = "VERIFIED_NOTYET";
100: }
101: if (numeric == VERIFIED_OK) {
102: ret = "VERIFIED_OK";
103: }
104: if (numeric == VERIFIED_REJECTED) {
105: ret = "VERIFIED_REJECTED";
106: }
107: ret += "\n" + detailMessage + "\n";
108: return ret;
109: }
110: }
|