Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
InterceptorAdapter |
|
| 2.0;2 |
1 | /* | |
2 | * $Id: InterceptorAdapter.java 11130 2008-02-29 15:14:53Z acooke $ | |
3 | * -------------------------------------------------------------------------------------- | |
4 | * Copyright (c) MuleSource, Inc. All rights reserved. http://www.mulesource.com | |
5 | * | |
6 | * The software in this package is published under the terms of the CPAL v1.0 | |
7 | * license, a copy of which has been included with this distribution in the | |
8 | * LICENSE.txt file. | |
9 | */ | |
10 | ||
11 | package org.mule.module.spring.interceptor; | |
12 | ||
13 | import org.mule.api.interceptor.Interceptor; | |
14 | import org.mule.api.MuleMessage; | |
15 | ||
16 | import org.aopalliance.intercept.MethodInterceptor; | |
17 | import org.aopalliance.intercept.MethodInvocation; | |
18 | ||
19 | /** | |
20 | * This adapts an implementation of the {@link Interceptor} interface for use with the Spring AOP | |
21 | * interceptor framework. Note that the Interceptor implementation can return null if it does not | |
22 | * want to change the result - the appropriate {@link MuleMessage} will then be constructed correctly | |
23 | * by Mule. | |
24 | */ | |
25 | 0 | public class InterceptorAdapter implements MethodInterceptor |
26 | { | |
27 | ||
28 | private Interceptor interceptor; | |
29 | ||
30 | public Object invoke(MethodInvocation invocation) throws Throwable | |
31 | { | |
32 | 0 | InvocationAdapter adapter = new InvocationAdapter(invocation); |
33 | 0 | MuleMessage message = interceptor.intercept(adapter); |
34 | 0 | if (null == message) |
35 | { | |
36 | 0 | return adapter.getResult(); |
37 | } | |
38 | else | |
39 | { | |
40 | 0 | return message; |
41 | } | |
42 | } | |
43 | ||
44 | public void setInterceptor(Interceptor interceptor) | |
45 | { | |
46 | 0 | this.interceptor = interceptor; |
47 | 0 | } |
48 | ||
49 | } |