|
|||||||||||||||||||
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover | |||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
MethodFabImpl.java | - | 100% | 100% | 100% |
|
1 |
// Copyright 2004 The Apache Software Foundation
|
|
2 |
//
|
|
3 |
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4 |
// you may not use this file except in compliance with the License.
|
|
5 |
// You may obtain a copy of the License at
|
|
6 |
//
|
|
7 |
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8 |
//
|
|
9 |
// Unless required by applicable law or agreed to in writing, software
|
|
10 |
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11 |
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12 |
// See the License for the specific language governing permissions and
|
|
13 |
// limitations under the License.
|
|
14 |
|
|
15 |
package org.apache.hivemind.service.impl;
|
|
16 |
|
|
17 |
import javassist.CtClass;
|
|
18 |
import javassist.CtMethod;
|
|
19 |
|
|
20 |
import org.apache.hivemind.ApplicationRuntimeException;
|
|
21 |
import org.apache.hivemind.service.MethodFab;
|
|
22 |
import org.apache.hivemind.service.MethodSignature;
|
|
23 |
|
|
24 |
/**
|
|
25 |
* Implementation of {@link org.apache.hivemind.service.MethodFab},
|
|
26 |
* which is returned
|
|
27 |
* from {@link org.apache.hivemind.service.ClassFab#addMethod(int, String, Class, Class[], Class[], String)},
|
|
28 |
* so that additional exception handlers may be attached to the added method.
|
|
29 |
*
|
|
30 |
* @author Howard Lewis Ship
|
|
31 |
*/
|
|
32 |
class MethodFabImpl implements MethodFab |
|
33 |
{ |
|
34 |
private CtClassSource _source;
|
|
35 |
private MethodSignature _signature;
|
|
36 |
private CtMethod _method;
|
|
37 |
|
|
38 | 2396 |
public MethodFabImpl(CtClassSource source, MethodSignature signature, CtMethod method)
|
39 |
{ |
|
40 | 2396 |
_source = source; |
41 | 2396 |
_signature = signature; |
42 | 2396 |
_method = method; |
43 |
} |
|
44 |
|
|
45 | 15 |
public void addCatch(Class exceptionClass, String catchBody) |
46 |
{ |
|
47 | 15 |
CtClass ctException = _source.getCtClass(exceptionClass); |
48 |
|
|
49 | 15 |
try
|
50 |
{ |
|
51 | 15 |
_method.addCatch(catchBody, ctException); |
52 |
} |
|
53 |
catch (Exception ex)
|
|
54 |
{ |
|
55 | 1 |
throw new ApplicationRuntimeException( |
56 |
ServiceMessages.unableToAddCatch(exceptionClass, _method, ex), |
|
57 |
ex); |
|
58 |
} |
|
59 |
} |
|
60 |
|
|
61 | 3 |
public void extend(String body, boolean asFinally) |
62 |
{ |
|
63 | 3 |
try
|
64 |
{ |
|
65 | 3 |
_method.insertAfter(body, asFinally); |
66 |
} |
|
67 |
catch (Exception ex)
|
|
68 |
{ |
|
69 | 1 |
throw new ApplicationRuntimeException( |
70 |
ServiceMessages.unableToExtendMethod( |
|
71 |
_signature, |
|
72 |
_method.getDeclaringClass().getName(), |
|
73 |
ex), |
|
74 |
ex); |
|
75 |
} |
|
76 |
} |
|
77 |
|
|
78 |
} |
|
79 |
|
|