⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xmlimporter.java

📁 这个是perst-269.zip下面的SOURCECODE,和大家分享了。
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
                        }
                    }
                    offs += 8;
                    continue;
                case ClassDescriptor.tpFloat:
                    buf.extend(offs + 4);
                    if (elem != null) { 
                        if (elem.isIntValue()) {
                            Bytes.pack4(buf.arr, offs, Float.floatToIntBits((float)elem.getIntValue()));
                        } else if (elem.isRealValue()) {
                            Bytes.pack4(buf.arr, offs, Float.floatToIntBits((float)elem.getRealValue()));
                        } else { 
                            throwException("Conversion for field " + fieldName + " is not possible");
                        }
                    }
                    offs += 4;
                    continue;
                case ClassDescriptor.tpDouble:
                    buf.extend(offs + 8);
                    if (elem != null) { 
                        if (elem.isIntValue()) {
                            Bytes.pack8(buf.arr, offs, Double.doubleToLongBits((double)elem.getIntValue()));
                        } 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.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.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");
                            }
                            int oid = mapId(getIntAttribute(ref, "id"));
                            Bytes.pack4(buf.arr, offs, oid);
                            item = item.getNextSibling();
                            offs += 4;
                        }
                    }
                    continue;
                case ClassDescriptor.tpArrayOfValue:
                    if (elem == null || elem.isNullValue()) {
                        buf.extend(offs + 4);
                        Bytes.pack4(buf.arr, offs, -1);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -