* @param composite
* @exception XDocletException
*/
void hasCompositeId_Impl(String template, boolean composite) throws XDocletException
{
XClass oldClass = getCurrentClass();
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()}));
}
// Determine whether or not the ID is a user-defined type.
// If it is then it is not a composite id.
boolean isUserType = false;
String typeStr = method.getDoc().getTagAttributeValue("hibernate.id", "type");
if (typeStr != null) {
// The type attribute was supplied, so check
// whether it implements cirrus.hibernate.UserType
XClass typeClass = getXJavaDoc().getXClass(typeStr);
if (typeClass != null) {
isUserType = typeClass.isA("cirrus.hibernate.UserType") || typeClass.isA("net.sf.hibernate.UserType");
}
}
else {
typeStr = method.getReturnType().getType().getQualifiedName();
}
// decide whether we have composite or primitive ID
boolean isPrimitive = TypeTagsHandler.isPrimitiveType(typeStr) ||
"java.lang.Byte".equals(typeStr) ||
"java.lang.Double".equals(typeStr) ||
"java.lang.Float".equals(typeStr) ||
"java.lang.Integer".equals(typeStr) ||
"java.lang.Long".equals(typeStr) ||
"java.lang.Short".equals(typeStr) ||
"java.lang.String".equals(typeStr) ||
"java.math.BigDecimal".equals(typeStr) ||
"java.math.BigInteger".equals(typeStr) ||
isUserType;
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().getType();
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()}));
}
}
if (getCurrentClass() != oldClass)
setCurrentClass(oldClass);