db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From b..@apache.org
Subject cvs commit: jakarta-ojb/src/java/org/apache/ojb/broker/util ProxyHelper.java
Date Tue, 17 Dec 2002 19:00:39 GMT
brj         2002/12/17 11:00:39

  Modified:    src/java/org/apache/ojb/broker/metadata/fieldaccess
                        PersistentFieldDefaultImpl.java
                        PersistentFieldMaxPerformanceImpl.java
  Added:       src/java/org/apache/ojb/broker/util ProxyHelper.java
  Log:
  use the new ProxyHelper to get the real object
  
  Revision  Changes    Path
  1.11      +4 -32     jakarta-ojb/src/java/org/apache/ojb/broker/metadata/fieldaccess/PersistentFieldDefaultImpl.java
  
  Index: PersistentFieldDefaultImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ojb/src/java/org/apache/ojb/broker/metadata/fieldaccess/PersistentFieldDefaultImpl.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- PersistentFieldDefaultImpl.java	17 Dec 2002 18:24:00 -0000	1.10
  +++ PersistentFieldDefaultImpl.java	17 Dec 2002 19:00:39 -0000	1.11
  @@ -56,13 +56,11 @@
   
   import java.io.Serializable;
   import java.lang.reflect.Field;
  -import java.lang.reflect.Proxy;
   import java.security.AccessController;
   import java.security.PrivilegedAction;
   
  -import org.apache.ojb.broker.VirtualProxy;
  -import org.apache.ojb.broker.accesslayer.IndirectionHandler;
   import org.apache.ojb.broker.metadata.MetadataException;
  +import org.apache.ojb.broker.util.ProxyHelper;
   import org.apache.ojb.broker.util.logging.Logger;
   import org.apache.ojb.broker.util.logging.LoggerFactory;
   
  @@ -137,7 +135,7 @@
   			 */
   			if ((value != null) || !type.isPrimitive())
   			{
  -				f.set(ensureRealObject(obj), value);
  +				f.set(ProxyHelper.getRealObject(obj), value);
   			}	
   		}
           catch (NullPointerException ignored)
  @@ -179,7 +177,7 @@
   		try
   		{
   			Field field = getField();
  -			Object result = field.get(ensureRealObject(obj));
  +			Object result = field.get(ProxyHelper.getRealObject(obj));
   
   			return result;
   		}
  @@ -200,32 +198,6 @@
               field.setAccessible(before);
           }
   	}
  -
  -    /**
  -     * get the real object for objectOrProxy
  -     * @param objectOrProxy
  -     * @return Object
  -     */
  -    protected Object ensureRealObject(Object objectOrProxy)
  -    {
  -        IndirectionHandler handler;
  -
  -        if (Proxy.isProxyClass(objectOrProxy.getClass()))
  -        {
  -            handler = (IndirectionHandler) Proxy.getInvocationHandler(objectOrProxy);
  -            return handler.getRealSubject();
  -        }
  -        else if (objectOrProxy instanceof VirtualProxy)
  -        {
  -            handler = (IndirectionHandler) VirtualProxy.getIndirectionHandler((VirtualProxy)objectOrProxy);
  -            return handler.getRealSubject();
  -        }
  -        else
  -        {
  -            return objectOrProxy;
  -        }
  -    }
  -
   
   	/**
   	 * Tries to compute a Field object using getFieldRecursive.
  
  
  
  1.10      +4 -3      jakarta-ojb/src/java/org/apache/ojb/broker/metadata/fieldaccess/PersistentFieldMaxPerformanceImpl.java
  
  Index: PersistentFieldMaxPerformanceImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ojb/src/java/org/apache/ojb/broker/metadata/fieldaccess/PersistentFieldMaxPerformanceImpl.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- PersistentFieldMaxPerformanceImpl.java	17 Dec 2002 18:24:00 -0000	1.9
  +++ PersistentFieldMaxPerformanceImpl.java	17 Dec 2002 19:00:39 -0000	1.10
  @@ -60,6 +60,7 @@
   import org.apache.ojb.broker.VirtualProxy;
   import org.apache.ojb.broker.accesslayer.IndirectionHandler;
   import org.apache.ojb.broker.metadata.MetadataException;
  +import org.apache.ojb.broker.util.ProxyHelper;
   import org.apache.ojb.broker.util.logging.Logger;
   import org.apache.ojb.broker.util.logging.LoggerFactory;
   
  @@ -125,7 +126,7 @@
   			// thanks to Tomasz Wysocki for this trick
   			if ((value != null) || !type.isPrimitive())
   			{
  -				f.set(ensureRealObject(obj), value);
  +				f.set(ProxyHelper.getRealObject(obj), value);
   			}
   		}
   		catch (NullPointerException ignored)
  @@ -155,7 +156,7 @@
   		try
   		{
   			Field field = getField();
  -			Object result = field.get(ensureRealObject(obj));
  +			Object result = field.get(ProxyHelper.getRealObject(obj));
   			return result;
   		}
   		catch (IllegalAccessException e)
  
  
  
  1.1                  jakarta-ojb/src/java/org/apache/ojb/broker/util/ProxyHelper.java
  
  Index: ProxyHelper.java
  ===================================================================
  package org.apache.ojb.broker.util;
  
  import java.lang.reflect.Proxy;
  
  import org.apache.ojb.broker.VirtualProxy;
  import org.apache.ojb.broker.accesslayer.IndirectionHandler;
  
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache ObjectRelationalBridge" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache ObjectRelationalBridge", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  /**
   * ProxyHelper used to get the real thing behind a proxy
   *
   * @author <a href="mailto:jbraeuchi@hotmail.com">Jakob Braeuchi</a>
   * @version $Id: ProxyHelper.java,v 1.1 2002/12/17 19:00:39 brj Exp $
   */
  public class ProxyHelper
  {
  
      /**
       * Get the real Object
       * 
       * @param objectOrProxy
       * @return Object
       */
      public static final Object getRealObject(Object objectOrProxy)
      {
          IndirectionHandler handler;
  
          if (Proxy.isProxyClass(objectOrProxy.getClass()))
          {
              handler = (IndirectionHandler) Proxy.getInvocationHandler(objectOrProxy);
              return handler.getRealSubject();
          }
          else if (objectOrProxy instanceof VirtualProxy)
          {
              return ((VirtualProxy)objectOrProxy).getRealSubject();
          }
          else
          {
              return objectOrProxy;
          }
      }    
  
      /**
       * Get the real Class
       * 
       * @param objectOrProxy
       * @return Class
       */
      public static final Class getRealClass(Object objectOrProxy)
      {
          IndirectionHandler handler;
  
          if (Proxy.isProxyClass(objectOrProxy.getClass()))
          {
              handler = (IndirectionHandler) Proxy.getInvocationHandler(objectOrProxy);
              return handler.getIdentity().getObjectsClass();
          }
          else if (objectOrProxy instanceof VirtualProxy)
          {
              handler = (IndirectionHandler) VirtualProxy.getIndirectionHandler((VirtualProxy)objectOrProxy);
              return handler.getIdentity().getObjectsClass();
          }
          else
          {
              return objectOrProxy.getClass();
          }
      }    
  
  
  }
  
  
  

Mime
View raw message