Update of /cvsroot/xdoclet/xdoclet/modules/hibernate/src/xdoclet/modules/hibernate
In directory
sc8-pr-cvs1:/tmp/cvs-serv28056/modules/hibernate/src/xdoclet/modules/hibernate
Modified Files:
HibernateTagsHandler.java XDocletModulesHibernateMessages.java
Log Message:
XDT-219 - Partial implementation of composite ID support.
Index: HibernateTagsHandler.java
===================================================================
RCS file:
/cvsroot/xdoclet/xdoclet/modules/hibernate/src/xdoclet/modules/hibernate/HibernateTagsHandler.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -r1.4 -r1.5
*** HibernateTagsHandler.java 30 Dec 2002 14:08:33 -0000 1.4
--- HibernateTagsHandler.java 6 Jan 2003 12:08:23 -0000 1.5
***************
*** 10,16 ****
--- 10,20 ----
import org.apache.commons.logging.Log;
import xjavadoc.ClassIterator;
+ import xjavadoc.MethodIterator;
import xjavadoc.XClass;
import xjavadoc.XCollections;
+ import xjavadoc.XDoc;
+ import xjavadoc.XMethod;
+ import xjavadoc.XTag;
import xdoclet.DocletContext;
***************
*** 22,27 ****
--- 26,33 ----
import xdoclet.tagshandler.ClassTagsHandler;
+ import xdoclet.tagshandler.TypeTagsHandler;
import xdoclet.util.LogUtil;
+ import xdoclet.util.Translator;
import xdoclet.util.TypeConversionUtil;
/**
***************
*** 37,42 ****
{
- //~ Methods
........................................................................................................
-
/**
* Returns full path of hibernate file for the current class.
--- 43,46 ----
***************
*** 58,61 ****
--- 62,114 ----
/**
+ * find id property of current class
+ *
+ * @return
+ * @exception XDocletException
+ */
+ public XMethod getIdMethod() throws XDocletException
+ {
+ XClass clazz = getCurrentClass();
+ MethodIterator methodIterator =
+XCollections.methodIterator(clazz.getMethods(true));
+
+ XMethod method;
+
+ // iterate through all the methods defined in this class
+ while (methodIterator.hasNext()) {
+ method = methodIterator.next();
+ if (method.getDoc().hasTag("hibernate.id")) {
+ return method;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * render template if ID is composite
+ *
+ * @param template
+ * @param attributes
+ * @exception XDocletException
+ * @doc.tag type="block"
+ */
+ public void ifHasCompositeId(String template, Properties attributes) throws
+XDocletException
+ {
+ hasCompositeId_Impl(template, true);
+ }
+
+ /**
+ * render template if id is primitive
+ *
+ * @param template
+ * @param attributes
+ * @exception XDocletException
+ * @doc.tag type="block"
+ */
+ public void ifHasPrimitiveId(String template, Properties attributes) throws
+XDocletException
+ {
+ hasCompositeId_Impl(template, false);
+ }
+
+ /**
* return configured service name
*
***************
*** 184,187 ****
--- 237,299 ----
}
}
+ }
+
+ /**
+ * actual templating for composite/primitive IDs
+ *
+ * @param template
+ * @param composite
+ * @exception XDocletException
+ */
+ void hasCompositeId_Impl(String template, boolean composite) throws
+XDocletException
+ {
+ XMethod method = getIdMethod();
+
+ // bomb politely if no ID method could be found
+ if (method == null) {
+ throw new XDocletException(
+ Translator.getString(XDocletModulesHibernateMessages.class,
+ XDocletModulesHibernateMessages.NO_ID_PROPERTY,
+ new String[]{getCurrentClass().getQualifiedName()}));
+ }
+
+ // decide whether we have composite or primitive ID
+ String type = method.getReturnType().getQualifiedName();
+ boolean isPrimitive = TypeTagsHandler.isPrimitiveType(type) ||
+ "java.lang.Byte".equals(type) ||
+ "java.lang.Double".equals(type) ||
+ "java.lang.Float".equals(type) ||
+ "java.lang.Integer".equals(type) ||
+ "java.lang.Long".equals(type) ||
+ "java.lang.Short".equals(type) ||
+ "java.lang.String".equals(type);
+
+ if (isPrimitive && !composite) {
+ setCurrentMethod(method);
+ generate(template);
+ }
+
+ if (composite && !isPrimitive) {
+ // check whether specified type satisfies us
+ // it has to be serializable,
+ // and implement equals itself.
+ // bomb if not.
+ XClass returnType = method.getReturnType();
+
+ if (returnType.isA("java.io.Serializable") && !returnType.isAbstract() &&
+
+!"java.lang.Object".equals(returnType.getMethod("equals(java.lang.Object)",
+true).getContainingClass().getQualifiedName())) {
+ setCurrentMethod(method);
+ generate(template);
+
+ }
+ else {
+ // bomb politely that given property does not qualify as composite ID
+ throw new XDocletException(
+ Translator.getString(XDocletModulesHibernateMessages.class,
+ XDocletModulesHibernateMessages.WRONG_COMPOSITE_ID,
+ new String[]{returnType.getQualifiedName()}));
+ }
+ }
+
}
Index: XDocletModulesHibernateMessages.java
===================================================================
RCS file:
/cvsroot/xdoclet/xdoclet/modules/hibernate/src/xdoclet/modules/hibernate/XDocletModulesHibernateMessages.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -r1.4 -r1.5
*** XDocletModulesHibernateMessages.java 12 Dec 2002 18:27:56 -0000 1.4
--- XDocletModulesHibernateMessages.java 6 Jan 2003 12:08:23 -0000 1.5
***************
*** 47,49 ****
--- 47,63 ----
*/
public final static String DATA_SOURCE_REQUIRED = "DATA_SOURCE_REQUIRED";
+ /**
+ * @msg.bundle msg="Class {0} misses ID property"
+ * @msg.bundle msg="Klasse {0} braucht ID-Property" language="de"
+ */
+ public static String NO_ID_PROPERTY = "NO_ID_PROPERTY";
+
+ /**
+ * @msg.bundle msg="Composite ID property of type {0} is invalid. It has to be
+serializable and reimplement
+ * equals(Object)"
+ * @msg.bundle msg="Datentyp {0} kann nicht als Composite-ID verwendet werden.
+Composite ID mu� Serializierbar
+ * sein, und equals(Object) �berladen" language="de"
+ */
+ public static String WRONG_COMPOSITE_ID = "WRONG_COMPOSITE_ID";
+
}
-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
_______________________________________________
Xdoclet-devel mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/xdoclet-devel