db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From arm...@apache.org
Subject cvs commit: db-ojb/src/java/org/apache/ojb/broker/metadata/fieldaccess PersistentFieldIntrospectorImpl.java PersistentFieldDynaBeanAccessImpl.java PersistentNestedFieldMaxPerformanceImpl.java PersistentFieldPropertyImpl.java PersistentFieldPrivilegedImpl.java PersistentFieldMaxPerformanceImpl.java PersistentFieldFactory.java PersistentFieldDynaBeanImpl.java PersistentFieldDirectAccessImpl.java PersistentFieldDefaultImpl.java AbstractPersistentField.java
Date Tue, 08 Jul 2003 14:30:08 GMT
arminw      2003/07/08 07:30:08

  Modified:    src/test/org/apache/ojb OJB.properties
               src/java/org/apache/ojb/broker/metadata/fieldaccess
                        PersistentNestedFieldMaxPerformanceImpl.java
                        PersistentFieldPropertyImpl.java
                        PersistentFieldPrivilegedImpl.java
                        PersistentFieldMaxPerformanceImpl.java
                        PersistentFieldFactory.java
                        PersistentFieldDynaBeanImpl.java
                        PersistentFieldDirectAccessImpl.java
                        PersistentFieldDefaultImpl.java
                        AbstractPersistentField.java
  Added:       src/java/org/apache/ojb/broker/metadata/fieldaccess
                        PersistentFieldIntrospectorImpl.java
                        PersistentFieldDynaBeanAccessImpl.java
  Log:
  refactoring the fieldacces package:
  - declare old PersistentField implementations
  deprecated
  - new implementations inherit from an abstract
  base class reusing existing code
  - all implementations now support nested
  fields of arbitrary level depth
  
  Revision  Changes    Path
  1.52      +25 -17    db-ojb/src/test/org/apache/ojb/OJB.properties
  
  Index: OJB.properties
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/OJB.properties,v
  retrieving revision 1.51
  retrieving revision 1.52
  diff -u -r1.51 -r1.52
  --- OJB.properties	30 Jun 2003 21:18:22 -0000	1.51
  +++ OJB.properties	8 Jul 2003 14:30:07 -0000	1.52
  @@ -302,27 +302,35 @@
   #----------------------------------------------------------------------------------------
   # The PersistentFieldClass property defines the implementation class
   # for PersistentField attributes used in the OJB MetaData layer.
  -# By default a attribute based Version using Reflection is selected.
  -# using this Class persistent attributes don't need getters and setters
  -# and don't have to be declared public or protected.
  +# By default the best performing attribute/refection based implementation
  +# is selected (PersistentFieldDirectAccessImpl).
   #
  -#PersistentFieldClass=org.apache.ojb.broker.metadata.fieldaccess.PersistentFieldDefaultImpl
  +# - PersistentFieldDirectAccessImpl
  +#   is a high-speed version of the access strategies.
  +#   It does not cooperate with an AccessController,
  +#   but accesses the fields directly. Persistent
  +#   attributes don't need getters and setters
  +#   and don't have to be declared public or protected
  +# - PersistentFieldPrivilegedImpl
  +#   Same as above, but does cooperate with AccessController and do not
  +#   suppress the java language access check.
  +# - PersistentFieldIntrospectorImpl
  +#   uses JavaBeans compliant calls only to access persistent attributes.
  +#   No Reflection is needed. But for each attribute xxx there must be
  +#   public getXxx() and setXxx() methods.
  +# - PersistentFieldDynaBeanAccessImpl
  +#   implementation used to access a property from a
  +#   org.apache.commons.beanutils.DynaBean.
  +#
  +#PersistentFieldClass=org.apache.ojb.broker.metadata.fieldaccess.PersistentFieldDirectAccessImpl
  +#PersistentFieldClass=org.apache.ojb.broker.metadata.fieldaccess.PersistentFieldPrivilegedImpl
  +PersistentFieldClass=org.apache.ojb.broker.metadata.fieldaccess.PersistentFieldIntrospectorImpl
  +#PersistentFieldClass=org.apache.ojb.broker.metadata.fieldaccess.PersistentFieldDynaBeanAccessImpl
   #
  -# There is also a high-speed version of this access strategy avalaible.
  -# The PersistentFieldMaxPerformanceImpl does not cooperate with
  -# an AccessController, but accesses the fields directly.
  +# outdated deprecated versions:
   #PersistentFieldClass=org.apache.ojb.broker.metadata.fieldaccess.PersistentFieldMaxPerformanceImpl
  -#
  -# in addition PersistentNestedFieldMaxPerformanceImpl provides support
  -# for nested (or embedded) fields:
  -PersistentFieldClass=org.apache.ojb.broker.metadata.fieldaccess.PersistentNestedFieldMaxPerformanceImpl
  -#
  -# The PersistentFieldPropertyImpl uses JavaBeans comformant calls only
  -# to access persistent attributes. No Reflection is needed.
  -# But for each attribute xxx there must be public getXxx() and setXxx() methods.
  -#
  +#PersistentFieldClass=org.apache.ojb.broker.metadata.fieldaccess.PersistentNestedFieldMaxPerformanceImpl
   #PersistentFieldClass=org.apache.ojb.broker.metadata.fieldaccess.PersistentFieldPropertyImpl
  -#
   #
   #----------------------------------------------------------------------------------------
   # Component Intercepting for Profiling and Tracing
  
  
  
  1.10      +18 -16    db-ojb/src/java/org/apache/ojb/broker/metadata/fieldaccess/PersistentNestedFieldMaxPerformanceImpl.java
  
  Index: PersistentNestedFieldMaxPerformanceImpl.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/metadata/fieldaccess/PersistentNestedFieldMaxPerformanceImpl.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- PersistentNestedFieldMaxPerformanceImpl.java	3 Jul 2003 09:55:07 -0000	1.9
  +++ PersistentNestedFieldMaxPerformanceImpl.java	8 Jul 2003 14:30:07 -0000	1.10
  @@ -1,15 +1,17 @@
   package org.apache.ojb.broker.metadata.fieldaccess;
   
  -import java.lang.reflect.Field;
  -
   import org.apache.ojb.broker.metadata.MetadataException;
   import org.apache.ojb.broker.util.ProxyHelper;
   
  +import java.lang.reflect.Field;
  +
   /**
    *
    * This class supports using of nested attribute.
    * @author Atipon Pongpat
    * @author Thomas Mahler
  + *
  + * @deprecated use {@link PersistentFieldDirectAccessImpl} instead
    * @version $Id$
    */
   public class PersistentNestedFieldMaxPerformanceImpl extends PersistentFieldMaxPerformanceImpl
  @@ -131,10 +133,10 @@
                               e);
                   }
                   Class type = pField.getType();
  -				if ((value != null) || !type.isPrimitive())
  -				{
  -                	pField.set(ProxyHelper.getRealObject(obj), attrib);
  -				}
  +                if ((value != null) || !type.isPrimitive())
  +                {
  +                    pField.set(ProxyHelper.getRealObject(obj), attrib);
  +                }
               }
               //
               String nestedName = fieldName.substring(index + PATH_TOKEN.length());
  @@ -187,13 +189,13 @@
           return result;
       }
   
  -	public boolean usesAccessorsAndMutators()
  -	{
  -		return false;
  -	}
  -
  -	 public String getName()
  -	 {
  -	 	return this.m_fieldname;
  -	 }
  +    public boolean usesAccessorsAndMutators()
  +    {
  +        return false;
  +    }
  +
  +    public String getName()
  +    {
  +        return this.m_fieldname;
  +    }
   }
  
  
  
  1.6       +230 -229  db-ojb/src/java/org/apache/ojb/broker/metadata/fieldaccess/PersistentFieldPropertyImpl.java
  
  Index: PersistentFieldPropertyImpl.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/metadata/fieldaccess/PersistentFieldPropertyImpl.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- PersistentFieldPropertyImpl.java	20 Dec 2002 21:49:00 -0000	1.5
  +++ PersistentFieldPropertyImpl.java	8 Jul 2003 14:30:07 -0000	1.6
  @@ -66,246 +66,247 @@
   
   /**
    * Access Fileds using Properties
  + *
  + * @deprecated use {@link PersistentFieldIntrospectorImpl} instead
    * @author <a href="mailto:jbraeuchi@hotmail.com">Jakob Braeuchi</a>
    * @version $Id$
    */
   public class PersistentFieldPropertyImpl implements PersistentField
   {
   
  -	private java.lang.Class declaringClass;
  -	private String propertyName;
  -	private transient java.beans.PropertyDescriptor propertyDescriptor;
  -	
  -	/**
  -	* Make the newInstace with no constructor call happy!
  -	*/
  -	public PersistentFieldPropertyImpl()
  -	{
  -
  -	}
  -
  -	public PersistentFieldPropertyImpl(Class aClass, String aPropertyName)
  -	{
  -		setDeclaringClass(aClass);
  -		setPropertyName(aPropertyName);
  -		setPropertyDescriptor(findPropertyDescriptor(aClass, aPropertyName));
  -	}
  -
  -	/**
  -	 * Sets aValue for anObject
  -	 */
  -	public void set(Object anObject, Object aValue) throws MetadataException
  -	{
  -		Method m = getPropertyDescriptor().getWriteMethod();
  -		Object[] args = { aValue };
  -		if (m != null)
  -		{
  -			try
  -			{
  -				/**
  -				 * MBAIRD: it is safe to call getParameterTypes()[0] because this is
  -				 * the "set" method and it needs to take one parameter only.
  -				 * we need to be able to set values to null. We can only set something to null if
  -				 * the type is not a primitive (assignable from Object).
  -				 */
  -				if ((aValue != null) || !m.getParameterTypes()[0].isPrimitive())
  -				{
  -					m.invoke(anObject, args);
  -				}
  -			}
  -			catch (Throwable e)
  -			{
  -				logProblem(anObject, aValue, e.getClass().getName());
  -				throw new MetadataException("Error invoking method:" + m.getName() + " in object:" + anObject.getClass().getName(), e);
  -			}
  -		}
  -		else
  -		{
  -			logProblem(anObject, aValue, "set: getWriteMethod returned null");
  -			throw new MetadataException(
  -				"Can't get WriteMethod for property:" + getPropertyDescriptor().getName() + " in object:" + anObject.getClass().getName());
  -		}
  -	}
  -
  -	/**
  -	 * Let's give the user some hints as to what could be wrong.
  -	 */
  -	protected void logProblem(Object anObject, Object aValue, String msg)
  -	{
  -		Logger logger = LoggerFactory.getDefaultLogger();
  -		logger.error("Error in [PersistentFieldPropertyImpl], " + msg);
  -		logger.error("Declaring class [" + getDeclaringClass().getName() + "]");
  -		logger.error("Property Name [" + getPropertyName() + "]");
  -		logger.error("Property Type [" + getPropertyDescriptor().getPropertyType().getName() + "]");
  -
  -		if (anObject != null)
  -		{
  -			logger.error("anObject was class [" + anObject.getClass().getName() + "]");
  -		}
  -		else
  -		{
  -			logger.error("anObject was null");
  -		}
  -		if (aValue != null)
  -		{
  -			logger.error("aValue was class [" + aValue.getClass().getName() + "]");
  -		}
  -		else
  -		{
  -			logger.error("aValue was null");
  -		}
  -	}
  -
  -	/**
  -	 * Get the Value from anObject
  -	 */
  -	public Object get(Object anObject) throws MetadataException
  -	{
  -		Method m = getPropertyDescriptor().getReadMethod();
  -		Object[] args = null;
  -
  -		if (m != null)
  -		{
  -			try
  -			{
  -				Object result = m.invoke(anObject, args);
  -				return result;
  -			}
  -			catch (Throwable e)
  -			{
  -				logProblem(anObject, null, e.getClass().getName());
  -				throw new MetadataException("Error invoking method:" + m.getName() + " in object:" + anObject.getClass().getName(), e);
  -			}
  -		}
  -		else
  -		{
  -			logProblem(anObject, null, "get: getReadMethod returned null");
  -			throw new MetadataException(
  -				"Can't get ReadMethod for property:" + getPropertyDescriptor().getName() + " in object:" + anObject.getClass().getName());
  -		}
  -	}
  -
  -	public Class getType()
  -	{
  -		return getPropertyDescriptor().getPropertyType();
  -	}
  -
  -	public String getName()
  -	{
  -		return getPropertyDescriptor().getName();
  -	}
  -
  -	/**
  -	 * Get the PropertyDescriptor for aClass and aPropertyName
  -	 */
  -	protected PropertyDescriptor findPropertyDescriptor(Class aClass, String aPropertyName)
  -	{
  -		BeanInfo info;
  -		PropertyDescriptor[] pd;
  -		PropertyDescriptor descriptor = null;
  -
  -		try
  -		{
  -			info = Introspector.getBeanInfo(aClass);
  -			pd = info.getPropertyDescriptors();
  -			for (int i = 0; i < pd.length; i++)
  -			{
  -				if (pd[i].getName().equals(aPropertyName))
  -				{
  -					descriptor = pd[i];
  -					break;
  -				}
  -			}
  -			if (descriptor == null)
  -			{
  -				/*
  +    private Class declaringClass;
  +    private String propertyName;
  +    private transient PropertyDescriptor propertyDescriptor;
  +
  +    /**
  +     * Make the newInstace with no constructor call happy!
  +     */
  +    public PersistentFieldPropertyImpl()
  +    {
  +    }
  +
  +    public PersistentFieldPropertyImpl(Class aClass, String aPropertyName)
  +    {
  +        setDeclaringClass(aClass);
  +        setPropertyName(aPropertyName);
  +        setPropertyDescriptor(findPropertyDescriptor(aClass, aPropertyName));
  +    }
  +
  +    /**
  +     * Sets aValue for anObject
  +     */
  +    public void set(Object anObject, Object aValue) throws MetadataException
  +    {
  +        Method m = getPropertyDescriptor().getWriteMethod();
  +        Object[] args = {aValue};
  +        if (m != null)
  +        {
  +            try
  +            {
  +                /**
  +                 * MBAIRD: it is safe to call getParameterTypes()[0] because this is
  +                 * the "set" method and it needs to take one parameter only.
  +                 * we need to be able to set values to null. We can only set something to null if
  +                 * the type is not a primitive (assignable from Object).
  +                 */
  +                if ((aValue != null) || !m.getParameterTypes()[0].isPrimitive())
  +                {
  +                    m.invoke(anObject, args);
  +                }
  +            }
  +            catch (Throwable e)
  +            {
  +                logProblem(anObject, aValue, e.getClass().getName());
  +                throw new MetadataException("Error invoking method:" + m.getName() + " in object:" + anObject.getClass().getName(), e);
  +            }
  +        }
  +        else
  +        {
  +            logProblem(anObject, aValue, "set: getWriteMethod returned null");
  +            throw new MetadataException(
  +                    "Can't get WriteMethod for property:" + getPropertyDescriptor().getName() + " in object:" + anObject.getClass().getName());
  +        }
  +    }
  +
  +    /**
  +     * Let's give the user some hints as to what could be wrong.
  +     */
  +    protected void logProblem(Object anObject, Object aValue, String msg)
  +    {
  +        Logger logger = LoggerFactory.getDefaultLogger();
  +        logger.error("Error in [PersistentFieldPropertyImpl], " + msg);
  +        logger.error("Declaring class [" + getDeclaringClass().getName() + "]");
  +        logger.error("Property Name [" + getPropertyName() + "]");
  +        logger.error("Property Type [" + getPropertyDescriptor().getPropertyType().getName() + "]");
  +
  +        if (anObject != null)
  +        {
  +            logger.error("anObject was class [" + anObject.getClass().getName() + "]");
  +        }
  +        else
  +        {
  +            logger.error("anObject was null");
  +        }
  +        if (aValue != null)
  +        {
  +            logger.error("aValue was class [" + aValue.getClass().getName() + "]");
  +        }
  +        else
  +        {
  +            logger.error("aValue was null");
  +        }
  +    }
  +
  +    /**
  +     * Get the Value from anObject
  +     */
  +    public Object get(Object anObject) throws MetadataException
  +    {
  +        Method m = getPropertyDescriptor().getReadMethod();
  +        Object[] args = null;
  +
  +        if (m != null)
  +        {
  +            try
  +            {
  +                Object result = m.invoke(anObject, args);
  +                return result;
  +            }
  +            catch (Throwable e)
  +            {
  +                logProblem(anObject, null, e.getClass().getName());
  +                throw new MetadataException("Error invoking method:" + m.getName() + " in object:" + anObject.getClass().getName(), e);
  +            }
  +        }
  +        else
  +        {
  +            logProblem(anObject, null, "get: getReadMethod returned null");
  +            throw new MetadataException(
  +                    "Can't get ReadMethod for property:" + getPropertyDescriptor().getName() + " in object:" + anObject.getClass().getName());
  +        }
  +    }
  +
  +    public Class getType()
  +    {
  +        return getPropertyDescriptor().getPropertyType();
  +    }
  +
  +    public String getName()
  +    {
  +        return getPropertyDescriptor().getName();
  +    }
  +
  +    /**
  +     * Get the PropertyDescriptor for aClass and aPropertyName
  +     */
  +    protected PropertyDescriptor findPropertyDescriptor(Class aClass, String aPropertyName)
  +    {
  +        BeanInfo info;
  +        PropertyDescriptor[] pd;
  +        PropertyDescriptor descriptor = null;
  +
  +        try
  +        {
  +            info = Introspector.getBeanInfo(aClass);
  +            pd = info.getPropertyDescriptors();
  +            for (int i = 0; i < pd.length; i++)
  +            {
  +                if (pd[i].getName().equals(aPropertyName))
  +                {
  +                    descriptor = pd[i];
  +                    break;
  +                }
  +            }
  +            if (descriptor == null)
  +            {
  +                /*
   				 * Daren Drummond: 	Throw here so we are consistent
   				 * 					with PersistentFieldDefaultImpl.
   				 */
  -				throw new MetadataException("Can't find property " + aPropertyName + " in " + aClass.getName());
  -			}
  -			return descriptor;
  -		}
  -		catch (IntrospectionException ex)
  -		{
  -			/*
  +                throw new MetadataException("Can't find property " + aPropertyName + " in " + aClass.getName());
  +            }
  +            return descriptor;
  +        }
  +        catch (IntrospectionException ex)
  +        {
  +            /*
   			 * Daren Drummond: 	Throw here so we are consistent
   			 * 					with PersistentFieldDefaultImpl.
   			 */
  -			throw new MetadataException("Can't find property " + aPropertyName + " in " + aClass.getName(), ex);
  -		}
  +            throw new MetadataException("Can't find property " + aPropertyName + " in " + aClass.getName(), ex);
  +        }
   
  -	}
  +    }
   
  -	/**
  -	 * Insert the method's description here.
  -	 * Creation date: (29.11.2001 09:49:21)
  -	 * @return java.lang.Class
  -	 */
  -	public java.lang.Class getDeclaringClass()
  -	{
  -		return declaringClass;
  -	}
  -
  -	/**
  -	 * Insert the method's description here.
  -	 * Creation date: (29.11.2001 09:19:17)
  -	 * @return java.beans.PropertyDescriptor
  -	 */
  -	protected java.beans.PropertyDescriptor getPropertyDescriptor()
  -	{
  -		if (propertyDescriptor == null)
  -		{
  -			setPropertyDescriptor(findPropertyDescriptor(getDeclaringClass(), getPropertyName()));
  -		}
  -		return propertyDescriptor;
  -	}
  -
  -	/**
  -	 * Insert the method's description here.
  -	 * Creation date: (29.11.2001 09:49:21)
  -	 * @param newDeclaringClass java.lang.Class
  -	 */
  -	public void setDeclaringClass(java.lang.Class newDeclaringClass)
  -	{
  -		declaringClass = newDeclaringClass;
  -	}
  -
  -	/**
  -	 * Insert the method's description here.
  -	 * Creation date: (29.11.2001 09:19:17)
  -	 * @param newPropertyDescriptor java.beans.PropertyDescriptor
  -	 */
  -	protected void setPropertyDescriptor(java.beans.PropertyDescriptor newPropertyDescriptor)
  -	{
  -		propertyDescriptor = newPropertyDescriptor;
  -	}
  -
  -	/**
  -	 * Gets the propertyName.
  -	 * @return Returns a String
  -	 */
  -	public String getPropertyName()
  -	{
  -		return propertyName;
  -	}
  -
  -	/**
  -	 * Sets the propertyName.
  -	 * @param propertyName The propertyName to set
  -	 */
  -	public void setPropertyName(String propertyName)
  -	{
  -		this.propertyName = propertyName;
  -	}
  -
  -	public String toString()
  -	{
  -		return getDeclaringClass().getName() + "." + getPropertyName();
  -	}
  -
  -	public boolean usesAccessorsAndMutators()
  -	{
  -		return true;
  -	}
  +    /**
  +     * Insert the method's description here.
  +     * Creation date: (29.11.2001 09:49:21)
  +     * @return java.lang.Class
  +     */
  +    public Class getDeclaringClass()
  +    {
  +        return declaringClass;
  +    }
  +
  +    /**
  +     * Insert the method's description here.
  +     * Creation date: (29.11.2001 09:19:17)
  +     * @return java.beans.PropertyDescriptor
  +     */
  +    protected PropertyDescriptor getPropertyDescriptor()
  +    {
  +        if (propertyDescriptor == null)
  +        {
  +            setPropertyDescriptor(findPropertyDescriptor(getDeclaringClass(), getPropertyName()));
  +        }
  +        return propertyDescriptor;
  +    }
  +
  +    /**
  +     * Insert the method's description here.
  +     * Creation date: (29.11.2001 09:49:21)
  +     * @param newDeclaringClass java.lang.Class
  +     */
  +    public void setDeclaringClass(java.lang.Class newDeclaringClass)
  +    {
  +        declaringClass = newDeclaringClass;
  +    }
  +
  +    /**
  +     * Insert the method's description here.
  +     * Creation date: (29.11.2001 09:19:17)
  +     * @param newPropertyDescriptor java.beans.PropertyDescriptor
  +     */
  +    protected void setPropertyDescriptor(java.beans.PropertyDescriptor newPropertyDescriptor)
  +    {
  +        propertyDescriptor = newPropertyDescriptor;
  +    }
  +
  +    /**
  +     * Gets the propertyName.
  +     * @return Returns a String
  +     */
  +    public String getPropertyName()
  +    {
  +        return propertyName;
  +    }
  +
  +    /**
  +     * Sets the propertyName.
  +     * @param propertyName The propertyName to set
  +     */
  +    public void setPropertyName(String propertyName)
  +    {
  +        this.propertyName = propertyName;
  +    }
  +
  +    public String toString()
  +    {
  +        return getDeclaringClass().getName() + "." + getPropertyName();
  +    }
  +
  +    public boolean usesAccessorsAndMutators()
  +    {
  +        return true;
  +    }
   }
  
  
  
  1.3       +23 -13    db-ojb/src/java/org/apache/ojb/broker/metadata/fieldaccess/PersistentFieldPrivilegedImpl.java
  
  Index: PersistentFieldPrivilegedImpl.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/metadata/fieldaccess/PersistentFieldPrivilegedImpl.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- PersistentFieldPrivilegedImpl.java	8 Jul 2003 06:05:36 -0000	1.2
  +++ PersistentFieldPrivilegedImpl.java	8 Jul 2003 14:30:07 -0000	1.3
  @@ -62,15 +62,25 @@
   import java.security.PrivilegedAction;
   
   /**
  - * This class is a wrapper around java.lang.reflect.Field objects.
  + * A {@link PersistentField} implementation using
  + * reflection to access but does cooperate with
  + * AccessController and do not suppress the java
  + * language access check.
  + *
  + * @see PersistentFieldDirectAccessImpl
  + *
    * @author <a href="mailto:thma@apache.org">Thomas Mahler<a>
  + * @author <a href="mailto:armin@codeAuLait.de">Armin Waibel</a>
    * @version $Id$
    */
   public class PersistentFieldPrivilegedImpl extends PersistentFieldDirectAccessImpl
   {
       private SetAccessibleAction setAccessibleAction = new SetAccessibleAction();
  +    private static final int ACCESSIBLE_STATE_UNKOWN = 0;
  +    private static final int ACCESSIBLE_STATE_FALSE = 1;
  +    private static final int ACCESSIBLE_STATE_SET_TRUE = 2;
   
  -    public PersistentFieldPrivilegedImpl()
  +    protected PersistentFieldPrivilegedImpl()
       {
       }
   
  @@ -84,12 +94,12 @@
        */
       public synchronized void doSet(Object obj, Object value) throws MetadataException
       {
  -        int accessibleState = 0;
  +        int accessibleState = ACCESSIBLE_STATE_UNKOWN;
           Field field = getField();
  -        if(!field.isAccessible()) accessibleState = 1;
  -        if(accessibleState == 1)
  +        if (!field.isAccessible()) accessibleState = ACCESSIBLE_STATE_FALSE;
  +        if (accessibleState == ACCESSIBLE_STATE_FALSE)
           {
  -            accessibleState = 2;
  +            accessibleState = ACCESSIBLE_STATE_SET_TRUE;
               AccessController.doPrivileged(setAccessibleAction);
           }
           try
  @@ -98,7 +108,7 @@
           }
           finally
           {
  -            if(accessibleState == 2) field.setAccessible(false);
  +            if (accessibleState == ACCESSIBLE_STATE_SET_TRUE) field.setAccessible(false);
           }
       }
   
  @@ -107,13 +117,13 @@
        */
       public synchronized Object doGet(Object obj) throws MetadataException
       {
  -        int accessibleState = 0;
  +        int accessibleState = ACCESSIBLE_STATE_UNKOWN;
           Field field = getField();
           Object result = null;
  -        if(!field.isAccessible()) accessibleState = 1;
  -        if(accessibleState == 1)
  +        if (!field.isAccessible()) accessibleState = ACCESSIBLE_STATE_FALSE;
  +        if (accessibleState == ACCESSIBLE_STATE_FALSE)
           {
  -            accessibleState = 2;
  +            accessibleState = ACCESSIBLE_STATE_SET_TRUE;
               AccessController.doPrivileged(setAccessibleAction);
           }
           try
  @@ -122,7 +132,7 @@
           }
           finally
           {
  -            if(accessibleState == 2) field.setAccessible(false);
  +            if (accessibleState == ACCESSIBLE_STATE_SET_TRUE) field.setAccessible(false);
           }
           return result;
       }
  
  
  
  1.16      +3 -1      db-ojb/src/java/org/apache/ojb/broker/metadata/fieldaccess/PersistentFieldMaxPerformanceImpl.java
  
  Index: PersistentFieldMaxPerformanceImpl.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/metadata/fieldaccess/PersistentFieldMaxPerformanceImpl.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- PersistentFieldMaxPerformanceImpl.java	3 Jul 2003 09:55:07 -0000	1.15
  +++ PersistentFieldMaxPerformanceImpl.java	8 Jul 2003 14:30:07 -0000	1.16
  @@ -64,6 +64,8 @@
   
   /**
    * This class is a wrapper around java.lang.reflect.Field objects.
  + *
  + * @deprecated use {@link PersistentFieldDirectAccessImpl} instead
    * @author <a href="mailto:thma@apache.org">Thomas Mahler<a>
    * @version $Id$
    */
  
  
  
  1.7       +6 -6      db-ojb/src/java/org/apache/ojb/broker/metadata/fieldaccess/PersistentFieldFactory.java
  
  Index: PersistentFieldFactory.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/metadata/fieldaccess/PersistentFieldFactory.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- PersistentFieldFactory.java	3 Jul 2003 09:55:07 -0000	1.6
  +++ PersistentFieldFactory.java	8 Jul 2003 14:30:07 -0000	1.7
  @@ -70,7 +70,8 @@
   public class PersistentFieldFactory
   {
       private static Logger log = LoggerFactory.getLogger(PersistentFieldFactory.class);
  -    public static final Class DEFAULT_PERSISTENT_FIELD_IMPL = PersistentFieldDefaultImpl.class;
  +    private static final Class DEFAULT_PERSISTENT_FIELD_IMPL = PersistentFieldDirectAccessImpl.class;
  +    private static final Class[] METOD_PARAMETER_TYPES = {Class.class, String.class};
   
       private static Class persistentFieldClass = null;
       private static boolean usesAccessorsAndMutators = false;
  @@ -90,13 +91,13 @@
                       persistentFieldClass = getPersistentFieldClass();
                   }
               }
  -            Class[] types = {Class.class, String.class};
               Object[] args = {attributeType, attributeName};
  -            return (PersistentField) ClassHelper.newInstance(persistentFieldClass, types, args);
  +            return (PersistentField) ClassHelper.newInstance(persistentFieldClass, METOD_PARAMETER_TYPES, args);
           }
           catch (Exception ex)
           {
  -            throw new MetadataException("Error creating PersistentField: " + attributeType.getName() + ", " + attributeName, ex);
  +            throw new MetadataException("Error creating PersistentField: " +
  +                    attributeType.getName() + ", " + attributeName, ex);
           }
       }
   
  @@ -118,7 +119,6 @@
               catch (Exception e)
               {
                   log.error("Cannot verify 'usesAccessorsAndMutators' attribute for class " + clazz, e);
  -                // System.out.println("InstantiationException in usesAccessorsAndMutators " + e.getMessage());
               }
               finally
               {
  
  
  
  1.5       +158 -158  db-ojb/src/java/org/apache/ojb/broker/metadata/fieldaccess/PersistentFieldDynaBeanImpl.java
  
  Index: PersistentFieldDynaBeanImpl.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/metadata/fieldaccess/PersistentFieldDynaBeanImpl.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- PersistentFieldDynaBeanImpl.java	3 Jul 2003 09:55:07 -0000	1.4
  +++ PersistentFieldDynaBeanImpl.java	8 Jul 2003 14:30:07 -0000	1.5
  @@ -55,10 +55,9 @@
    */
   
   import org.apache.commons.beanutils.DynaBean;
  -
  -import org.apache.ojb.broker.util.logging.*;
  -import org.apache.ojb.broker.util.logging.LoggerFactory;
   import org.apache.ojb.broker.PersistenceBrokerException;
  +import org.apache.ojb.broker.util.logging.Logger;
  +import org.apache.ojb.broker.util.logging.LoggerFactory;
   
   /**
    * This class accesses a property from a {@link DynaBean}.
  @@ -66,169 +65,170 @@
    * at run time the type of the field could actually be different, since
    * it depends on the DynaClass of the DynaBean that is given at runtime.
    *
  + * @deprecated use {@link PersistentFieldDynaBeanAccessImpl} instead
    * @author James Strachan
    * @version $Id$
    */
   public class PersistentFieldDynaBeanImpl implements PersistentField
   {
   
  -	private String propertyName;
  -	private Class propertyType;
  +    private String propertyName;
  +    private Class propertyType;
   
       public PersistentFieldDynaBeanImpl()
       {
       }
   
  -	public PersistentFieldDynaBeanImpl(Class aPropertyType, String aPropertyName)
  -	{
  -		this.propertyType = aPropertyType;
  -		this.propertyName = aPropertyName;
  -	}
  -
  -	/**
  -	 * Sets aValue for anObject
  -	 */
  -	public void set(Object anObject, Object aValue) throws PersistenceBrokerException
  -	{
  -		if (anObject instanceof DynaBean)
  -		{
  -			DynaBean dynaBean = (DynaBean) anObject;
  -			try
  -			{
  -				dynaBean.set(propertyName, aValue);
  -			}
  -			catch (Throwable t)
  -			{
  -				String msg = dynaBean.getClass().getName();
  -				logSetProblem(anObject, aValue, msg);
  -				throw new PersistenceBrokerException(t);
  -			}
  -		}
  -		else
  -		{
  -			String msg = "the object is not a DynaBean";
  -			logSetProblem(anObject, aValue, msg);
  -			throw new PersistenceBrokerException(msg);
  -		}
  -	}
  -
  -	/**
  -	 * Get the Value from anObject
  -	 */
  -	public Object get(Object anObject) throws PersistenceBrokerException
  -	{
  -		if (anObject instanceof DynaBean)
  -		{
  -			DynaBean dynaBean = (DynaBean) anObject;
  -			try
  -			{
  -				return dynaBean.get(propertyName);
  -			}
  -			catch (Throwable t)
  -			{
  -				String msg = dynaBean.getClass().getName();
  -				logGetProblem(anObject, msg);
  -				throw new PersistenceBrokerException(t);
  -			}
  -		}
  -		else
  -		{
  -			String msg = "the object is not a DynaBean";
  -			logGetProblem(anObject, msg);
  -			throw new PersistenceBrokerException(msg);
  -		}
  -	}
  -
  -	public Class getType()
  -	{
  -		return propertyType;
  -	}
  -
  -	public String getName()
  -	{
  -		return propertyName;
  -	}
  -
  -	public Class getDeclaringClass()
  -	{
  -		return DynaBean.class;
  -	}
  -
  -	/**
  -	 * Gets the propertyName.
  -	 * @return Returns a String
  -	 */
  -	public String getPropertyName()
  -	{
  -		return propertyName;
  -	}
  -
  -	/**
  -	 * Sets the propertyName.
  -	 * @param propertyName The propertyName to set
  -	 */
  -	public void setPropertyName(String propertyName)
  -	{
  -		this.propertyName = propertyName;
  -	}
  -
  -	public String toString()
  -	{
  -		return "DynaBean." + getPropertyName();
  -	}
  -
  -	/**
  -	 * Let's give the user some hints as to what could be wrong.
  -	 */
  -	protected void logSetProblem(Object anObject, Object aValue, String msg)
  -	{
  -		Logger logger = LoggerFactory.getDefaultLogger();
  -		logger.error("Error in operation [set] of object [PersistentFieldDynaBeanImpl], " + msg);
  -		logger.error("Property Name [" + getPropertyName() + "]");
  -		if (anObject instanceof DynaBean)
  -		{
  -			DynaBean dynaBean = (DynaBean) anObject;
  -			logger.error("anObject was DynaClass [" + dynaBean.getDynaClass().getName() + "]");
  -		}
  -		else if (anObject != null)
  -		{
  -			logger.error("anObject was class [" + anObject.getClass().getName() + "]");
  -		}
  -		else
  -		{
  -			logger.error("anObject was null");
  -		}
  -		if (aValue != null)
  -			logger.error("aValue was class [" + aValue.getClass().getName() + "]");
  -		else
  -			logger.error("aValue was null");
  -	}
  -
  -	/**
  -	 * Let's give the user some hints as to what could be wrong.
  -	 */
  -	protected void logGetProblem(Object anObject, String msg)
  -	{
  -		Logger logger = LoggerFactory.getDefaultLogger();
  -		logger.error("Error in operation [get of object [PersistentFieldDynaBeanImpl], " + msg);
  -		logger.error("Property Name [" + getPropertyName() + "]");
  -		if (anObject instanceof DynaBean)
  -		{
  -			DynaBean dynaBean = (DynaBean) anObject;
  -			logger.error("anObject was DynaClass [" + dynaBean.getDynaClass().getName() + "]");
  -		}
  -		else if (anObject != null)
  -		{
  -			logger.error("anObject was class [" + anObject.getClass().getName() + "]");
  -		}
  -		else
  -		{
  -			logger.error("anObject was null");
  -		}
  -	}
  -
  -	public boolean usesAccessorsAndMutators()
  -	{
  -		return false;
  -	}
  +    public PersistentFieldDynaBeanImpl(Class aPropertyType, String aPropertyName)
  +    {
  +        this.propertyType = aPropertyType;
  +        this.propertyName = aPropertyName;
  +    }
  +
  +    /**
  +     * Sets aValue for anObject
  +     */
  +    public void set(Object anObject, Object aValue) throws PersistenceBrokerException
  +    {
  +        if (anObject instanceof DynaBean)
  +        {
  +            DynaBean dynaBean = (DynaBean) anObject;
  +            try
  +            {
  +                dynaBean.set(propertyName, aValue);
  +            }
  +            catch (Throwable t)
  +            {
  +                String msg = dynaBean.getClass().getName();
  +                logSetProblem(anObject, aValue, msg);
  +                throw new PersistenceBrokerException(t);
  +            }
  +        }
  +        else
  +        {
  +            String msg = "the object is not a DynaBean";
  +            logSetProblem(anObject, aValue, msg);
  +            throw new PersistenceBrokerException(msg);
  +        }
  +    }
  +
  +    /**
  +     * Get the Value from anObject
  +     */
  +    public Object get(Object anObject) throws PersistenceBrokerException
  +    {
  +        if (anObject instanceof DynaBean)
  +        {
  +            DynaBean dynaBean = (DynaBean) anObject;
  +            try
  +            {
  +                return dynaBean.get(propertyName);
  +            }
  +            catch (Throwable t)
  +            {
  +                String msg = dynaBean.getClass().getName();
  +                logGetProblem(anObject, msg);
  +                throw new PersistenceBrokerException(t);
  +            }
  +        }
  +        else
  +        {
  +            String msg = "the object is not a DynaBean";
  +            logGetProblem(anObject, msg);
  +            throw new PersistenceBrokerException(msg);
  +        }
  +    }
  +
  +    public Class getType()
  +    {
  +        return propertyType;
  +    }
  +
  +    public String getName()
  +    {
  +        return propertyName;
  +    }
  +
  +    public Class getDeclaringClass()
  +    {
  +        return DynaBean.class;
  +    }
  +
  +    /**
  +     * Gets the propertyName.
  +     * @return Returns a String
  +     */
  +    public String getPropertyName()
  +    {
  +        return propertyName;
  +    }
  +
  +    /**
  +     * Sets the propertyName.
  +     * @param propertyName The propertyName to set
  +     */
  +    public void setPropertyName(String propertyName)
  +    {
  +        this.propertyName = propertyName;
  +    }
  +
  +    public String toString()
  +    {
  +        return "DynaBean." + getPropertyName();
  +    }
  +
  +    /**
  +     * Let's give the user some hints as to what could be wrong.
  +     */
  +    protected void logSetProblem(Object anObject, Object aValue, String msg)
  +    {
  +        Logger logger = LoggerFactory.getDefaultLogger();
  +        logger.error("Error in operation [set] of object [PersistentFieldDynaBeanImpl], " + msg);
  +        logger.error("Property Name [" + getPropertyName() + "]");
  +        if (anObject instanceof DynaBean)
  +        {
  +            DynaBean dynaBean = (DynaBean) anObject;
  +            logger.error("anObject was DynaClass [" + dynaBean.getDynaClass().getName() + "]");
  +        }
  +        else if (anObject != null)
  +        {
  +            logger.error("anObject was class [" + anObject.getClass().getName() + "]");
  +        }
  +        else
  +        {
  +            logger.error("anObject was null");
  +        }
  +        if (aValue != null)
  +            logger.error("aValue was class [" + aValue.getClass().getName() + "]");
  +        else
  +            logger.error("aValue was null");
  +    }
  +
  +    /**
  +     * Let's give the user some hints as to what could be wrong.
  +     */
  +    protected void logGetProblem(Object anObject, String msg)
  +    {
  +        Logger logger = LoggerFactory.getDefaultLogger();
  +        logger.error("Error in operation [get of object [PersistentFieldDynaBeanImpl], " + msg);
  +        logger.error("Property Name [" + getPropertyName() + "]");
  +        if (anObject instanceof DynaBean)
  +        {
  +            DynaBean dynaBean = (DynaBean) anObject;
  +            logger.error("anObject was DynaClass [" + dynaBean.getDynaClass().getName() + "]");
  +        }
  +        else if (anObject != null)
  +        {
  +            logger.error("anObject was class [" + anObject.getClass().getName() + "]");
  +        }
  +        else
  +        {
  +            logger.error("anObject was null");
  +        }
  +    }
  +
  +    public boolean usesAccessorsAndMutators()
  +    {
  +        return false;
  +    }
   }
  
  
  
  1.3       +10 -3     db-ojb/src/java/org/apache/ojb/broker/metadata/fieldaccess/PersistentFieldDirectAccessImpl.java
  
  Index: PersistentFieldDirectAccessImpl.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/metadata/fieldaccess/PersistentFieldDirectAccessImpl.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- PersistentFieldDirectAccessImpl.java	8 Jul 2003 06:05:36 -0000	1.2
  +++ PersistentFieldDirectAccessImpl.java	8 Jul 2003 14:30:07 -0000	1.3
  @@ -61,13 +61,20 @@
   import java.lang.reflect.Field;
   
   /**
  - * This class is a wrapper around java.lang.reflect.Field objects.
  + * A {@link PersistentField} implementation
  + * is a high-speed version of the access strategies.
  + * It does not cooperate with an AccessController,
  + * but accesses the fields directly. This implementation persistent
  + * attributes don't need getters and setters
  + * and don't have to be declared public or protected
  + *
    * @author <a href="mailto:thma@apache.org">Thomas Mahler<a>
  + * @author <a href="mailto:armin@codeAuLait.de">Armin Waibel</a>
    * @version $Id$
    */
   public class PersistentFieldDirectAccessImpl extends AbstractPersistentField
   {
  -    public PersistentFieldDirectAccessImpl()
  +    protected PersistentFieldDirectAccessImpl()
       {
       }
   
  
  
  
  1.17      +3 -1      db-ojb/src/java/org/apache/ojb/broker/metadata/fieldaccess/PersistentFieldDefaultImpl.java
  
  Index: PersistentFieldDefaultImpl.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/metadata/fieldaccess/PersistentFieldDefaultImpl.java,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- PersistentFieldDefaultImpl.java	23 Apr 2003 20:05:26 -0000	1.16
  +++ PersistentFieldDefaultImpl.java	8 Jul 2003 14:30:07 -0000	1.17
  @@ -67,6 +67,8 @@
   
   /**
    * This class is a wrapper around java.lang.reflect.Field objects.
  + *
  + * @deprecated use {@link PersistentFieldPrivilegedImpl} instead
    * @author <a href="mailto:thma@apache.org">Thomas Mahler<a>
    * @version $Id$
    */
  
  
  
  1.2       +74 -11    db-ojb/src/java/org/apache/ojb/broker/metadata/fieldaccess/AbstractPersistentField.java
  
  Index: AbstractPersistentField.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/metadata/fieldaccess/AbstractPersistentField.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- AbstractPersistentField.java	8 Jul 2003 01:04:39 -0000	1.1
  +++ AbstractPersistentField.java	8 Jul 2003 14:30:07 -0000	1.2
  @@ -1,5 +1,59 @@
   package org.apache.ojb.broker.metadata.fieldaccess;
   
  +/* ====================================================================
  + * 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/>.
  + */
  +
   import org.apache.commons.lang.builder.ToStringBuilder;
   import org.apache.commons.lang.builder.ToStringStyle;
   import org.apache.ojb.broker.metadata.MetadataException;
  @@ -10,7 +64,7 @@
   import java.lang.reflect.Field;
   
   /**
  - * Abstract {@link PersistentField} implementation.
  + * Abstract {@link PersistentField} base implementation.
    *
    * @author <a href="mailto:armin@codeAuLait.de">Armin Waibel</a>
    * @version $Id$
  @@ -20,6 +74,7 @@
       public static final String PATH_TOKEN = "::";
       public static final Class PERSISTENT_FIELD_IMPL_FOR_NESTED = PersistentFieldDirectAccessImpl.class;
   
  +    private static final int UNKNOWN_FIELD = 0;
       private static final int NORMAL_FIELD = 1;
       private static final int NESTED_FIELD = 2;
       private static final Class[] METHOD_TYPES = {Class.class, String.class};
  @@ -32,7 +87,7 @@
        * 1 - normal field
        * 2 - nested field
        */
  -    private int isNestedField;
  +    private int isNestedField = UNKNOWN_FIELD;
   
       /**
        * For internal use only!!
  @@ -159,7 +214,7 @@
   
       protected boolean isNestedField()
       {
  -        if (isNestedField == 0) // not initialized
  +        if (isNestedField == UNKNOWN_FIELD) // not initialized
           {
               if (fieldName == null)
               {
  @@ -220,7 +275,7 @@
           if (index >= 0)
           {
               String name = fieldName.substring(0, index);
  -            AbstractPersistentField pField = createInternPersistentField(ProxyHelper.getRealClass(obj), name);
  +            PersistentField pField = createInternPersistentField(ProxyHelper.getRealClass(obj), name);
               Object attrib = pField.get(ProxyHelper.getRealObject(obj));
   
               if (attrib == null)
  @@ -242,24 +297,32 @@
                   Class type = pField.getType();
                   if ((value != null) || !type.isPrimitive())
                   {
  -                    pField.doSet(ProxyHelper.getRealObject(obj), attrib);
  +                    /*
  +                    TODO: here we need cast to AbstractPersistentField to execute the doSet-method.
  +                    Find better solution without cast?
  +                    */
  +                    if(pField instanceof AbstractPersistentField)
  +                    {
  +                        ((AbstractPersistentField) pField).doSet(ProxyHelper.getRealObject(obj), attrib);
  +                    }
  +                    else
  +                    {
  +                        pField.set(ProxyHelper.getRealObject(obj), attrib);
  +                    }
                   }
               }
  -            //
               String nestedName = fieldName.substring(index + PATH_TOKEN.length());
  -
               setNestedObject(attrib, nestedName, value);
           }
           else
           {
  -
               PersistentField pField = createInternPersistentField(ProxyHelper.getRealClass(obj), fieldName);
               pField.set(ProxyHelper.getRealObject(obj), value);
           }
   
       }
   
  -    private AbstractPersistentField createInternPersistentField(Class fieldType, String fieldName)
  +    private PersistentField createInternPersistentField(Class fieldType, String fieldName)
       {
   //        try
   //        {
  @@ -274,7 +337,7 @@
   
           try
           {
  -            return (AbstractPersistentField) PersistentFieldFactory.createPersistentField(fieldType, fieldName);
  +            return PersistentFieldFactory.createPersistentField(fieldType, fieldName);
           }
           catch (Exception e)
           {
  
  
  
  1.1                  db-ojb/src/java/org/apache/ojb/broker/metadata/fieldaccess/PersistentFieldIntrospectorImpl.java
  
  Index: PersistentFieldIntrospectorImpl.java
  ===================================================================
  package org.apache.ojb.broker.metadata.fieldaccess;
  
  /* ====================================================================
   * 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/>.
   */
  
  import org.apache.ojb.broker.metadata.MetadataException;
  import org.apache.ojb.broker.util.logging.Logger;
  import org.apache.ojb.broker.util.logging.LoggerFactory;
  
  import java.beans.BeanInfo;
  import java.beans.IntrospectionException;
  import java.beans.Introspector;
  import java.beans.PropertyDescriptor;
  import java.lang.reflect.Method;
  
  /**
   * A {@link PersistentField} implementation using
   * JavaBeans compliant calls only to access persistent attributes.
   * No Reflection is needed. But for each attribute xxx there must be
   * public getXxx() and setXxx() methods.
   *
   * @author <a href="mailto:jbraeuchi@hotmail.com">Jakob Braeuchi</a>
   * @author <a href="mailto:armin@codeAuLait.de">Armin Waibel</a>
   * @version $Id: PersistentFieldIntrospectorImpl.java,v 1.1 2003/07/08 14:30:07 arminw Exp $
   */
  public class PersistentFieldIntrospectorImpl extends AbstractPersistentField
  {
      private transient PropertyDescriptor propertyDescriptor;
  
      protected PersistentFieldIntrospectorImpl()
      {
          super();
      }
  
      public PersistentFieldIntrospectorImpl(Class aClass, String aPropertyName)
      {
          super(aClass, aPropertyName);
      }
  
      /**
       * Sets aValue for anObject
       */
      public void doSet(Object anObject, Object aValue) throws MetadataException
      {
          Method m = getPropertyDescriptor().getWriteMethod();
          Object[] args = {aValue};
          if (m != null)
          {
              try
              {
                  /**
                   * MBAIRD: it is safe to call getParameterTypes()[0] because this is
                   * the "set" method and it needs to take one parameter only.
                   * we need to be able to set values to null. We can only set something to null if
                   * the type is not a primitive (assignable from Object).
                   */
                  if ((aValue != null) || !m.getParameterTypes()[0].isPrimitive())
                  {
                      m.invoke(anObject, args);
                  }
              }
              catch (Throwable e)
              {
                  logProblem(anObject, aValue, e.getClass().getName());
                  throw new MetadataException("Error invoking method:" + m.getName() + " in object:" + anObject.getClass().getName(), e);
              }
          }
          else
          {
              logProblem(anObject, aValue, "set: getWriteMethod returned null");
              throw new MetadataException(
                      "Can't get WriteMethod for property:" + getPropertyDescriptor().getName() + " in object:" + anObject.getClass().getName());
          }
      }
  
      /**
       * Get the Value from anObject
       */
      public Object doGet(Object anObject) throws MetadataException
      {
          Method m = getPropertyDescriptor().getReadMethod();
          Object[] args = null;
  
          if (m != null)
          {
              try
              {
                  Object result = m.invoke(anObject, args);
                  return result;
              }
              catch (Throwable e)
              {
                  logProblem(anObject, null, e.getClass().getName());
                  throw new MetadataException("Error invoking method:" + m.getName() + " in object:" + anObject.getClass().getName(), e);
              }
          }
          else
          {
              logProblem(anObject, null, "get: getReadMethod returned null");
              throw new MetadataException(
                      "Can't get ReadMethod for property:" + getPropertyDescriptor().getName() + " in object:" + anObject.getClass().getName());
          }
      }
  
      /**
       * Get the PropertyDescriptor for aClass and aPropertyName
       */
      protected PropertyDescriptor findPropertyDescriptor(Class aClass, String aPropertyName)
      {
          BeanInfo info;
          PropertyDescriptor[] pd;
          PropertyDescriptor descriptor = null;
  
          try
          {
              info = Introspector.getBeanInfo(aClass);
              pd = info.getPropertyDescriptors();
              for (int i = 0; i < pd.length; i++)
              {
                  if (pd[i].getName().equals(aPropertyName))
                  {
                      descriptor = pd[i];
                      break;
                  }
              }
              if (descriptor == null)
              {
                  /*
  				 * Daren Drummond: 	Throw here so we are consistent
  				 * 					with PersistentFieldDefaultImpl.
  				 */
                  throw new MetadataException("Can't find property " + aPropertyName + " in " + aClass.getName());
              }
              return descriptor;
          }
          catch (IntrospectionException ex)
          {
              /*
  			 * Daren Drummond: 	Throw here so we are consistent
  			 * 					with PersistentFieldDefaultImpl.
  			 */
              throw new MetadataException("Can't find property " + aPropertyName + " in " + aClass.getName(), ex);
          }
  
      }
  
      /**
       * Returns the PropertyDescriptor.
       * @return java.beans.PropertyDescriptor
       */
      protected PropertyDescriptor getPropertyDescriptor()
      {
          if (propertyDescriptor == null)
          {
              setPropertyDescriptor(findPropertyDescriptor(getDeclaringClass(), getName()));
          }
          return propertyDescriptor;
      }
  
      /**
       * Set PropertyDescriptor.
       * @param newPropertyDescriptor java.beans.PropertyDescriptor
       */
      protected void setPropertyDescriptor(PropertyDescriptor newPropertyDescriptor)
      {
          propertyDescriptor = newPropertyDescriptor;
      }
  
      /**
       * This implementation returns always 'false'.
       * @see AbstractPersistentField#makeAccessible()
       */
      public boolean makeAccessible()
      {
          return false;
      }
  
      /**
       * Always returns 'false'.
       * @see PersistentField#usesAccessorsAndMutators
       */
      public boolean usesAccessorsAndMutators()
      {
          return true;
      }
  
      /**
       * Let's give the user some hints as to what could be wrong.
       */
      protected void logProblem(Object anObject, Object aValue, String msg)
      {
          Logger logger = LoggerFactory.getDefaultLogger();
          logger.error("Error in [PersistentFieldPropertyImpl], " + msg);
          logger.error("Declaring class [" + getDeclaringClass().getName() + "]");
          logger.error("Property Name [" + getName() + "]");
          logger.error("Property Type [" + getPropertyDescriptor().getPropertyType().getName() + "]");
  
          if (anObject != null)
          {
              logger.error("anObject was class [" + anObject.getClass().getName() + "]");
          }
          else
          {
              logger.error("anObject was null");
          }
          if (aValue != null)
          {
              logger.error("aValue was class [" + aValue.getClass().getName() + "]");
          }
          else
          {
              logger.error("aValue was null");
          }
      }
  }
  
  
  
  1.1                  db-ojb/src/java/org/apache/ojb/broker/metadata/fieldaccess/PersistentFieldDynaBeanAccessImpl.java
  
  Index: PersistentFieldDynaBeanAccessImpl.java
  ===================================================================
  package org.apache.ojb.broker.metadata.fieldaccess;
  
  /* ====================================================================
   * 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/>.
   */
  
  import org.apache.commons.beanutils.DynaBean;
  import org.apache.ojb.broker.PersistenceBrokerException;
  import org.apache.ojb.broker.util.logging.Logger;
  import org.apache.ojb.broker.util.logging.LoggerFactory;
  
  /**
   * A {@link PersistentField} implementation accesses a property
   * from a {@link org.apache.commons.beanutils.DynaBean}.
   * Note that because of the way that PersistentField works,
   * at run time the type of the field could actually be different, since
   * it depends on the DynaClass of the DynaBean that is given at runtime.
   *
   * @author James Strachan
   * @version $Id: PersistentFieldDynaBeanAccessImpl.java,v 1.1 2003/07/08 14:30:07 arminw Exp $
   */
  public class PersistentFieldDynaBeanAccessImpl extends AbstractPersistentField
  {
      public PersistentFieldDynaBeanAccessImpl()
      {
          super();
      }
  
      public PersistentFieldDynaBeanAccessImpl(Class aPropertyType, String aPropertyName)
      {
          super(aPropertyType, aPropertyName);
      }
  
      /**
       * Sets aValue for anObject
       */
      public void doSet(Object anObject, Object aValue) throws PersistenceBrokerException
      {
          if (anObject instanceof DynaBean)
          {
              DynaBean dynaBean = (DynaBean) anObject;
              try
              {
                  dynaBean.set(getName(), aValue);
              }
              catch (Throwable t)
              {
                  String msg = dynaBean.getClass().getName();
                  logSetProblem(anObject, aValue, msg);
                  throw new PersistenceBrokerException(t);
              }
          }
          else
          {
              String msg = "the object is not a DynaBean";
              logSetProblem(anObject, aValue, msg);
              throw new PersistenceBrokerException(msg);
          }
      }
  
      /**
       * Get the Value from anObject
       */
      public Object doGet(Object anObject) throws PersistenceBrokerException
      {
          if (anObject instanceof DynaBean)
          {
              DynaBean dynaBean = (DynaBean) anObject;
              try
              {
                  return dynaBean.get(getName());
              }
              catch (Throwable t)
              {
                  String msg = dynaBean.getClass().getName();
                  logGetProblem(anObject, msg);
                  throw new PersistenceBrokerException(t);
              }
          }
          else
          {
              String msg = "the object is not a DynaBean";
              logGetProblem(anObject, msg);
              throw new PersistenceBrokerException(msg);
          }
      }
  
      public boolean makeAccessible()
      {
          return false;
      }
  
      public boolean usesAccessorsAndMutators()
      {
          return false;
      }
  
      public String toString()
      {
          return "DynaBean." + getName() + ": " + super.toString();
      }
  
      /**
       * Let's give the user some hints as to what could be wrong.
       */
      protected void logSetProblem(Object anObject, Object aValue, String msg)
      {
          Logger logger = LoggerFactory.getDefaultLogger();
          logger.error("Error in operation [set] of object [" + this.getClass().getName() + "], " + msg);
          logger.error("Property Name [" + getName() + "]");
          if (anObject instanceof DynaBean)
          {
              DynaBean dynaBean = (DynaBean) anObject;
              logger.error("anObject was DynaClass [" + dynaBean.getDynaClass().getName() + "]");
          }
          else if (anObject != null)
          {
              logger.error("anObject was class [" + anObject.getClass().getName() + "]");
          }
          else
          {
              logger.error("anObject was null");
          }
          if (aValue != null)
              logger.error("aValue was class [" + aValue.getClass().getName() + "]");
          else
              logger.error("aValue was null");
      }
  
      /**
       * Let's give the user some hints as to what could be wrong.
       */
      protected void logGetProblem(Object anObject, String msg)
      {
          Logger logger = LoggerFactory.getDefaultLogger();
          logger.error("Error in operation [get of object [" + this.getClass().getName() + "], " + msg);
          logger.error("Property Name [" + getName() + "]");
          if (anObject instanceof DynaBean)
          {
              DynaBean dynaBean = (DynaBean) anObject;
              logger.error("anObject was DynaClass [" + dynaBean.getDynaClass().getName() + "]");
          }
          else if (anObject != null)
          {
              logger.error("anObject was class [" + anObject.getClass().getName() + "]");
          }
          else
          {
              logger.error("anObject was null");
          }
      }
  }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org


Mime
View raw message