📄 classdescriptor.java
字号:
}
public static int getTypeCode(Class c) {
int type;
if (c.equals(byte.class)) {
type = tpByte;
} else if (c.equals(short.class)) {
type = tpShort;
} else if (c.equals(char.class)) {
type = tpChar;
} else if (c.equals(int.class)) {
type = tpInt;
} else if (c.equals(long.class)) {
type = tpLong;
} else if (c.equals(float.class)) {
type = tpFloat;
} else if (c.equals(double.class)) {
type = tpDouble;
} else if (c.equals(String.class)) {
type = tpString;
} else if (c.equals(boolean.class)) {
type = tpBoolean;
} else if (c.isEnum()) {
type = tpEnum;
} else if (c.equals(java.util.Date.class)) {
type = tpDate;
} else if (IPersistent.class.isAssignableFrom(c)) {
type = tpObject;
} else if (IValue.class.isAssignableFrom(c)) {
type = tpValue;
} else if (c.equals(Link.class)) {
type = tpLink;
} else if (c.isArray()) {
type = getTypeCode(c.getComponentType());
if (type >= tpLink) {
throw new StorageError(StorageError.UNSUPPORTED_TYPE, c);
}
type += tpArrayOfBoolean;
} else if (CustomSerializable.class.isAssignableFrom(c)) {
type = tpCustom;
} else if (c.equals(Object.class) || Comparable.class.isAssignableFrom(c)) {
type = tpRaw;
} else if (serializeNonPersistentObjects) {
type = tpRaw;
} else if (treateAnyNonPersistentObjectAsValue) {
if (c.equals(Object.class)) {
throw new StorageError(StorageError.EMPTY_VALUE);
}
type = tpValue;
} else {
throw new StorageError(StorageError.UNSUPPORTED_TYPE, c);
}
return type;
}
static boolean treateAnyNonPersistentObjectAsValue = Boolean.getBoolean("perst.implicit.values");
static boolean serializeNonPersistentObjects = Boolean.getBoolean("perst.serialize.transient.objects");
ClassDescriptor() {}
private void locateConstructor() {
try {
//Class c = Class.forName(cls.getName() + "LoadFactory");
Class c = Thread.currentThread().getContextClassLoader().loadClass(cls.getName() + "LoadFactory");
factory = (LoadFactory)c.newInstance();
} catch (Exception x1) {
try {
loadConstructor = cls.getDeclaredConstructor(perstConstructorProfile);
constructorParams = new Object[]{this};
} catch (NoSuchMethodException x2) {
try {
loadConstructor = getReflectionProvider().getDefaultConstructor(cls);
constructorParams = null;
} catch (Exception x3) {
throw new StorageError(StorageError.DESCRIPTOR_FAILURE, cls, x3);
}
}
try {
loadConstructor.setAccessible(true);
} catch (Exception x) {}
}
}
ClassDescriptor(StorageImpl storage, Class cls) {
this.cls = cls;
name = getClassName(cls);
ArrayList list = new ArrayList();
buildFieldList(storage, cls, list);
allFields = (FieldDescriptor[])list.toArray(new FieldDescriptor[list.size()]);
locateConstructor();
resolved = true;
}
protected static Field locateField(Class scope, String name) {
try {
do {
try {
Field fld = scope.getDeclaredField(name);
try {
fld.setAccessible(true);
} catch (Exception e) {}
return fld;
} catch (NoSuchFieldException x) {
scope = scope.getSuperclass();
}
} while (scope != null);
} catch (Exception x) {
throw new StorageError(StorageError.ACCESS_VIOLATION, scope.getName() + "." + name, x);
}
return null;
}
public static String getClassName(Class cls) {
ClassLoader loader = cls.getClassLoader();
return (loader instanceof INamedClassLoader)
? ((INamedClassLoader)loader).getName() + ':' + cls.getName()
: cls.getName();
}
public static Class loadClass(Storage storage, String name) {
if (storage != null) {
int col = name.indexOf(':');
ClassLoader loader;
if (col >= 0) {
loader = storage.findClassLoader(name.substring(0, col));
if (loader == null) {
// just ignore this class
return null;
}
name = name.substring(col+1);
} else {
loader = storage.getClassLoader();
}
if (loader != null) {
try {
return loader.loadClass(name);
} catch (ClassNotFoundException x) {}
}
}
try {
return Thread.currentThread().getContextClassLoader().loadClass(name);
// return Class.forName(name);
} catch (ClassNotFoundException x) {
throw new StorageError(StorageError.CLASS_NOT_FOUND, name, x);
}
}
public void onLoad() {
cls = loadClass(getStorage(), name);
Class scope = cls;
int n = allFields.length;
for (int i = n; --i >= 0;) {
FieldDescriptor fd = allFields[i];
fd.load();
if (!fd.className.equals(scope.getName())) {
for (scope = cls; scope != null; scope = scope.getSuperclass()) {
if (fd.className.equals(scope.getName())) {
break;
}
}
}
if (scope != null) {
try {
Field f = scope.getDeclaredField(fd.fieldName);
if ((f.getModifiers() & (Modifier.TRANSIENT|Modifier.STATIC)) == 0) {
try {
f.setAccessible(true);
} catch (Exception e) {}
fd.field = f;
}
} catch (NoSuchFieldException x) {}
} else {
scope = cls;
}
}
for (int i = n; --i >= 0;) {
FieldDescriptor fd = allFields[i];
if (fd.field == null) {
hierarchyLoop:
for (scope = cls; scope != null; scope = scope.getSuperclass()) {
try {
Field f = scope.getDeclaredField(fd.fieldName);
if ((f.getModifiers() & (Modifier.TRANSIENT|Modifier.STATIC)) == 0) {
for (int j = 0; j < n; j++) {
if (allFields[j].field == f) {
continue hierarchyLoop;
}
}
try {
f.setAccessible(true);
} catch (Exception e) {}
fd.field = f;
break;
}
} catch (NoSuchFieldException x) {}
}
}
}
locateConstructor();
StorageImpl s = (StorageImpl)getStorage();
if (s.classDescMap.get(cls) == null) {
s.classDescMap.put(cls, this);
}
}
void resolve() {
if (!resolved) {
StorageImpl classStorage = (StorageImpl)getStorage();
ClassDescriptor desc = new ClassDescriptor(classStorage, cls);
resolved = true;
if (!desc.equals(this)) {
classStorage.registerClassDescriptor(desc);
}
}
}
public boolean recursiveLoading() {
return false;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -