📄 xmlimporter.java
字号:
} else if (elem.isRealValue()) {
Bytes.pack8(buf.arr, offs, Double.doubleToLongBits((double)elem.getRealValue()));
} else {
throwException("Conversion for field " + fieldName + " is not possible");
}
}
offs += 8;
continue;
case ClassDescriptor.tpEnum:
buf.extend(offs + 4);
if (elem != null) {
if (elem.isIntValue()) {
Bytes.pack4(buf.arr, offs, (int)elem.getIntValue());
} else if (elem.isRealValue()) {
Bytes.pack4(buf.arr, offs, (int)elem.getRealValue());
} else if (elem.isNullValue()) {
Bytes.pack4(buf.arr, offs, -1);
} else if (elem.isStringValue()) {
Bytes.pack4(buf.arr, offs, Enum.valueOf((Class)fd.field.getType(), elem.getStringValue()).ordinal());
} else {
throwException("Conversion for field " + fieldName + " is not possible");
}
}
offs += 4;
continue;
case ClassDescriptor.tpDate:
buf.extend(offs + 8);
if (elem != null) {
if (elem.isIntValue()) {
Bytes.pack8(buf.arr, offs, elem.getIntValue());
} else if (elem.isNullValue()) {
Bytes.pack8(buf.arr, offs, -1);
} else if (elem.isStringValue()) {
Date date = httpFormatter.parse(elem.getStringValue(), new ParsePosition(0));
if (date == null) {
throwException("Invalid date");
}
Bytes.pack8(buf.arr, offs, date.getTime());
} else {
throwException("Conversion for field " + fieldName + " is not possible");
}
}
offs += 8;
continue;
case ClassDescriptor.tpString:
if (elem != null) {
String value = null;
if (elem.isIntValue()) {
value = Long.toString(elem.getIntValue());
} else if (elem.isRealValue()) {
value = Double.toString(elem.getRealValue());
} else if (elem.isStringValue()) {
value = elem.getStringValue();
} else if (elem.isNullValue()) {
value = null;
} else {
throwException("Conversion for field " + fieldName + " is not possible");
}
offs = buf.packString(offs, value, storage.encoding);
continue;
}
buf.extend(offs + 4);
Bytes.pack4(buf.arr, offs, -1);
offs += 4;
continue;
case ClassDescriptor.tpObject:
{
int oid = 0;
if (elem != null) {
XMLElement ref = elem.getSibling("ref");
if (ref == null) {
throwException("<ref> element expected");
}
oid = mapId(getIntAttribute(ref, "id"));
}
buf.extend(offs + 4);
Bytes.pack4(buf.arr, offs, oid);
offs += 4;
continue;
}
case ClassDescriptor.tpValue:
offs = packObject(elem, fd.valueDesc, offs, buf);
continue;
case ClassDescriptor.tpRaw:
case ClassDescriptor.tpArrayOfByte:
offs = importBinary(elem, offs, buf, fieldName);
continue;
case ClassDescriptor.tpCustom:
{
if (!elem.isStringValue()) {
throwException("text element expected");
}
String str = elem.getStringValue();
try {
CustomSerializable obj = storage.serializer.parse(str);
storage.serializer.pack(obj, buf.getOutputStream());
offs = buf.size();
} catch (IOException x) {
throwException("exception in custom serializer: " + x);
}
break;
}
case ClassDescriptor.tpArrayOfBoolean:
if (elem == null || elem.isNullValue()) {
buf.extend(offs + 4);
Bytes.pack4(buf.arr, offs, -1);
offs += 4;
} else {
XMLElement item = elem.getSibling("element");
int len = (item == null) ? 0 : item.getCounter();
buf.extend(offs + 4 + len);
Bytes.pack4(buf.arr, offs, len);
offs += 4;
while (--len >= 0) {
if (item.isIntValue()) {
buf.arr[offs] = (byte)(item.getIntValue() != 0 ? 1 : 0);
} else if (item.isRealValue()) {
buf.arr[offs] = (byte)(item.getRealValue() != 0.0 ? 1 : 0);
} else {
throwException("Conversion for field " + fieldName + " is not possible");
}
item = item.getNextSibling();
offs += 1;
}
}
continue;
case ClassDescriptor.tpArrayOfChar:
case ClassDescriptor.tpArrayOfShort:
if (elem == null || elem.isNullValue()) {
buf.extend(offs + 4);
Bytes.pack4(buf.arr, offs, -1);
offs += 4;
} else {
XMLElement item = elem.getSibling("element");
int len = (item == null) ? 0 : item.getCounter();
buf.extend(offs + 4 + len*2);
Bytes.pack4(buf.arr, offs, len);
offs += 4;
while (--len >= 0) {
if (item.isIntValue()) {
Bytes.pack2(buf.arr, offs, (short)item.getIntValue());
} else if (item.isRealValue()) {
Bytes.pack2(buf.arr, offs, (short)item.getRealValue());
} else {
throwException("Conversion for field " + fieldName + " is not possible");
}
item = item.getNextSibling();
offs += 2;
}
}
continue;
case ClassDescriptor.tpArrayOfInt:
if (elem == null || elem.isNullValue()) {
buf.extend(offs + 4);
Bytes.pack4(buf.arr, offs, -1);
offs += 4;
} else {
XMLElement item = elem.getSibling("element");
int len = (item == null) ? 0 : item.getCounter();
buf.extend(offs + 4 + len*4);
Bytes.pack4(buf.arr, offs, len);
offs += 4;
while (--len >= 0) {
if (item.isIntValue()) {
Bytes.pack4(buf.arr, offs, (int)item.getIntValue());
} else if (item.isRealValue()) {
Bytes.pack4(buf.arr, offs, (int)item.getRealValue());
} else {
throwException("Conversion for field " + fieldName + " is not possible");
}
item = item.getNextSibling();
offs += 4;
}
}
continue;
case ClassDescriptor.tpArrayOfEnum:
if (elem == null || elem.isNullValue()) {
buf.extend(offs + 4);
Bytes.pack4(buf.arr, offs, -1);
offs += 4;
} else {
XMLElement item = elem.getSibling("element");
int len = (item == null) ? 0 : item.getCounter();
buf.extend(offs + 4 + len*4);
Bytes.pack4(buf.arr, offs, len);
Class enumType = fd.field.getType();
offs += 4;
while (--len >= 0) {
if (item.isIntValue()) {
Bytes.pack4(buf.arr, offs, (int)item.getIntValue());
} else if (item.isRealValue()) {
Bytes.pack4(buf.arr, offs, (int)item.getRealValue());
} else if (item.isNullValue()) {
Bytes.pack4(buf.arr, offs, -1);
} else if (item.isStringValue()) {
Bytes.pack4(buf.arr, offs, Enum.valueOf(enumType, item.getStringValue()).ordinal());
} else {
throwException("Conversion for field " + fieldName + " is not possible");
}
item = item.getNextSibling();
offs += 4;
}
}
continue;
case ClassDescriptor.tpArrayOfLong:
if (elem == null || elem.isNullValue()) {
buf.extend(offs + 4);
Bytes.pack4(buf.arr, offs, -1);
offs += 4;
} else {
XMLElement item = elem.getSibling("element");
int len = (item == null) ? 0 : item.getCounter();
buf.extend(offs + 4 + len*8);
Bytes.pack4(buf.arr, offs, len);
offs += 4;
while (--len >= 0) {
if (item.isIntValue()) {
Bytes.pack8(buf.arr, offs, item.getIntValue());
} else if (item.isRealValue()) {
Bytes.pack8(buf.arr, offs, (long)item.getRealValue());
} else {
throwException("Conversion for field " + fieldName + " is not possible");
}
item = item.getNextSibling();
offs += 8;
}
}
continue;
case ClassDescriptor.tpArrayOfFloat:
if (elem == null || elem.isNullValue()) {
buf.extend(offs + 4);
Bytes.pack4(buf.arr, offs, -1);
offs += 4;
} else {
XMLElement item = elem.getSibling("element");
int len = (item == null) ? 0 : item.getCounter();
buf.extend(offs + 4 + len*4);
Bytes.pack4(buf.arr, offs, len);
offs += 4;
while (--len >= 0) {
if (item.isIntValue()) {
Bytes.pack4(buf.arr, offs, Float.floatToIntBits((float)item.getIntValue()));
} else if (item.isRealValue()) {
Bytes.pack4(buf.arr, offs, Float.floatToIntBits((float)item.getRealValue()));
} else {
throwException("Conversion for field " + fieldName + " is not possible");
}
item = item.getNextSibling();
offs += 4;
}
}
continue;
case ClassDescriptor.tpArrayOfDouble:
if (elem == null || elem.isNullValue()) {
buf.extend(offs + 4);
Bytes.pack4(buf.arr, offs, -1);
offs += 4;
} else {
XMLElement item = elem.getSibling("element");
int len = (item == null) ? 0 : item.getCounter();
buf.extend(offs + 4 + len*8);
Bytes.pack4(buf.arr, offs, len);
offs += 4;
while (--len >= 0) {
if (item.isIntValue()) {
Bytes.pack8(buf.arr, offs, Double.doubleToLongBits((double)item.getIntValue()));
} else if (item.isRealValue()) {
Bytes.pack8(buf.arr, offs, Double.doubleToLongBits((double)item.getRealValue()));
} else {
throwException("Conversion for field " + fieldName + " is not possible");
}
item = item.getNextSibling();
offs += 8;
}
}
continue;
case ClassDescriptor.tpArrayOfDate:
if (elem == null || elem.isNullValue()) {
buf.extend(offs + 4);
Bytes.pack4(buf.arr, offs, -1);
offs += 4;
} else {
XMLElement item = elem.getSibling("element");
int len = (item == null) ? 0 : item.getCounter();
buf.extend(offs + 4 + len*8);
Bytes.pack4(buf.arr, offs, len);
offs += 4;
while (--len >= 0) {
if (item.isNullValue()) {
Bytes.pack8(buf.arr, offs, -1);
} else if (item.isStringValue()) {
Date date = httpFormatter.parse(item.getStringValue(), new ParsePosition(0));
if (date == null) {
throwException("Invalid date");
}
Bytes.pack8(buf.arr, offs, date.getTime());
} else {
throwException("Conversion for field " + fieldName + " is not possible");
}
item = item.getNextSibling();
offs += 8;
}
}
continue;
case ClassDescriptor.tpArrayOfString:
if (elem == null || elem.isNullValue()) {
buf.extend(offs + 4);
Bytes.pack4(buf.arr, offs, -1);
offs += 4;
} else {
XMLElement item = elem.getSibling("element");
int len = (item == null) ? 0 : item.getCounter();
buf.extend(offs + 4);
Bytes.pack4(buf.arr, offs, len);
offs += 4;
while (--len >= 0) {
String value = null;
if (item.isIntValue()) {
value = Long.toString(item.getIntValue());
} else if (item.isRealValue()) {
value = Double.toString(item.getRealValue());
} else if (item.isStringValue()) {
value = item.getStringValue();
} else if (item.isNullValue()) {
value = null;
} else {
throwException("Conversion for field " + fieldName + " is not possible");
}
offs = buf.packString(offs, value, storage.encoding);
item = item.getNextSibling();
}
}
continue;
case ClassDescriptor.tpArrayOfObject:
case ClassDescriptor.tpLink:
if (elem == null || elem.isNullValue()) {
buf.extend(offs + 4);
Bytes.pack4(buf.arr, offs, -1);
offs += 4;
} else {
XMLElement item = elem.getSibling("element");
int len = (item == null) ? 0 : item.getCounter();
buf.extend(offs + 4 + len*4);
Bytes.pack4(buf.arr, offs, len);
offs += 4;
while (--len >= 0) {
XMLElement ref = item.getSibling("ref");
if (ref == null) {
throwException("<ref> element expected");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -