{
// When using inner class, must be static
if (ClassUtils.isInnerClass(pkClass.getName()) &&
!Modifier.isStatic(pkClass.getModifiers()))
{
throw new InvalidPrimaryKeyException(LOCALISER, "019000",
cmd.getFullClassName(), pkClass.getName());
}
// Must be public
if (!Modifier.isPublic(pkClass.getModifiers()))
{
throw new InvalidPrimaryKeyException(LOCALISER, "019001",
cmd.getFullClassName(), pkClass.getName());
}
// Must implement Serializable
if (!Serializable.class.isAssignableFrom(pkClass))
{
throw new InvalidPrimaryKeyException(LOCALISER, "019002",
cmd.getFullClassName(), pkClass.getName());
}
// a). JDO's SingleFieldIdentity class
if (isSingleFieldIdentityClass(pkClass.getName()))
{
if (noOfPkFields != 1)
{
throw new InvalidPrimaryKeyException(LOCALISER, "019003",
cmd.getFullClassName());
}
}
// b). Users own primary key class
else
{
// Must have public default constructor
try
{
Constructor constructor = pkClass.getConstructor(new Class[0]);
if (constructor == null ||
!Modifier.isPublic(constructor.getModifiers()))
{
throw new InvalidPrimaryKeyException(LOCALISER, "019004",
cmd.getFullClassName(), pkClass.getName());
}
}
catch (NoSuchMethodException ex)
{
throw new InvalidPrimaryKeyException(LOCALISER, "019004",
cmd.getFullClassName(), pkClass.getName());
}
// Must have public String arg constructor
try
{
Constructor constructor=
pkClass.getConstructor(new Class[] {String.class});
if (constructor == null ||
!Modifier.isPublic(constructor.getModifiers()))
{
throw new InvalidPrimaryKeyException(LOCALISER, "019005",
cmd.getFullClassName(), pkClass.getName());
}
}
catch (NoSuchMethodException nsme)
{
}
// Must override toString() method
try
{
java.lang.reflect.Method method=pkClass.getMethod("toString",new Class[0]);
if (method == null ||
!Modifier.isPublic(method.getModifiers()) ||
method.getDeclaringClass().equals(Object.class))
{
throw new InvalidPrimaryKeyException(LOCALISER, "019006",
cmd.getFullClassName(), pkClass.getName());
}
}
catch (NoSuchMethodException nsme)
{
}
// Must override hashCode() method
try
{
java.lang.reflect.Method method=pkClass.getMethod("hashCode",new Class[0]);
if (method == null ||
method.getDeclaringClass().equals(Object.class))
{
throw new InvalidPrimaryKeyException(LOCALISER, "019007",
cmd.getFullClassName(), pkClass.getName());
}
}
catch (NoSuchMethodException nsme)
{
}
// Must override equals(Object) method
try
{
java.lang.reflect.Method method=pkClass.getMethod("equals",new Class[] {Object.class});
if (method == null ||
method.getDeclaringClass().equals(Object.class))
{
throw new InvalidPrimaryKeyException(LOCALISER, "019008",
cmd.getFullClassName(), pkClass.getName());
}
}
catch (NoSuchMethodException nsme)
{
}
// Check the field types of the objectid-class
int noPkFields = processPrimaryKeyClass(pkClass, cmd, clr, mmgr);
for (Class<?> supercls : ClassUtils.getSuperclasses(pkClass))
{
noPkFields += processPrimaryKeyClass(supercls, cmd, clr, mmgr);
}
// No of Primary Key fields and no of fields in
// objectid-class must concur
if (noOfPkFields != noPkFields &&
cmd.getIdentityType() == IdentityType.APPLICATION)
{
throw new InvalidPrimaryKeyException(LOCALISER, "019015",
cmd.getFullClassName(), pkClass.getName(),
"" + noOfPkFields, "" + noPkFields);
}
}