tomdz 2005/08/22 14:31:40
Modified: src/xdoclet/java/src/xdoclet/modules/ojb/constraints
InheritanceHelper.java
ReferenceDescriptorConstraints.java
src/xdoclet/test/xdoclet/modules/ojb/tests
ReferenceTagClassRefAttributeTests.java
lib 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
1.5 +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.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- InheritanceHelper.java 19 Jun 2005 13:53:33 -0000 1.4
+++ InheritanceHelper.java 22 Aug 2005 21:31:40 -0000 1.5
@@ -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;
}
/**
1.6 +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.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- ReferenceDescriptorConstraints.java 19 Jun 2005 13:53:33 -0000
1.5
+++ ReferenceDescriptorConstraints.java 22 Aug 2005 21:31:40 -0000
1.6
@@ -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.9 +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.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- ReferenceTagClassRefAttributeTests.java 19 Jun 2005 13:53:33 -0000
1.8
+++ ReferenceTagClassRefAttributeTests.java 22 Aug 2005 21:31:40 -0000
1.9
@@ -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"));
+ }
}
1.4 +124 -127 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]