in yoko-rmi-impl/src/main/java/org/apache/yoko/rmi/impl/ValueDescriptor.java [158:399]
private void init0() {
final Class<?> superClass = type.getSuperclass();
_is_rmi_stub = RMIStub.class.isAssignableFrom(type);
_is_externalizable = Externalizable.class.isAssignableFrom(type);
_is_serializable = Serializable.class.isAssignableFrom(type);
_is_immutable_value = _immutable_value_classes.contains(type);
if ((superClass != null) && (superClass != Object.class)) {
TypeDescriptor superDesc = repo.getDescriptor(superClass);
if (superDesc instanceof ValueDescriptor) {
_super_descriptor = (ValueDescriptor) superDesc;
}
}
AccessController.doPrivileged(new PrivilegedAction<Object>() {
public Object run() {
for (Class<?> curr = type; curr != null; curr = curr.getSuperclass()) {
//
// get writeReplace, if any
//
try {
_write_replace_method = curr.getDeclaredMethod("writeReplace");
_write_replace_method.setAccessible(true);
break;
} catch (NoSuchMethodException ignored) {
}
}
//
// Get readResolve, if present
//
try {
_read_resolve_method = type.getDeclaredMethod("readResolve");
_read_resolve_method.setAccessible(true);
} catch (NoSuchMethodException ignored) {
}
//
// get readObject
//
try {
_read_object_method = type.getDeclaredMethod("readObject", ObjectInputStream.class);
_read_object_method.setAccessible(true);
} catch (NoSuchMethodException ignored) {
}
//
// get readObject
//
try {
_write_object_method = type.getDeclaredMethod("writeObject", ObjectOutputStream.class);
_write_object_method.setAccessible(true);
} catch (NoSuchMethodException ignored) {
}
//
// validate readObject
//
if ((_write_object_method == null) || !Modifier.isPrivate(_write_object_method.getModifiers())
|| Modifier.isStatic(_write_object_method.getModifiers()) || (_write_object_method.getDeclaringClass() != type)) {
_write_object_method = null;
}
//
// validate writeObject
//
if ((_read_object_method == null) || !Modifier.isPrivate(_read_object_method.getModifiers())
|| Modifier.isStatic(_read_object_method.getModifiers())) {
_read_object_method = null;
}
//
// get serialVersionUID field
//
try {
_serial_version_uid_field = type.getDeclaredField("serialVersionUID");
if (Modifier.isStatic(_serial_version_uid_field.getModifiers())) {
_serial_version_uid_field.setAccessible(true);
} else {
_serial_version_uid_field = null;
}
} catch (NoSuchFieldException ex) {
// skip //
}
//
// get serialPersistentFields field
//
ObjectStreamField[] serial_persistent_fields = null;
try {
Field _serial_persistent_fields_field = type.getDeclaredField("serialPersistentFields");
_serial_persistent_fields_field.setAccessible(true);
serial_persistent_fields = (ObjectStreamField[]) _serial_persistent_fields_field.get(null);
} catch (IllegalAccessException | NoSuchFieldException ex) {
// skip //
}
if (_is_externalizable) {
//
// Get the default constructor
//
try {
_constructor = type.getDeclaredConstructor();
_constructor.setAccessible(true);
} catch (NoSuchMethodException ex) {
logger.log(Level.WARNING, "Class " + type.getName() + " is not properly externalizable. "
+ "It has not default constructor.", ex);
}
} else if (_is_serializable && !type.isInterface()) {
Class<?> initClass = type;
while ((initClass != null) && Serializable.class.isAssignableFrom(initClass)) {
initClass = initClass.getSuperclass();
}
if (initClass == null) {
logger.warning("Class " + type.getName() + " is not properly serializable. " + "It has no non-serializable super-class");
} else {
try {
Constructor init_cons = initClass.getDeclaredConstructor();
if (Modifier.isPublic(init_cons.getModifiers()) || Modifier.isProtected(init_cons.getModifiers())) {
// do nothing - it's accessible
} else if (!samePackage(type, initClass)) {
logger.warning("Class " + type.getName() + " is not properly serializable. "
+ "The default constructor of its first " + "non-serializable super-class (" + initClass.getName()
+ ") is not accessible.");
}
_constructor = ReflectionFactory.getReflectionFactory().newConstructorForSerialization(type, init_cons);
if (_constructor == null) {
logger.warning("Unable to get constructor for serialization for class " + java_name);
} else {
_constructor.setAccessible(true);
}
} catch (NoSuchMethodException ex) {
logger.log(Level.WARNING, "Class " + type.getName() + " is not properly serializable. "
+ "First non-serializable super-class (" + initClass.getName() + ") has no default constructor.", ex);
}
}
}
if (serial_persistent_fields == null) {
//
// Get relevant field definitions
//
Field[] ff = type.getDeclaredFields();
if ((ff == null) || (ff.length == 0)) {
_fields = new FieldDescriptor[0];
} else {
List<FieldDescriptor> flist = new ArrayList<>();
for (Field f : ff) {
int mod = f.getModifiers();
if (Modifier.isStatic(mod) || Modifier.isTransient(mod)) {
continue;
}
f.setAccessible(true);
FieldDescriptor fd = FieldDescriptor.get(f, repo);
flist.add(fd);
}
_fields = new FieldDescriptor[flist.size()];
_fields = flist.toArray(_fields);
//
// sort the fields
//
Arrays.sort(_fields);
}
} else {
_fields = new FieldDescriptor[serial_persistent_fields.length];
for (int i = 0; i < serial_persistent_fields.length; i++) {
ObjectStreamField f = serial_persistent_fields[i];
FieldDescriptor fd = null;
try {
Field rf = type.getField(f.getName());
rf.setAccessible(true);
if (rf.getType() == f.getType()) {
fd = FieldDescriptor.get(rf,repo);
}
} catch (SecurityException | NoSuchFieldException ex) {
}
if (fd == null) {
fd = FieldDescriptor.get(type, f, repo);
}
_fields[i] = fd;
}
//
// sort the fields (this is also the case for serial
// persistent
// fields, because they have to map to some foreign
// IDL).
//
Arrays.sort(_fields);
}
//
// Compute the structural hash
//
_hash_code = computeHashCode();
//
// Setup the default deserializer
//
_object_deserializer = new ObjectDeserializer(ValueDescriptor.this);
return null;
}
});
}