Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
AbstractPerfidixMethodException |
|
| 3.142857142857143;3.143 |
1 | /** | |
2 | * Copyright (c) 2012, University of Konstanz, Distributed Systems Group | |
3 | * All rights reserved. | |
4 | * | |
5 | * Redistribution and use in source and binary forms, with or without | |
6 | * modification, are permitted provided that the following conditions are met: | |
7 | * * Redistributions of source code must retain the above copyright | |
8 | * notice, this list of conditions and the following disclaimer. | |
9 | * * Redistributions in binary form must reproduce the above copyright | |
10 | * notice, this list of conditions and the following disclaimer in the | |
11 | * documentation and/or other materials provided with the distribution. | |
12 | * * Neither the name of the University of Konstanz nor the | |
13 | * names of its contributors may be used to endorse or promote products | |
14 | * derived from this software without specific prior written permission. | |
15 | * | |
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | |
17 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | |
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
19 | * DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY | |
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | |
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | |
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | |
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
26 | */ | |
27 | package org.perfidix.exceptions; | |
28 | ||
29 | import java.lang.annotation.Annotation; | |
30 | import java.lang.reflect.Method; | |
31 | ||
32 | /** | |
33 | * This class acts as a super exception for all exception thrown by the Perfidix | |
34 | * framework while invoking methods. | |
35 | * | |
36 | * @author Sebastian Graf, University of Konstanz | |
37 | */ | |
38 | public abstract class AbstractPerfidixMethodException extends Exception { | |
39 | /** Serial because of serializable. */ | |
40 | private static final long serialVersionUID = 5251116501564408317L; | |
41 | ||
42 | /** | |
43 | * Encapsulated Exception. | |
44 | */ | |
45 | private transient final Throwable exec; | |
46 | ||
47 | /** | |
48 | * Related method. | |
49 | */ | |
50 | private transient final Method meth; | |
51 | ||
52 | /** Related annotation to this method. */ | |
53 | private transient final Class<? extends Annotation> relatedAnno; | |
54 | ||
55 | /** | |
56 | * Simple Constructor. | |
57 | * | |
58 | * @param paramExec | |
59 | * the exception to be hold in this container. | |
60 | * @param paramMeth | |
61 | * the related method to the exception. | |
62 | * @param paramAnnotation | |
63 | * the related annotation to this method | |
64 | */ | |
65 | public AbstractPerfidixMethodException(final Throwable paramExec, final Method paramMeth, | |
66 | final Class<? extends Annotation> paramAnnotation) { | |
67 | 116 | super(); |
68 | 116 | this.exec = paramExec; |
69 | 116 | this.meth = paramMeth; |
70 | 116 | this.relatedAnno = paramAnnotation; |
71 | 116 | } |
72 | ||
73 | /** | |
74 | * Getter for the related {@link Method}. | |
75 | * | |
76 | * @return the method for this exception. | |
77 | */ | |
78 | public final Method getMethod() { | |
79 | 154 | return meth; |
80 | } | |
81 | ||
82 | /** | |
83 | * Getter for the encapsulated {@link Exception}. | |
84 | * | |
85 | * @return the exec which is hold in this container. | |
86 | */ | |
87 | public final Throwable getExec() { | |
88 | 56 | return exec; |
89 | } | |
90 | ||
91 | /** | |
92 | * Getter for annotation. | |
93 | * | |
94 | * @return the related annotation for this errored method | |
95 | */ | |
96 | public final Class<? extends Annotation> getRelatedAnno() { | |
97 | 51 | return relatedAnno; |
98 | } | |
99 | ||
100 | /** {@inheritDoc} */ | |
101 | @Override | |
102 | public final int hashCode() { | |
103 | 101 | final int prime = 31; |
104 | 101 | int result = 1; |
105 | 101 | if (exec == null) { |
106 | 0 | result = prime * result; |
107 | } else { | |
108 | 101 | result = prime * result + exec.hashCode(); |
109 | } | |
110 | 101 | if (meth == null) { |
111 | 0 | result = prime * result; |
112 | } else { | |
113 | 101 | result = prime * result + meth.hashCode(); |
114 | } | |
115 | 101 | if (relatedAnno == null) { |
116 | 0 | result = prime * result; |
117 | } else { | |
118 | 101 | result = prime * result + relatedAnno.hashCode(); |
119 | } | |
120 | 101 | return result; |
121 | } | |
122 | ||
123 | /** {@inheritDoc} */ | |
124 | @Override | |
125 | public final boolean equals(final Object obj) { | |
126 | 5 | boolean returnVal = true; |
127 | 5 | if (this == obj) { |
128 | 0 | returnVal = true; |
129 | } | |
130 | 5 | if (obj == null) { |
131 | 0 | returnVal = false; |
132 | } | |
133 | 5 | if (getClass() != obj.getClass()) { |
134 | 0 | returnVal = false; |
135 | } | |
136 | 5 | final AbstractPerfidixMethodException other = (AbstractPerfidixMethodException)obj; |
137 | 5 | if (exec == null) { |
138 | 0 | if (other.exec != null) { |
139 | 0 | returnVal = false; |
140 | } | |
141 | } else { | |
142 | 5 | if (!exec.equals(other.exec)) { |
143 | 0 | returnVal = false; |
144 | } | |
145 | } | |
146 | 5 | if (meth == null) { |
147 | 0 | if (other.meth != null) { |
148 | 0 | returnVal = false; |
149 | } | |
150 | } else { | |
151 | 5 | if (!meth.equals(other.meth)) { |
152 | 0 | returnVal = false; |
153 | } | |
154 | } | |
155 | 5 | if (relatedAnno == null) { |
156 | 0 | if (other.relatedAnno != null) { |
157 | 0 | returnVal = false; |
158 | } | |
159 | } else { | |
160 | 5 | if (!relatedAnno.equals(other.relatedAnno)) { |
161 | 0 | returnVal = false; |
162 | } | |
163 | } | |
164 | 5 | return returnVal; |
165 | } | |
166 | ||
167 | /** | |
168 | * {@inheritDoc} | |
169 | */ | |
170 | @Override | |
171 | public final String toString() { | |
172 | 0 | final StringBuilder builder = new StringBuilder(); |
173 | 0 | builder.append(this.getClass().getSimpleName()); |
174 | 0 | builder.append(":"); |
175 | 0 | builder.append(this.exec.getClass().getSimpleName()); |
176 | 0 | builder.append(":"); |
177 | 0 | builder.append(this.relatedAnno.getClass().getSimpleName()); |
178 | 0 | builder.append(":"); |
179 | 0 | builder.append(this.meth.getName()); |
180 | 0 | return builder.toString(); |
181 | } | |
182 | ||
183 | } |