Update of /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/tool/hbm2java
In directory sc8-pr-cvs1:/tmp/cvs-serv10459/src/net/sf/hibernate/tool/hbm2java
Modified Files:
ClassMapping.java
Log Message:
hbm2java now check if a type is an UserType and uses the value of returnedClass() property
instead of the acutal UserType name. (if it fails a warning is printed and it just uses the name of the UserType directly)
Index: ClassMapping.java
===================================================================
RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/tool/hbm2java/ClassMapping.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -d -r1.9 -r1.10
*** ClassMapping.java 2 Feb 2003 04:48:27 -0000 1.9
--- ClassMapping.java 2 Feb 2003 11:49:12 -0000 1.10
***************
*** 12,18 ****
--- 12,20 ----
import java.util.TreeSet;
+ import net.sf.hibernate.UserType;
import net.sf.hibernate.type.TypeFactory;
import net.sf.hibernate.type.PrimitiveType;
import net.sf.hibernate.type.Type;
+ import net.sf.hibernate.util.ReflectHelper;
import net.sf.hibernate.util.StringHelper;
***************
*** 587,590 ****
--- 589,594 ----
}
else {
+ // check and resolve correct type if it is an usertype
+ hibernateType = getTypeForUserType(hibernateType);
ClassName classType = new ClassName();
classType.setFullyQualifiedName(hibernateType);
***************
*** 596,599 ****
--- 600,641 ----
}
+ /** Returns name of returnedclass if type is an UserType **/
+ private String getTypeForUserType(String type) {
+ Class clazz = null;
+ try {
+ clazz = ReflectHelper.classForName(type);
+
+ if (UserType.class.isAssignableFrom(clazz)) {
+ UserType ut = (UserType) clazz.newInstance();
+ log.debug("Resolved usertype: " + type + " to " + ut.returnedClass().getName());
+ String t= clazzToName(ut.returnedClass());
+ return t;
+ }
+
+ } catch (ClassNotFoundException e) {
+ log.warn("Could not find UserType: " + type + ". Using the type '" + type + "' directly instead. (" + e.toString() +")");
+ } catch (IllegalAccessException iae) {
+ log.warn("Error while trying to resolve UserType. Using the type '" + type + "' directly instead. (" + iae.toString() + ")");
+ } catch (InstantiationException e) {
+ log.warn("Error while trying to resolve UserType. Using the type '" + type + "' directly instead. (" + e.toString() + ")");
+ }
+
+ return type;
+
+ }
+
+ private String clazzToName(Class cl) {
+ String s = null;
+
+ if(cl.isArray()) {
+ s = clazzToName(cl.getComponentType()) + "[]";
+ } else {
+ s = cl.getName();
+ }
+
+ return s;
+
+
+ }
|