Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
DeserializationPostInitialisable |
|
| 0.0;0 | ||||
DeserializationPostInitialisable$Implementation |
|
| 0.0;0 | ||||
DeserializationPostInitialisable$Implementation$1 |
|
| 0.0;0 |
1 | /* | |
2 | * $Id: DeserializationPostInitialisable.java 20321 2010-11-24 15:21:24Z dfeist $ | |
3 | * -------------------------------------------------------------------------------------- | |
4 | * Copyright (c) MuleSoft, Inc. All rights reserved. http://www.mulesoft.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.util.store; | |
12 | ||
13 | import org.mule.api.MuleContext; | |
14 | ||
15 | import java.lang.reflect.Method; | |
16 | import java.security.AccessController; | |
17 | import java.security.PrivilegedAction; | |
18 | ||
19 | /** | |
20 | * A marker interface used to trigger post-deserialization initialization of an object. This works | |
21 | * in the same way as {@link Cloneable} interface. Implementors of this interface must add the | |
22 | * method <code>private void initAfterDeserialization(MuleContext muleContext) throws MuleException</code> | |
23 | * to their class (note that it's private). This will get invoked after the object has been | |
24 | * deserialized passing in the current mulecontext when using either | |
25 | * {@link org.mule.transformer.wire.SerializationWireFormat}, | |
26 | * {@link org.mule.transformer.wire.SerializedMuleMessageWireFormat}, or the | |
27 | * {@link org.mule.transformer.simple.ByteArrayToSerializable} transformer. | |
28 | * | |
29 | * @see org.mule.transformer.simple.ByteArrayToSerializable | |
30 | * @see org.mule.transformer.wire.SerializationWireFormat | |
31 | * @see org.mule.transformer.wire.SerializedMuleMessageWireFormat | |
32 | */ | |
33 | public interface DeserializationPostInitialisable | |
34 | { | |
35 | //private void initAfterDeserialisation(MuleContext muleContext) throws MuleException; | |
36 | ||
37 | 0 | public class Implementation |
38 | { | |
39 | public static void init(final Object object, final MuleContext muleContext) throws Exception | |
40 | { | |
41 | try | |
42 | { | |
43 | 0 | final Method m = object.getClass().getDeclaredMethod("initAfterDeserialisation", |
44 | MuleContext.class); | |
45 | ||
46 | 0 | Object o = AccessController.doPrivileged(new PrivilegedAction<Object>() |
47 | 0 | { |
48 | public Object run() | |
49 | { | |
50 | try | |
51 | { | |
52 | 0 | m.setAccessible(true); |
53 | 0 | m.invoke(object, muleContext); |
54 | 0 | return null; |
55 | } | |
56 | 0 | catch (Exception e) |
57 | { | |
58 | 0 | return e; |
59 | } | |
60 | ||
61 | } | |
62 | }); | |
63 | ||
64 | 0 | if (o != null) |
65 | { | |
66 | 0 | throw (Exception) o; |
67 | } | |
68 | ||
69 | } | |
70 | 0 | catch (NoSuchMethodException e) |
71 | { | |
72 | 0 | throw new IllegalArgumentException("Object " + object.getClass() + " implements " + |
73 | DeserializationPostInitialisable.class + " but does not have a method " + | |
74 | "private void initAfterDeserialisation(MuleContext) defined", e); | |
75 | 0 | } |
76 | 0 | } |
77 | } | |
78 | } |