xlsutil.java

来自「UCS (Ultra Corba Simulator) is one more 」· Java 代码 · 共 1,287 行 · 第 1/4 页

JAVA
1,287
字号
                if (!os.ior.equals("null")) {
                    MNQMutableTreeNode mtn = (MNQMutableTreeNode) op.dmtn.getParent();
                    IdlInterface in = (IdlInterface) mtn.getUserObject();
                    in.setior(os.ior);
                }
            }
            int col = 0;
            for (Enumeration e = root.children(); e.hasMoreElements();) {
                MNQMutableTreeNode mtn = (MNQMutableTreeNode) e.nextElement();
                Object n = mtn.getUserObject();
                if (n instanceof InArgs || n instanceof InoutArgs || n instanceof OutArgs) {
                    List tmp = XlsUtil.readObjectFromXXX(reader, col++, 3);
                    tmp = null;
                } else {
                    continue;
                }
            }

            reader.close();
            return true;
        } catch (Exception e) {
            MNQmainFrame.commonPane.appendln("fail to loadOperation:" + e.getMessage());
            return false;
        }
    }

    public static boolean loadOpFlow(MNQMutableTreeNode root, String file) {
        if (!root.isLeaf()) // remove child
        {
            ReplaceUtil.clearAll();
            MatchUtil.clearAll();
            root.removeAllChildren(true);
        }
        try {
            OpFlowReader reader = new OpFlowReader();
            if (!reader.open(file))
                return false;
            if (!reader.getFlowType().equals(OpFlowWriter.CLIENT_FLOW)) {
                // TODO:
                return false; // current only client side will be
                // supported
            }
            while (!reader.eof()) {
                OpFlowReader.FlowItemStruct fi = reader.getNextItem();
                if (fi.type.equals(OpFlowWriter.FILE_ITEM)) {
                    if (!addOperation(root, fi.value1, fi.value2))
                        return false;
                } else if (fi.type.equals(OpFlowWriter.REPLACE_ITEM)) {
                    ReplaceUtil.setRepParameterById(fi.value1, fi.value2);
                } else if (fi.type.equals(OpFlowWriter.PATTERN_ITEM)) {
                    MNQMutableTreeNode n = ReplaceUtil.pathId2node(fi.value1, root);
                    MatchUtil.setPattern(n, fi.value2);
                } else {
                    // TODO
                }
            }
            reader.close();
            return true;
        } catch (Exception e) {
            MNQmainFrame.commonPane.appendln("fail to load test suit:" + e.getMessage());
            return false;
        }
    }

    // remove child of sequence or array
    private static void removeSeqArray(MNQMutableTreeNode mtn) {
        TypeBase t = getMtnType(mtn);
        if ((t instanceof CTSequence) || (t instanceof CTArray)) {
            mtn.removeAllChildren(true);
            return;
        }
        for (Enumeration e = mtn.children(); e.hasMoreElements();) {
            MNQMutableTreeNode child = (MNQMutableTreeNode) e.nextElement();
            removeSeqArray(child);
        }
    }

    private static boolean saveNodeFromTree(OpWriter w, MNQMutableTreeNode parent,
            MNQMutableTreeNode root) {

        Object n = parent.getUserObject();
        TypeBase t;
        if (n instanceof Args) {
            Args p = (Args) n;
            t = p.pt;
        } else {
            t = (TypeBase) n;
        }
        t.getValueFromTree();
        String id = ReplaceUtil.getNodePathId(parent, root);
        if (t instanceof CTBasic) {
            if (t.rdn != null && t.rdn.equals("any")) {
                // System.out.println("meet any");
                ArgsTable table = (ArgsTable) Warehouse.node2table.get(parent);
                w.writeNextPar(id, table.getInputValue());
            } else {
                w.writeNextPar(id, t.toCaseLabel(t.val));
            }
        } else if (t instanceof CTEnum) {
            w.writeNextPar(id, t.toCaseLabel(t.val));
        } else if (t instanceof CTUnion) {
            ArgsTable table = (ArgsTable) Warehouse.node2table.get(parent);
            w.writeNextPar(id, table.getInputValue());
        } else if (t instanceof CTExceptList) {
            ArgsTable table = (ArgsTable) Warehouse.node2table.get(parent);
            w.writeNextPar(id, table.getInputValue());
        }

        if (!parent.isLeaf()) {
            for (Enumeration e = parent.children(); e.hasMoreElements();) {
                MNQMutableTreeNode mtn = (MNQMutableTreeNode) e.nextElement();
                if (!saveNodeFromTree(w, mtn, root))
                    return false;
            }
        }
        return true;
    }

    // used to save operation on operation tree
    public static boolean saveOperation(IdlOperation op, MNQMutableTreeNode root, String file) {
        OpWriter w = new OpWriter();
        if (!w.open(file))
            return false;
        if (!w.writeOp(op.toString(), op.cName, op.getIor()))
            return false;
        // go through whole parameter tree,including
        for (Enumeration e = root.children(); e.hasMoreElements();) {
            MNQMutableTreeNode mtn = (MNQMutableTreeNode) e.nextElement();
            if (!saveNodeFromTree(w, mtn, root))
                return false;
        }
        w.close();
        return true;
    }

    // used to save operation on operation tree for both
    public static boolean saveOperationBoth(IdlOperation op, MNQMutableTreeNode root, String file) {
        OpWriter w = new OpWriter();
        if (!w.openBoth(file))
            return false;
        if (!w.writeOp(op.toString(), op.cName, op.getIor()))
            return false;
        if (!w.writeOpXXX(op.toString(), op.cName, op.getIor()))
            return false;
        // go through whole parameter tree,including
        for (Enumeration e = root.children(); e.hasMoreElements();) {
            MNQMutableTreeNode mtn = (MNQMutableTreeNode) e.nextElement();
            if (!saveNodeFromTree(w, mtn, root))
                return false;

        }

        // go through whole parameter tree,including
        int col = 0;
        for (Enumeration e = root.children(); e.hasMoreElements();) {
            MNQMutableTreeNode mtn = (MNQMutableTreeNode) e.nextElement();
            Object n = mtn.getUserObject();
            if (n instanceof InArgs || n instanceof InoutArgs || n instanceof OutArgs) {
                Args args = (Args) n;
                if (!saveArgsFromTreeXXX(w, args, col)) { return false; }
                col++;
            } else {
                continue;
            }
        }

        w.close();
        return true;
    }

    // used to save operation on operation tree without gui info
    public static boolean saveOperationXXX(IdlOperation op, MNQMutableTreeNode root, String file) {
        OpWriter w = new OpWriter();
        if (!w.openXXX(file))
            return false;
        if (!w.writeOpXXX(op.toString(), op.cName, op.getIor()))
            return false;
        // go through whole parameter tree,including
        int col = 0;
        for (Enumeration e = root.children(); e.hasMoreElements();) {
            MNQMutableTreeNode mtn = (MNQMutableTreeNode) e.nextElement();
            Object n = mtn.getUserObject();
            if (n instanceof InArgs || n instanceof InoutArgs || n instanceof OutArgs) {
                Args args = (Args) n;
                if (!saveArgsFromTreeXXX(w, args, col)) { return false; }
                col++;
            } else {
                continue;
            }
        }
        w.closeXXX();
        return true;
    }

    private static boolean saveArgsFromTreeXXX(OpWriter w, Args args, int col) {

        TypeBase t = args.pt;
        int line = 2;
        w.writeNextParXXX(col, line, args.toString());
        line++;
        // get value from parameter tree
        t.getValueFromTree();

        Object val = t.val;

        return saveObjectToXXX(w, val, col, line) < 0 ? false : true;
    }

    // read object value from file
    // list: 0 -- lin, 1--object value
    private static List readObjectFromXXX(OpReader r, int col, int lin) {
        String str = r.getNextParXXX(col, lin++);
        List ret = new Vector();
        List tmp;
        TypeBase tb;
        ;

        if (str.equals("java.lang.Object[]")) {
            // CTArray , CTSequence
            str = r.getNextParXXX(col, lin++);
            int len = Integer.parseInt(str);
            Object[] oo = new Object[len];

            for (int i = 0; i < oo.length; i++) {
                tmp = readObjectFromXXX(r, col, lin);
                lin = ((Integer) tmp.get(0)).intValue();
                oo[i] = tmp.get(1);
            }
            ret.add(new Integer(lin));
            ret.add(oo);
            return ret;
        } else if (str.equals("java.util.List")) {
            // CTStruct , CTUnion , CTExcept
            List list = new Vector();
            str = r.getNextParXXX(col, lin++);
            int len = Integer.parseInt(str);
            for (int i = 0; i < len; i++) {
                tmp = readObjectFromXXX(r, col, lin);
                lin = ((Integer) tmp.get(0)).intValue();
                list.add(tmp.get(1));
            }
            ret.add(new Integer(lin));
            ret.add(list);
            return ret;
            // } else if (str.equals("org.omg.CORBA.Object")) {
            // org.omg.CORBA.Object obj = (org.omg.CORBA.Object) o;
            // w.writeNextParXXX(col, lin, "java.lang.String");
            // lin++;
            // String str = "";
            // try {
            // str = CorbaFacility.orb.object_to_string(obj);
            // } catch (Exception ex) {
            // // nothing to do
            // }
            // w.writeNextParXXX(col, lin, str);
            // lin++;
            // return lin;
        } else if (str.equals("org.omg.CORBA.Any")) {
            // CTBasic, "any"
            org.omg.CORBA.Any any = CorbaFacility.orb.create_any();
            str = r.getNextParXXX(col, lin++);
            Object node = Warehouse.cname2node.get(str.replaceAll("::_", "::"));
            if (node != null) {
                if (node instanceof IdlType) {
                    tb = ((IdlType) node).toType();
                    tmp = readObjectFromXXX(r, col, lin);
                    lin = ((Integer) tmp.get(0)).intValue();
                    tb.insert(any, tmp.get(1));
                } else if (node instanceof IdlInterface) {
                    tb = ((IdlInterface) node).toType();
                    tmp = readObjectFromXXX(r, col, lin);
                    lin = ((Integer) tmp.get(0)).intValue();
                    tb.insert(any, tmp.get(1));
                } else {
                    // try the primitive
                }
            } else {
                // primitive type
                if (str.equals("tk_float")) {
                    str = r.getNextParXXX(col, lin++);
                    str = r.getNextParXXX(col, lin++);
                    any.insert_float(new Float(str).floatValue());
                }
                if (str.equals("tk_double")) {
                    str = r.getNextParXXX(col, lin++);
                    str = r.getNextParXXX(col, lin++);
                    any.insert_double(new Double(str).doubleValue());
                }
                if (str.equals("tk_longdouble")) {
                    str = r.getNextParXXX(col, lin++);
                    str = r.getNextParXXX(col, lin++);
                    any.insert_double(new Double(str).doubleValue());
                }
                if (str.equals("tk_short")) {
                    str = r.getNextParXXX(col, lin++);
                    str = r.getNextParXXX(col, lin++);
                    any.insert_short(new Short(str).shortValue());
                }
                if (str.equals("tk_long")) {
                    str = r.getNextParXXX(col, lin++);
                    str = r.getNextParXXX(col, lin++);
                    any.insert_long(new Integer(str).intValue());
                }
                if (str.equals("tk_longlong")) {
                    str = r.getNextParXXX(col, lin++);
                    str = r.getNextParXXX(col, lin++);
                    any.insert_longlong(new Long(str).longValue());
                }
                if (str.equals("tk_ushort")) {
                    str = r.getNextParXXX(col, lin++);
                    str = r.getNextParXXX(col, lin++);
                    any.insert_ushort(new Short(str).shortValue());
                }
                if (str.equals("tk_ulong")) {
                    str = r.getNextParXXX(col, lin++);
                    str = r.getNextParXXX(col, lin++);
                    any.insert_ulong(new Integer(str).intValue());
                }
                if (str.equals("tk_ulonglong")) {
                    str = r.getNextParXXX(col, lin++);
                    str = r.getNextParXXX(col, lin++);
                    any.insert_ulonglong(new Long(str).longValue());

⌨️ 快捷键说明

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