01: package org.apache.ojb.broker.core.proxy;
02:
03: /* Copyright 2002-2005 The Apache Software Foundation
04: *
05: * Licensed under the Apache License, Version 2.0 (the "License");
06: * you may not use this file except in compliance with the License.
07: * You may obtain a copy of the License at
08: *
09: * 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: private static final long serialVersionUID = 568312334450175549L;
34: private Logger logger = LoggerFactory
35: .getLogger(OJBSerializableProxy.class);
36:
37: private Class classObject;
38:
39: private IndirectionHandler indirectionHandler;
40:
41: public OJBSerializableProxy(Class proxyClass,
42: IndirectionHandler indirectionHandler) {
43: this .classObject = proxyClass;
44: this .indirectionHandler = indirectionHandler;
45: }
46:
47: private Object readResolve() throws ObjectStreamException {
48: try {
49: return ProxyHelper.getProxyFactory().createProxy(
50: classObject, indirectionHandler);
51: } catch (Throwable e) {
52: //Fail gracefully -- there a bunch of reasons why we cannot create the Proxy, and
53: //so we just want to put a null into the reference.
54: logger.warn("Unable to create a new Proxy of type '"
55: + classObject.getName() + "' due to a '"
56: + e.getClass().getName() + "'.");
57: return null;
58: }
59: }
60:
61: }
|