static void print(ObjectStreamClass desc) { System.out.println("Class name : " + desc.getName()); System.out.println("SerialVersionUID: " + desc.getSerialVersionUID()); System.out.println("ObjectStreamFields"); ObjectStreamField[] fields = desc.getFields(); int numPrim = 0; int numObj = 0; for (int i = 0; i < fields.length; i++) { ObjectStreamField f = fields[i]; String fieldName = "<fieldName unknown>"; try { fieldName = f.getName(); } catch (NoSuchMethodError e) { // ignore. ObjectStreamField.getName did not exist in JDK 1.1 } if (f.isPrimitive()) { numPrim++; System.out.println("" + i + ". " + f.getType().getName() + " " + fieldName); } else { numObj++; String ts = "<unknown>"; try { ts = f.getTypeString(); } catch (NoSuchMethodError e) { // ignore. ObjectStreamField.getTypeString did not exist in JDK 1.1 ts = "<field type unknown>"; } System.out.println("" + i + ". " + ts + " " + fieldName); } } System.out.println("# primitive fields:" + numPrim + " # object ref fields:" + numObj); }
private static Map<String, Long> getMessageSVUID(Type messageType) throws SJIOException, ClassNotFoundException // SJCompilerUtils has a simpler version of this routine. { HashMap<String, Long> ours = new HashMap<String, Long>(); if (messageType instanceof SJSessionType) // Should come before ordinary class cases? (But SJSessionType shouldn't be a // class type). { ours.putAll(getClassSVUIDs((SJSessionType) messageType)); } else if (messageType.isPrimitive()) { // No SVUID needed for primitive types. } else if (messageType.isClass()) // Duplicated from above. { String className = messageType.toClass().fullName(); Class<?> c = Class.forName(className); if (c.isInterface()) { // Interfaces don't have SVUIDs (so what should we do here?). // This encourages use of // abstract classes rather than interfaces for message types? } else { ObjectStreamClass osc = ObjectStreamClass.lookup(c); if (osc == null) { throw new SJIOException("Class not serializable: " + c); } ours.put( className, osc .getSerialVersionUID()); // Not possible to find a different SVUID for the same // (name) class here? // SVUIDs could be recorded in the // session type objects. // Put currently problems working // with these values at compilation time if the class // binary is not available a priori (SVUID value not built // yet?). } } else if (messageType.isArray()) { throw new SJIOException("Array types not done yet: " + messageType); } return ours; }