You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-dev@db.apache.org by to...@apache.org on 2004/02/04 14:48:50 UTC

cvs commit: db-ojb/src/java/org/apache/ojb/broker/metadata DescriptorRepository.java

tomdz       2004/02/04 05:48:50

  Modified:    src/java/org/apache/ojb/broker/metadata
                        DescriptorRepository.java
  Log:
  Added support for discovering descriptors for interfaces as it is perfectly valid to have a normal class-descriptor with fields and all for interfaces (using factory-class, factory-method and property field accessors)
  
  Revision  Changes    Path
  1.47      +42 -7     db-ojb/src/java/org/apache/ojb/broker/metadata/DescriptorRepository.java
  
  Index: DescriptorRepository.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/metadata/DescriptorRepository.java,v
  retrieving revision 1.46
  retrieving revision 1.47
  diff -u -r1.46 -r1.47
  --- DescriptorRepository.java	30 Jan 2004 10:50:09 -0000	1.46
  +++ DescriptorRepository.java	4 Feb 2004 13:48:50 -0000	1.47
  @@ -645,20 +645,55 @@
               {
                   throw new OJBRuntimeException("Class, " + className + ", could not be found.", e);
               }
  +            result = discoverDescriptor(clazz);
  +         }
  +        return result;
  +    }
  +
  +    /**
  +     * Internal method for recursivly searching for a class descriptor that avoids
  +     * class loading when we already have a class object.
  +     *
  +     * @param clazz The class whose descriptor we need to find
  +     * @return ClassDescriptor for <code>clazz</code> or <code>null</code>
  +     *         if no ClassDescriptor could be located.
  +     */
  +    private ClassDescriptor discoverDescriptor(Class clazz)
  +    {
  +        ClassDescriptor result = (ClassDescriptor) descriptorTable.get(clazz.getName());
  +
  +        if (result == null)
  +        {
               Class superClass = clazz.getSuperclass();
  -            // only recurse if the superClass is a concrete object and it
  -            // is not a java.lang.Object. (boot strap condition)
  +            // only recurse if the superClass is not java.lang.Object
               if (superClass != null)
               {
  -                result = discoverDescriptor(superClass.getName());
  +                result = discoverDescriptor(superClass);
  +            }
  +            if (result == null)
  +            {
  +                // we're also checking the interfaces as there could be normal
  +                // mappings for them in the repository (using factory-class,
  +                // factory-method, and the property field accessor)
  +                Class[] interfaces = clazz.getInterfaces();
  +
  +                if ((interfaces != null) && (interfaces.length > 0))
  +                {
  +                    for (int idx = 0; (idx < interfaces.length) && (result == null); idx++)
  +                    {
  +                        result = discoverDescriptor(interfaces[idx]);
  +                    }
  +                }
               }
   
               if (result != null)
  -                descriptorTable.put(className, result);
  -         }
  +            {    
  +                descriptorTable.put(clazz.getName(), result);
  +            }
  +        }
           return result;
       }
  -
  +    
       protected void finalize() throws Throwable
       {
           LoggerFactory.getDefaultLogger().info("# finalize DescriptorRepository instance #");
  
  
  

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