• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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  */
18 package org.apache.bcel.verifier;
19 
20 /**
21  * A VerificationResult is what a PassVerifier returns
22  * after verifying.
23  *
24  * @version $Id$
25  */
26 public class VerificationResult {
27 
28     /**
29      * Constant to indicate verification has not been tried yet.
30      * This happens if some earlier verification pass did not return VERIFIED_OK.
31      */
32     public static final int VERIFIED_NOTYET = 0;
33 
34     /** Constant to indicate verification was passed. */
35     public static final int VERIFIED_OK = 1;
36 
37     /** Constant to indicate verfication failed. */
38     public static final int VERIFIED_REJECTED = 2;
39 
40     /**
41      * This string is the canonical message for verifications that have not been tried yet.
42      * This happens if some earlier verification pass did not return {@link #VERIFIED_OK}.
43      */
44     private static final String VERIFIED_NOTYET_MSG = "Not yet verified.";
45 
46     /** This string is the canonical message for passed verification passes. */
47     private static final String VERIFIED_OK_MSG = "Passed verification.";
48 
49     /**
50      * Canonical VerificationResult for not-yet-tried verifications.
51      * This happens if some earlier verification pass did not return {@link #VERIFIED_OK}.
52      */
53     public static final VerificationResult VR_NOTYET = new VerificationResult(VERIFIED_NOTYET, VERIFIED_NOTYET_MSG);
54 
55     /** Canonical VerificationResult for passed verifications. */
56     public static final VerificationResult VR_OK = new VerificationResult(VERIFIED_OK, VERIFIED_OK_MSG);
57 
58     /** The numeric status. */
59     private final int numeric;
60 
61     /** The detailed message. */
62     private final String detailMessage;
63 
64 
65     /** The usual constructor. */
VerificationResult(final int status, final String message)66     public VerificationResult(final int status, final String message) {
67         numeric = status;
68         detailMessage = message;
69     }
70 
71 
72     /**
73      * Returns one of the {@link #VERIFIED_OK}, {@link #VERIFIED_NOTYET},
74      * {@link #VERIFIED_REJECTED} constants.
75      */
getStatus()76     public int getStatus() {
77         return numeric;
78     }
79 
80 
81     /** Returns a detailed message. */
getMessage()82     public String getMessage() {
83         return detailMessage;
84     }
85 
86 
87     /**
88      * @return a hash code value for the object.
89      */
90     @Override
hashCode()91     public int hashCode() {
92         return numeric ^ detailMessage.hashCode();
93     }
94 
95 
96     /**
97      * Returns if two VerificationResult instances are equal.
98      */
99     @Override
equals( final Object o )100     public boolean equals( final Object o ) {
101         if (!(o instanceof VerificationResult)) {
102             return false;
103         }
104         final VerificationResult other = (VerificationResult) o;
105         return (other.numeric == this.numeric) && other.detailMessage.equals(this.detailMessage);
106     }
107 
108 
109     /**
110      * Returns a String representation of the VerificationResult.
111      */
112     @Override
toString()113     public String toString() {
114         String ret = "";
115         if (numeric == VERIFIED_NOTYET) {
116             ret = "VERIFIED_NOTYET";
117         }
118         if (numeric == VERIFIED_OK) {
119             ret = "VERIFIED_OK";
120         }
121         if (numeric == VERIFIED_REJECTED) {
122             ret = "VERIFIED_REJECTED";
123         }
124         ret += "\n" + detailMessage + "\n";
125         return ret;
126     }
127 }
128