db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From to...@apache.org
Subject cvs commit: db-ojb/src/java/org/apache/ojb/broker/metadata CreationDescriptor.java EnclosingClassReferenceDescriptor.java
Date Sat, 01 Oct 2005 09:20:27 GMT
tomdz       2005/10/01 02:20:27

  Modified:    src/java/org/apache/ojb/broker/core
                        PersistenceBrokerImpl.java
               src/java/org/apache/ojb/broker/util ClassHelper.java
               src/java/org/apache/ojb/broker/metadata
                        CreationDescriptor.java
                        EnclosingClassReferenceDescriptor.java
  Log:
  Replaced usages of Class#getEnclosingClass with Class#getDeclaringClass as the former is
Java 5-only
  
  Revision  Changes    Path
  1.122     +29 -24    db-ojb/src/java/org/apache/ojb/broker/core/PersistenceBrokerImpl.java
  
  Index: PersistenceBrokerImpl.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/core/PersistenceBrokerImpl.java,v
  retrieving revision 1.121
  retrieving revision 1.122
  diff -u -r1.121 -r1.122
  --- PersistenceBrokerImpl.java	30 Sep 2005 21:45:14 -0000	1.121
  +++ PersistenceBrokerImpl.java	1 Oct 2005 09:20:26 -0000	1.122
  @@ -1468,39 +1468,44 @@
        */
       private Object createDirectEnclosingObject(Class targetClass, Class directPersistentOuterClass,
Object directPersistentOuterObject)
       {
  -        Class directEnclosingClass = targetClass.getEnclosingClass();
  +        Class directEnclosingClass = ClassHelper.getEnclosingClass(targetClass);
   
           if ((directPersistentOuterClass != null) && directPersistentOuterClass.equals(directEnclosingClass))
           {
               return directPersistentOuterObject;
           }
  -        else if (directEnclosingClass.getEnclosingClass() != null)
  -        {
  -            // recursively create the direct enclosing object of the direct enclosing class
  -            Object oneLevelAboveOuterObj = createDirectEnclosingObject(directEnclosingClass,
directPersistentOuterClass, directPersistentOuterObject);
  -
  -            try
  -            {
  -                return  ClassHelper.newInstance(directEnclosingClass,
  -                                                new Class[] { directEnclosingClass.getEnclosingClass()
},
  -                                                new Object[] { oneLevelAboveOuterObj },
  -                                                true);
  -            }
  -            catch (Exception ex)
  -            {
  -                throw new MetadataException("Cannot create instance of class "+directEnclosingClass.getName()+"
because there is no no-arg constructor", ex);
  -            }
  -        }
           else
           {
  -            // the direct enclosing class is no inner class itself -> create with no-arg
constructor
  -            try
  +            Class outerEnclosingClass = ClassHelper.getEnclosingClass(directEnclosingClass);
  +
  +            if (outerEnclosingClass != null)
               {
  -                return  ClassHelper.newInstance(directEnclosingClass, true);
  +                // recursively create the direct enclosing object of the direct enclosing
class
  +                Object oneLevelAboveOuterObj = createDirectEnclosingObject(directEnclosingClass,
directPersistentOuterClass, directPersistentOuterObject);
  +    
  +                try
  +                {
  +                    return  ClassHelper.newInstance(directEnclosingClass,
  +                                                    new Class[] { outerEnclosingClass },
  +                                                    new Object[] { oneLevelAboveOuterObj
},
  +                                                    true);
  +                }
  +                catch (Exception ex)
  +                {
  +                    throw new MetadataException("Cannot create instance of class "+directEnclosingClass.getName()+"
because there is no no-arg constructor", ex);
  +                }
               }
  -            catch (Exception ex)
  +            else
               {
  -                throw new MetadataException("Cannot create instance of class "+directEnclosingClass.getName()+"
because there is no no-arg constructor", ex);
  +                // the direct enclosing class is no inner class itself -> create with
no-arg constructor
  +                try
  +                {
  +                    return  ClassHelper.newInstance(directEnclosingClass, true);
  +                }
  +                catch (Exception ex)
  +                {
  +                    throw new MetadataException("Cannot create instance of class "+directEnclosingClass.getName()+"
because there is no no-arg constructor", ex);
  +                }
               }
           }
       }
  
  
  
  1.17      +14 -3     db-ojb/src/java/org/apache/ojb/broker/util/ClassHelper.java
  
  Index: ClassHelper.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/util/ClassHelper.java,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- ClassHelper.java	30 Sep 2005 21:45:14 -0000	1.16
  +++ ClassHelper.java	1 Oct 2005 09:20:26 -0000	1.17
  @@ -150,6 +150,17 @@
       }
   
       /**
  +     * Determines the encllsing class for static and non-static inner classes.
  +     * 
  +     * @param clazz The class
  +     * @return The enclosing class or <code>null</code> if the given class
is not an inner class
  +     */
  +    public static Class getEnclosingClass(Class clazz)
  +    {
  +        return clazz.getDeclaringClass();
  +    }
  +    
  +    /**
        * Determines whether the given class is a non-static inner class.
        * 
        * @param clazz The class
  @@ -157,9 +168,9 @@
        */
       public static boolean isNonStaticInnerClass(Class clazz)
       {
  -        return (clazz.getEnclosingClass() != null) && !Modifier.isStatic(clazz.getModifiers());
  +        return (getEnclosingClass(clazz) != null) && !Modifier.isStatic(clazz.getModifiers());
       }
  -    
  +
       /**
        * Returns a new instance of the given class, using the default or a no-arg constructor.
        * 
  
  
  
  1.4       +2 -1      db-ojb/src/java/org/apache/ojb/broker/metadata/CreationDescriptor.java
  
  Index: CreationDescriptor.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/metadata/CreationDescriptor.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- CreationDescriptor.java	30 Sep 2005 21:45:15 -0000	1.3
  +++ CreationDescriptor.java	1 Oct 2005 09:20:27 -0000	1.4
  @@ -178,7 +178,8 @@
       
                   for (int idx = 0; idx < constructors.length; idx++)
                   {
  -                    if (fitsCreationParameters(constructors[idx].getParameterTypes(), getTargetClass().getEnclosingClass()))
  +                    if (fitsCreationParameters(constructors[idx].getParameterTypes(),
  +                                               ClassHelper.getEnclosingClass(getTargetClass())))
                       {
                           constructor = constructors[idx];
                           break;
  
  
  
  1.2       +5 -4      db-ojb/src/java/org/apache/ojb/broker/metadata/EnclosingClassReferenceDescriptor.java
  
  Index: EnclosingClassReferenceDescriptor.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/metadata/EnclosingClassReferenceDescriptor.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- EnclosingClassReferenceDescriptor.java	30 Sep 2005 21:45:15 -0000	1.1
  +++ EnclosingClassReferenceDescriptor.java	1 Oct 2005 09:20:27 -0000	1.2
  @@ -19,6 +19,7 @@
   
   import org.apache.ojb.broker.metadata.fieldaccess.AnonymousPersistentField;
   import org.apache.ojb.broker.metadata.fieldaccess.PersistentField;
  +import org.apache.ojb.broker.util.ClassHelper;
   import org.apache.ojb.broker.util.logging.Logger;
   import org.apache.ojb.broker.util.logging.LoggerFactory;
   
  @@ -52,7 +53,7 @@
        */
       public void setItemClass(Class c)
       {
  -        Class curClass = getClassDescriptor().getClassOfObject().getEnclosingClass();
  +        Class curClass = ClassHelper.getEnclosingClass(getClassDescriptor().getClassOfObject());
   
           while (curClass != null)
           {
  @@ -62,7 +63,7 @@
               }
               else
               {
  -                curClass = curClass.getEnclosingClass();
  +                curClass = ClassHelper.getEnclosingClass(curClass);
               }
           }
           if (curClass == null)
  @@ -207,7 +208,7 @@
   
                       enclosingThisField.setAccessible(true);
                       curObject = enclosingThisField.get(curObject);
  -                    curClass  = curClass.getEnclosingClass();
  +                    curClass  = ClassHelper.getEnclosingClass(curClass);
                   }
                   while ((curClass != null) && !curClass.equals(targetClass));
               }
  
  
  

---------------------------------------------------------------------
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