📄 classdescriptor.java
字号:
package org.garret.perst.impl;
import org.garret.perst.*;
import java.lang.reflect.*;
import java.util.*;
public final class ClassDescriptor extends Persistent {
ClassDescriptor next;
String name;
boolean hasReferences;
FieldDescriptor[] allFields;
CustomAllocator allocator;
static class FieldDescriptor extends Persistent {
String fieldName;
String className;
int type;
ClassDescriptor valueDesc;
transient Field field;
public boolean equals(FieldDescriptor fd) {
return fieldName.equals(fd.fieldName)
&& className.equals(fd.className)
&& valueDesc == fd.valueDesc
&& type == fd.type;
}
}
transient Class cls;
transient Constructor loadConstructor;
transient LoadFactory factory;
transient Object[] constructorParams;
transient boolean hasSubclasses;
transient boolean resolved;
static ReflectionProvider reflectionProvider;
static boolean reverseMembersOrder;
public static final int tpBoolean = 0;
public static final int tpByte = 1;
public static final int tpChar = 2;
public static final int tpShort = 3;
public static final int tpInt = 4;
public static final int tpLong = 5;
public static final int tpFloat = 6;
public static final int tpDouble = 7;
public static final int tpString = 8;
public static final int tpDate = 9;
public static final int tpObject = 10;
public static final int tpValue = 11;
public static final int tpRaw = 12;
public static final int tpLink = 13;
public static final int tpEnum = 14;
public static final int tpCustom = 15;
public static final int tpArrayOfBoolean = 20;
public static final int tpArrayOfByte = 21;
public static final int tpArrayOfChar = 22;
public static final int tpArrayOfShort = 23;
public static final int tpArrayOfInt = 24;
public static final int tpArrayOfLong = 25;
public static final int tpArrayOfFloat = 26;
public static final int tpArrayOfDouble = 27;
public static final int tpArrayOfString = 28;
public static final int tpArrayOfDate = 29;
public static final int tpArrayOfObject = 30;
public static final int tpArrayOfValue = 31;
public static final int tpArrayOfRaw = 32;
public static final int tpArrayOfLink = 33; // not supported
public static final int tpArrayOfEnum = 34;
static final String signature[] = {
"boolean",
"byte",
"char",
"short",
"int",
"long",
"float",
"double",
"String",
"Date",
"Object",
"Value",
"Raw",
"Link",
"enum",
"",
"",
"",
"",
"",
"",
"ArrayOfBoolean",
"ArrayOfByte",
"ArrayOfChar",
"ArrayOfShort",
"ArrayOfInt",
"ArrayOfLong",
"ArrayOfFloat",
"ArrayOfDouble",
"ArrayOfEnum",
"ArrayOfString",
"ArrayOfDate",
"ArrayOfObject",
"ArrayOfValue",
"ArrayOfRaw",
"ArrayOfLink",
"ArrayOfEnum"
};
static final int sizeof[] = {
1, // tpBoolean
1, // tpByte
2, // tpChar
2, // tpShort
4, // tpInt
8, // tpLong
4, // tpFloat
8, // tpDouble
0, // tpString
8, // tpDate
4, // tpObject
0, // tpValue
0, // tpRaw
0, // tpLink
4 // tpEnum
};
static final Class[] perstConstructorProfile = new Class[]{ClassDescriptor.class};
static ReflectionProvider getReflectionProvider() {
if (reflectionProvider == null) {
try {
Class.forName("sun.misc.Unsafe");
String cls = "org.garret.perst.impl.sun14.Sun14ReflectionProvider";
reflectionProvider = (ReflectionProvider)Class.forName(cls).newInstance();
} catch (Throwable x) {
reflectionProvider = new StandardReflectionProvider();
}
}
return reflectionProvider;
}
public boolean equals(ClassDescriptor cd) {
if (cd == null || allFields.length != cd.allFields.length) {
return false;
}
for (int i = 0; i < allFields.length; i++) {
if (!allFields[i].equals(cd.allFields[i])) {
return false;
}
}
return true;
}
Object newInstance() {
if (factory != null) {
return factory.create(this);
} else {
try {
return loadConstructor.newInstance(constructorParams);
} catch (Exception x) {
throw new StorageError(StorageError.CONSTRUCTOR_FAILURE, cls, x);
}
}
}
void buildFieldList(StorageImpl storage, Class cls, ArrayList list) {
Class superclass = cls.getSuperclass();
if (superclass != null) {
buildFieldList(storage, superclass, list);
}
Field[] flds = cls.getDeclaredFields();
if (ClassDescriptor.class.equals(cls)) {
for (int i = 0; i < flds.length; i++) {
if ((flds[i].getModifiers() & (Modifier.TRANSIENT|Modifier.STATIC)) == 0) {
if (!"next".equals(flds[i].getName())) {
reverseMembersOrder = true;
}
break;
}
}
}
if (reverseMembersOrder) {
for (int i = 0, n = flds.length; i < (n >> 1); i++) {
Field f = flds[i];
flds[i] = flds[n-i-1];
flds[n-i-1] = f;
}
}
for (int i = 0; i < flds.length; i++) {
Field f = flds[i];
if ((f.getModifiers() & (Modifier.TRANSIENT|Modifier.STATIC)) == 0) {
try {
f.setAccessible(true);
} catch (Exception x) {}
FieldDescriptor fd = new FieldDescriptor();
fd.field = f;
fd.fieldName = f.getName();
fd.className = cls.getName();
int type = getTypeCode(f.getType());
switch (type) {
case tpObject:
case tpLink:
case tpArrayOfObject:
hasReferences = true;
break;
case tpValue:
fd.valueDesc = storage.getClassDescriptor(f.getType());
hasReferences |= fd.valueDesc.hasReferences;
break;
case tpArrayOfValue:
fd.valueDesc = storage.getClassDescriptor(f.getType().getComponentType());
hasReferences |= fd.valueDesc.hasReferences;
}
fd.type = type;
list.add(fd);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -