Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
OJBSerializableProxy |
|
| 2.0;2 |
1 | package org.apache.ojb.broker.core.proxy; | |
2 | ||
3 | /* Copyright 2002-2005 The Apache Software Foundation | |
4 | * | |
5 | * Licensed under the Apache License, Version 2.0 (the "License"); | |
6 | * you may not use this file except in compliance with the License. | |
7 | * 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 | import java.io.ObjectStreamException; | |
19 | import java.io.Serializable; | |
20 | ||
21 | import org.apache.ojb.broker.util.logging.Logger; | |
22 | import org.apache.ojb.broker.util.logging.LoggerFactory; | |
23 | ||
24 | /** | |
25 | * @author andrew.clute | |
26 | * Simple class that is serializable, and containes references to an IndirectionHandler | |
27 | * and the base class. When the object is unserialized, it then generates a new Proxy | |
28 | * back in it's place. | |
29 | * | |
30 | */ | |
31 | public class OJBSerializableProxy implements Serializable | |
32 | { | |
33 | ||
34 | private static final long serialVersionUID = 568312334450175549L; | |
35 | private Logger logger = LoggerFactory.getLogger(OJBSerializableProxy.class); | |
36 | ||
37 | private Class classObject; | |
38 | ||
39 | private IndirectionHandler indirectionHandler; | |
40 | ||
41 | public OJBSerializableProxy(Class proxyClass, IndirectionHandler indirectionHandler) | |
42 | { | |
43 | this.classObject = proxyClass; | |
44 | this.indirectionHandler = indirectionHandler; | |
45 | } | |
46 | ||
47 | private Object readResolve() throws ObjectStreamException | |
48 | { | |
49 | try | |
50 | { | |
51 | return ProxyHelper.getProxyFactory().createProxy(classObject, indirectionHandler); | |
52 | } catch (Throwable e) | |
53 | { | |
54 | //Fail gracefully -- there a bunch of reasons why we cannot create the Proxy, and | |
55 | //so we just want to put a null into the reference. | |
56 | logger.warn("Unable to create a new Proxy of type '" + classObject.getName() + "' due to a '" + e.getClass().getName() + "'."); | |
57 | return null; | |
58 | } | |
59 | } | |
60 | ||
61 | } |