tomdz       2005/08/22 14:24:06

  Modified:    src/xdoclet/test/xdoclet/modules/ojb/tests Tag:
                        OJB_1_0_RELEASE
                        ReferenceTagClassRefAttributeTests.java
               src/xdoclet/java/src/xdoclet/modules/ojb/constraints Tag:
                        OJB_1_0_RELEASE ReferenceDescriptorConstraints.java
                        InheritanceHelper.java
               lib      Tag: OJB_1_0_RELEASE xdoclet-ojb-module-1.2.3.jar
  Log:
  Fix for bug uncovered by OJB-61 where the unqualified name was used instead 
of the qualified name for retreiving a class for checking the assignability of 
the class-ref type and the declared variable type
  Added check for whether the declared field type of a reference can be 
resolved (source or classpath); if not a warning will now be issued and the 
check will not be performed which makes the XDoclet usable in the case of 
OJB-61 (using the XJavadoc version 1.5)
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.6.2.3   +80 -0     
db-ojb/src/xdoclet/test/xdoclet/modules/ojb/tests/ReferenceTagClassRefAttributeTests.java
  
  Index: ReferenceTagClassRefAttributeTests.java
  ===================================================================
  RCS file: 
/home/cvs/db-ojb/src/xdoclet/test/xdoclet/modules/ojb/tests/ReferenceTagClassRefAttributeTests.java,v
  retrieving revision 1.6.2.2
  retrieving revision 1.6.2.3
  diff -u -r1.6.2.2 -r1.6.2.3
  --- ReferenceTagClassRefAttributeTests.java   18 Jun 2005 14:16:33 -0000      
1.6.2.2
  +++ ReferenceTagClassRefAttributeTests.java   22 Aug 2005 21:24:04 -0000      
1.6.2.3
  @@ -1222,4 +1222,84 @@
               "</database>",
               runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest"));
       }
  +
  +    // Test for OJB-61 though without Java5 syntax; the classes would not 
actually compile
  +    // but the idea is that the variable type cannot be resolved
  +    public void testClassRef21()
  +    {
  +        addClass(
  +            "test.A",
  +            "package test;\n"+
  +            "/** @ojb.class */\n"+
  +            "public class A {\n"+
  +            "  /** @ojb.field primarykey=\"true\" */\n"+
  +            "  private Integer id;\n"+
  +            "}\n");
  +        addClass(
  +            "test.B",
  +            "package test;\n"+
  +            "/** @ojb.class */\n"+
  +            "public class B {\n"+
  +            "  /** @ojb.field */\n"+
  +            "  private Integer aid;\n"+
  +            "  /** @ojb.reference foreignkey=\"aid\"\n"+
  +            "    *                class-ref=\"test.A\"\n"+
  +            "    */\n"+
  +            "  private T attr;\n"+
  +            "}\n");
  +
  +        // this should pass but with a few warnings because T could not be 
found
  +        assertEqualsOjbDescriptorFile(
  +            "<class-descriptor\n"+
  +            "    class=\"test.A\"\n"+
  +            "    table=\"A\"\n"+
  +            ">\n"+
  +            "    <field-descriptor\n"+
  +            "        name=\"id\"\n"+
  +            "        column=\"id\"\n"+
  +            "        jdbc-type=\"INTEGER\"\n"+
  +            "        primarykey=\"true\"\n"+
  +            "    >\n"+
  +            "    </field-descriptor>\n"+
  +            "</class-descriptor>\n"+
  +            "<class-descriptor\n"+
  +            "    class=\"test.B\"\n"+
  +            "    table=\"B\"\n"+
  +            ">\n"+
  +            "    <field-descriptor\n"+
  +            "        name=\"aid\"\n"+
  +            "        column=\"aid\"\n"+
  +            "        jdbc-type=\"INTEGER\"\n"+
  +            "    >\n"+
  +            "    </field-descriptor>\n"+
  +            "    <reference-descriptor\n"+
  +            "        name=\"attr\"\n"+
  +            "        class-ref=\"test.A\"\n"+
  +            "    >\n"+
  +            "        <foreignkey field-ref=\"aid\"/>\n"+
  +            "    </reference-descriptor>\n"+
  +            "</class-descriptor>",
  +            runOjbXDoclet(OJB_DEST_FILE));
  +        assertEqualsTorqueSchemaFile(
  +            "<database name=\"ojbtest\">\n"+
  +            "    <table name=\"A\">\n"+
  +            "        <column name=\"id\"\n"+
  +            "                javaName=\"id\"\n"+
  +            "                type=\"INTEGER\"\n"+
  +            "                primaryKey=\"true\"\n"+
  +            "                required=\"true\"\n"+
  +            "        />\n"+
  +            "    </table>\n"+
  +            "    <table name=\"B\">\n"+
  +            "        <column name=\"aid\"\n"+
  +            "                javaName=\"aid\"\n"+
  +            "                type=\"INTEGER\"\n"+
  +            "        />\n"+
  +            "        <foreign-key foreignTable=\"A\">\n"+
  +            "            <reference local=\"aid\" foreign=\"id\"/>\n"+
  +            "        </foreign-key>\n"+
  +            "    </table>\n"+
  +            "</database>",
  +            runTorqueXDoclet(TORQUE_DEST_FILE, "ojbtest"));
  +    }
   }
  
  
  
  No                   revision
  No                   revision
  1.4.2.2   +21 -2     
db-ojb/src/xdoclet/java/src/xdoclet/modules/ojb/constraints/ReferenceDescriptorConstraints.java
  
  Index: ReferenceDescriptorConstraints.java
  ===================================================================
  RCS file: 
/home/cvs/db-ojb/src/xdoclet/java/src/xdoclet/modules/ojb/constraints/ReferenceDescriptorConstraints.java,v
  retrieving revision 1.4.2.1
  retrieving revision 1.4.2.2
  diff -u -r1.4.2.1 -r1.4.2.2
  --- ReferenceDescriptorConstraints.java       18 Jun 2005 14:16:33 -0000      
1.4.2.1
  +++ ReferenceDescriptorConstraints.java       22 Aug 2005 21:24:05 -0000      
1.4.2.2
  @@ -1,5 +1,6 @@
   package xdoclet.modules.ojb.constraints;
   
  +import xdoclet.modules.ojb.LogHelper;
   import xdoclet.modules.ojb.model.ClassDescriptorDef;
   import xdoclet.modules.ojb.model.ModelDef;
   import xdoclet.modules.ojb.model.PropertyHelper;
  @@ -100,9 +101,27 @@
                   else
                   {    
                       // specified element class must be a subtype of the 
variable type (if it exists, i.e. not for anonymous references)
  -                    String varType = 
refDef.getProperty(PropertyHelper.OJB_PROPERTY_VARIABLE_TYPE);
  +                    String  varType      = 
refDef.getProperty(PropertyHelper.OJB_PROPERTY_VARIABLE_TYPE);
  +                    boolean performCheck = true;
       
  -                    if (!helper.isSameOrSubTypeOf(targetClassDef, varType, 
true))
  +                    // but we first check whether there is a useable type 
for the the variable type 
  +                    if (model.getClass(varType) == null)
  +                    {
  +                        try
  +                        {
  +                            InheritanceHelper.getClass(varType);
  +                        }
  +                        catch (ClassNotFoundException ex)
  +                        {
  +                            // no, so defer the check but issue a warning
  +                            performCheck = false;
  +                            LogHelper.warn(true,
  +                                           getClass(),
  +                                           "ensureClassRef",
  +                                           "Cannot check whether the type 
"+targetClassDef.getQualifiedName()+" specified as class-ref at reference 
"+refDef.getName()+" in class "+ownerClassDef.getName()+" is assignable to the 
declared type "+varType+" of the reference because this variable type cannot be 
found in source or on the classpath");
  +                        }
  +                    }
  +                    if (performCheck && 
!helper.isSameOrSubTypeOf(targetClassDef, varType, true))
                       {
                           throw new ConstraintException("The class 
"+targetClassName+" referenced by "+refDef.getName()+" in class 
"+ownerClassDef.getName()+" is not the same or a subtype of the variable type 
"+varType);
                       }
  
  
  
  1.3.2.2   +1 -1      
db-ojb/src/xdoclet/java/src/xdoclet/modules/ojb/constraints/InheritanceHelper.java
  
  Index: InheritanceHelper.java
  ===================================================================
  RCS file: 
/home/cvs/db-ojb/src/xdoclet/java/src/xdoclet/modules/ojb/constraints/InheritanceHelper.java,v
  retrieving revision 1.3.2.1
  retrieving revision 1.3.2.2
  diff -u -r1.3.2.1 -r1.3.2.2
  --- InheritanceHelper.java    18 Jun 2005 14:16:33 -0000      1.3.2.1
  +++ InheritanceHelper.java    22 Aug 2005 21:24:05 -0000      1.3.2.2
  @@ -95,7 +95,7 @@
           }
   
           // if not found, we try via actual classes
  -        return checkActualClasses ? isSameOrSubTypeOf(type.getName(), 
qualifiedBaseType) : false;
  +        return checkActualClasses ? 
isSameOrSubTypeOf(type.getQualifiedName(), qualifiedBaseType) : false;
       }
   
       /**
  
  
  
  No                   revision
  No                   revision
  1.1.2.4   +126 -129  db-ojb/lib/xdoclet-ojb-module-1.2.3.jar
  
        <<Binary file>>
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to