| Method from java.io.ObjectStreamClass Detail: |
void buildFieldDescriptors(Field[] declaredFields) {
// We could find the field ourselves in the collection, but calling
// reflect is easier. Optimize if needed.
final Field f = ObjectStreamClass.fieldSerialPersistentFields(this
.forClass());
// If we could not find the emulated fields, we'll have to compute
// dumpable fields from reflect fields
boolean useReflectFields = f == null; // Assume we will compute the
// fields to dump based on the
// reflect fields
ObjectStreamField[] _fields = null;
if (!useReflectFields) {
// The user declared a collection of emulated fields. Use them.
// We have to be able to fetch its value, even if it is private
AccessController.doPrivileged(new PriviAction< Object >(f));
try {
// static field, pass null
_fields = (ObjectStreamField[]) f.get(null);
} catch (IllegalAccessException ex) {
// WARNING - what should we do if we have no access ? This
// should not happen.
throw new RuntimeException(ex);
}
} else {
// Compute collection of dumpable fields based on reflect fields
List< ObjectStreamField > serializableFields = new ArrayList< ObjectStreamField >(
declaredFields.length);
// Filter, we are only interested in fields that are serializable
for (int i = 0; i < declaredFields.length; i++) {
Field declaredField = declaredFields[i];
int modifiers = declaredField.getModifiers();
boolean shouldBeSerialized = !(Modifier.isStatic(modifiers) || Modifier
.isTransient(modifiers));
if (shouldBeSerialized) {
ObjectStreamField field = new ObjectStreamField(
declaredField.getName(), declaredField.getType());
serializableFields.add(field);
}
}
if (serializableFields.size() == 0) {
_fields = NO_FIELDS; // If no serializable fields, share the
// special value so that users can test
} else {
// Now convert from Vector to array
_fields = new ObjectStreamField[serializableFields.size()];
_fields = serializableFields.toArray(_fields);
}
}
ObjectStreamField.sortFields(_fields);
// assign offsets
int primOffset = 0, objectOffset = 0;
for (int i = 0; i < _fields.length; i++) {
Class< ? > type = _fields[i].getType();
if (type.isPrimitive()) {
_fields[i].offset = primOffset;
primOffset += primitiveSize(type);
} else {
_fields[i].offset = objectOffset++;
}
}
fields = _fields;
}
Builds the collection of field descriptors for the receiver |
static Field fieldSerialPersistentFields(Class<?> cl) {
try {
Field f = cl.getDeclaredField("serialPersistentFields"); //$NON-NLS-1$
int modifiers = f.getModifiers();
if (Modifier.isStatic(modifiers) && Modifier.isPrivate(modifiers)
&& Modifier.isFinal(modifiers)) {
if (f.getType() == ARRAY_OF_FIELDS) {
return f;
}
}
} catch (NoSuchFieldException nsm) {
// Ignored
}
return null;
}
Return the java.lang.reflect.Field {@code serialPersistentFields}
if class {@code cl} implements it. Return null otherwise. |
ObjectStreamField[] fields() {
if (fields == null) {
Class< ? > forCl = forClass();
if (forCl != null && isSerializable() && !forCl.isArray()) {
buildFieldDescriptors(forCl.getDeclaredFields());
} else {
// Externalizables or arrays do not need FieldDesc info
setFields(NO_FIELDS);
}
}
return fields;
}
Returns the collection of field descriptors for the fields of the
corresponding class |
static Method findMethod(Class<?> cl,
String methodName) {
Class< ? > search = cl;
Method method = null;
while (search != null) {
try {
method = search.getDeclaredMethod(methodName, (Class[]) null);
if (search == cl
|| (method.getModifiers() & Modifier.PRIVATE) == 0) {
method.setAccessible(true);
return method;
}
} catch (NoSuchMethodException nsm) {
}
search = search.getSuperclass();
}
return null;
}
Return the java.lang.reflect.Method if class cl implements
methodName . Return null otherwise. |
static Method findPrivateMethod(Class<?> cl,
String methodName,
Class<?>[] param) {
try {
Method method = cl.getDeclaredMethod(methodName, param);
if (Modifier.isPrivate(method.getModifiers())
&& method.getReturnType() == VOID_CLASS) {
method.setAccessible(true);
return method;
}
} catch (NoSuchMethodException nsm) {
// Ignored
}
return null;
}
Return the java.lang.reflect.Method if class cl implements
private methodName . Return null otherwise. |
public Class<?> forClass() {
if (resolvedClass != null) {
return resolvedClass.get();
}
return null;
}
Returns the class (java.lang.Class) for this descriptor. |
long getConstructor() {
return constructor;
}
|
static native String getConstructorSignature(Constructor<?> c)
Return a String representing the signature for a Constructor {@code c}. |
public ObjectStreamField getField(String name) {
ObjectStreamField[] allFields = getFields();
for (int i = 0; i < allFields.length; i++) {
ObjectStreamField f = allFields[i];
if (f.getName().equals(name)) {
return f;
}
}
return null;
}
Gets a field descriptor of the class represented by this class
descriptor. |
public ObjectStreamField[] getFields() {
copyFieldAttributes();
return loadFields == null ? fields().clone() : loadFields.clone();
}
Returns a collection of field descriptors for the serialized fields of
the class represented by this class descriptor. |
byte getFlags() {
return flags;
}
Returns the flags for this descriptor, where possible combined values are
ObjectStreamConstants.SC_WRITE_METHOD
ObjectStreamConstants.SC_SERIALIZABLE
ObjectStreamConstants.SC_EXTERNALIZABLE |
ObjectStreamField[] getLoadFields() {
return loadFields;
}
Returns the collection of field descriptors for the input fields of the
corresponding class |
Method getMethodReadObject() {
return methodReadObject;
}
|
Method getMethodReadObjectNoData() {
return methodReadObjectNoData;
}
|
Method getMethodReadResolve() {
return methodReadResolve;
}
|
static native String getMethodSignature(Method m)
Return a String representing the signature for a method {@code m}. |
Method getMethodWriteObject() {
return methodWriteObject;
}
|
Method getMethodWriteReplace() {
return methodWriteReplace;
}
|
public String getName() {
return className;
}
Returns the name of the class represented by this descriptor. |
public long getSerialVersionUID() {
return svUID;
}
Returns the Serial Version User ID of the class represented by this
descriptor. |
ObjectStreamClass getSuperclass() {
return superclass;
}
Returns the descriptor (ObjectStreamClass) of the superclass of the class
represented by the receiver. |
boolean hasMethodReadObject() {
return (methodReadObject != null);
}
|
boolean hasMethodReadObjectNoData() {
return (methodReadObjectNoData != null);
}
|
boolean hasMethodReadResolve() {
return (methodReadResolve != null);
}
|
boolean hasMethodWriteObject() {
return (methodWriteObject != null);
}
|
boolean hasMethodWriteReplace() {
return (methodWriteReplace != null);
}
|
void initPrivateFields(ObjectStreamClass desc) {
methodWriteReplace = desc.methodWriteReplace;
methodReadResolve = desc.methodReadResolve;
methodWriteObject = desc.methodWriteObject;
methodReadObject = desc.methodReadObject;
methodReadObjectNoData = desc.methodReadObjectNoData;
}
|
boolean isEnum() {
resolveProperties();
return isEnum;
}
Answers whether the class for this descriptor is subclass of Enum |
boolean isExternalizable() {
resolveProperties();
return isExternalizable;
}
Answers whether the class for this descriptor is serializable |
static boolean isExternalizable(Class<?> cl) {
return EXTERNALIZABLE.isAssignableFrom(cl);
}
Return true if instances of class {@code cl} are Externalizable,
false otherwise. |
static boolean isPrimitiveType(char typecode) {
return !(typecode == '[' || typecode == 'L');
}
Return true if the type code
typecode describes a primitive type |
boolean isProxy() {
resolveProperties();
return isProxy;
}
Answers whether the class for this descriptor is proxied class |
boolean isSerializable() {
resolveProperties();
return isSerializable;
}
Answers whether the class for this descriptor is serializable |
static boolean isSerializable(Class<?> cl) {
return SERIALIZABLE.isAssignableFrom(cl);
}
Return true if instances of class {@code cl} are Serializable,
false otherwise. |
public static ObjectStreamClass lookup(Class<?> cl) {
ObjectStreamClass osc = lookupStreamClass(cl);
if (osc.isSerializable() || osc.isExternalizable()) {
return osc;
}
return null;
}
Returns the descriptor corresponding to the class {@code cl}. If the
class is not serializable or externalizable then {@code null} is
returned. |
public static ObjectStreamClass lookupAny(Class<?> cl) {
return lookupStreamClass(cl);
}
Return the descriptor (ObjectStreamClass) corresponding to the class
cl. This method does not check whether the class
implements Serializable or Externalizable. |
static ObjectStreamClass lookupStreamClass(Class<?> cl) {
WeakHashMap< Class< ? >,ObjectStreamClass > tlc = OSCThreadLocalCache.oscWeakHashMap.get();
ObjectStreamClass cachedValue = tlc.get(cl);
if (cachedValue == null) {
cachedValue = createClassDesc(cl);
tlc.put(cl, cachedValue);
}
return cachedValue;
}
Return the descriptor (ObjectStreamClass) corresponding to the class
{@code cl}. Returns an ObjectStreamClass even if instances of the
class cannot be serialized |
void setClass(Class<?> c) {
resolvedClass = new WeakReference< Class< ? > >(c);
}
Set the class (java.lang.Class) that the receiver represents |
void setConstructor(long newConstructor) {
constructor = newConstructor;
}
|
void setFields(ObjectStreamField[] f) {
fields = f;
}
Set the collection of field descriptors for the fields of the
corresponding class |
void setFlags(byte b) {
flags = b;
}
Set the flags for this descriptor, where possible combined values are
ObjectStreamConstants.SC_WRITE_METHOD
ObjectStreamConstants.SC_SERIALIZABLE
ObjectStreamConstants.SC_EXTERNALIZABLE |
void setLoadFields(ObjectStreamField[] f) {
loadFields = f;
}
Set the collection of field descriptors for the input fields of the
corresponding class |
void setName(String newName) {
className = newName;
}
Set the name of the class represented by the receiver |
void setSerialVersionUID(long l) {
svUID = l;
}
Set the Serial Version User ID of the class represented by the receiver |
void setSuperclass(ObjectStreamClass c) {
superclass = c;
}
Set the descriptor for the superclass of the class described by the
receiver |
public String toString() {
return getName() + ": static final long serialVersionUID =" //$NON-NLS-1$
+ getSerialVersionUID() + "L;"; //$NON-NLS-1$
}
Returns a string containing a concise, human-readable description of this
descriptor. |