* @throws IOException In case of error.
*/
static GridOptimizedClassDescriptor classDescriptor(Class<?> cls, @Nullable Object obj) throws IOException {
if (obj != null) {
if (obj instanceof GridOptimizedMarshallable) {
GridOptimizedMarshallable m = (GridOptimizedMarshallable)obj;
Object clsId = m.ggClassId();
if (clsId != null && !(clsId instanceof GridOptimizedClassDescriptor))
throw new IOException("Method '" + obj.getClass().getName() + ".ggClassId() must return " +
"the value of the field '" + CLS_ID_FIELD_NAME + "'.");
GridOptimizedClassDescriptor desc = (GridOptimizedClassDescriptor)clsId;
if (desc == null) {
desc = new GridOptimizedClassDescriptor(cls);
try {
Field field = obj.getClass().getDeclaredField(CLS_ID_FIELD_NAME);
field.setAccessible(true);
Object o = field.get(null);
if (o == null) {
if ((field.getModifiers() & Modifier.STATIC) == 0)
throw new IOException("Field '" + CLS_ID_FIELD_NAME + "' must be declared static: " +
obj.getClass().getName());
field.set(null, desc);
if (m.ggClassId() == null)
throw new IOException( "Method '" + obj.getClass().getName() + ".ggClassId() must " +
"return the value of the field '" + CLS_ID_FIELD_NAME + "': "
+ obj.getClass().getName());
}
else if (!(o instanceof GridOptimizedClassDescriptor))