001 package org.apache.ojb.broker.core.proxy;
002
003 /* Copyright 2002-2005 The Apache Software Foundation
004 *
005 * Licensed under the Apache License, Version 2.0 (the "License");
006 * you may not use this file except in compliance with the License.
007 * You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017
018 import java.io.ObjectStreamException;
019 import java.io.Serializable;
020
021 import org.apache.ojb.broker.util.logging.Logger;
022 import org.apache.ojb.broker.util.logging.LoggerFactory;
023
024 /**
025 * @author andrew.clute
026 * Simple class that is serializable, and containes references to an IndirectionHandler
027 * and the base class. When the object is unserialized, it then generates a new Proxy
028 * back in it's place.
029 *
030 */
031 public class OJBSerializableProxy implements Serializable
032 {
033
034 private static final long serialVersionUID = 568312334450175549L;
035 private Logger logger = LoggerFactory.getLogger(OJBSerializableProxy.class);
036
037 private Class classObject;
038
039 private IndirectionHandler indirectionHandler;
040
041 public OJBSerializableProxy(Class proxyClass, IndirectionHandler indirectionHandler)
042 {
043 this.classObject = proxyClass;
044 this.indirectionHandler = indirectionHandler;
045 }
046
047 private Object readResolve() throws ObjectStreamException
048 {
049 try
050 {
051 return ProxyHelper.getProxyFactory().createProxy(classObject, indirectionHandler);
052 } catch (Throwable e)
053 {
054 //Fail gracefully -- there a bunch of reasons why we cannot create the Proxy, and
055 //so we just want to put a null into the reference.
056 logger.warn("Unable to create a new Proxy of type '" + classObject.getName() + "' due to a '" + e.getClass().getName() + "'.");
057 return null;
058 }
059 }
060
061 }