diiimpl.java

来自「UCS (Ultra Corba Simulator) is one more 」· Java 代码 · 共 325 行

JAVA
325
字号
package com.corba.mnq.skelstub;

import com.corba.mnq.main.MNQmainFrame;
import com.corba.mnq.tool.CorbaFacility;
import com.corba.mnq.tool.LoggerTool;
import com.corba.mnq.tool.idl.IdlOperation;
import com.corba.mnq.tool.idl.type.CTExcept;
import com.corba.mnq.tool.idl.type.TypeBase;
import com.corba.mnq.ui.MNQMutableTreeNode;
import com.corba.mnq.xls.XlsUtil;

import javax.swing.JTree;

import java.util.List;
import java.util.Vector;
import java.util.logging.Logger;

import org.omg.CORBA.Any;
import org.omg.CORBA.TypeCode;
import org.omg.CORBA.UnknownUserException;

public class DiiImpl {

    private DiiImpl() {
        super();
        // TODO Auto-generated constructor stub
    }

    /** used for java.util.logging */
    private static final Logger LOG = Logger.getLogger(DiiImpl.class.getName());

    /**
     * @param obj
     *            obj for IOR string
     * @param op
     *            operation rdn
     * @param ret
     *            TypeCode for return type
     * @param in
     *            List of TypeBase
     * @param out
     *            List of TypeCode
     * @param inout
     *            List of TypeBase
     * @param excep
     *            List of ExcepType
     * @param oneWay
     */
    public static void invoke(IdlOperation opnode, List allArg, List excep, List allRes,
            TypeBase rt, TypeBase except, JTree tree, MNQMutableTreeNode topPara) {
        org.omg.CORBA.ORB orb = TypeBase.orb;

        try {

            String str = opnode.getIor();
            org.omg.CORBA.Object obj = TypeBase.orb.string_to_object(str);
            String op = opnode.sName;
            TypeCode ret = opnode.getReturnType().type();
            boolean oneWay = opnode.oneway;

            // a simple request
            List outAll = new Vector();
            Any tmp;
            // List result include in & inout & out
            List result = new Vector();

            org.omg.CORBA.Request r = obj._request(op);

            if (ret != null) {
                r.set_return_type(ret);
            } else {
                r.set_return_type(orb.get_primitive_tc(org.omg.CORBA.TCKind.tk_void));
            }

            // prepare in arguments
            for (int i = 0; i < allArg.size(); i++) {
                TypeBase arg = (TypeBase) allArg.get(i);
                if (arg.argModes.equalsIgnoreCase("in")) {
                    tmp = r.add_in_arg();
                    arg.insert(tmp, arg.val);
                    result.add(tmp);
                } else if (arg.argModes.equalsIgnoreCase("inout")) {
                    tmp = r.add_inout_arg();
                    arg.insert(tmp, arg.val);
                    outAll.add(tmp);
                    result.add(tmp);
                } else if (arg.argModes.equalsIgnoreCase("out")) {
                    tmp = r.add_out_arg();
                    tmp.type(arg.type());
                    outAll.add(tmp);
                    result.add(tmp);
                } else {
                    // nothing to do
                }
            }

            // prepare exception lists
            org.omg.CORBA.ExceptionList exceptions = r.exceptions();
            for (int i = 0; i < excep.size(); i++) {
                exceptions.add(((CTExcept) excep.get(i)).type());
            }

            if (oneWay) {
                r.send_oneway();
            } else {
                r.invoke();
            }

            MNQmainFrame.clientPane.appendln("Output ( " + opnode.sName + " ) :", "Title");

            Exception e = r.env().exception();
            if (e != null) {
                try {
                    org.omg.CORBA.UnknownUserException ue = (UnknownUserException) e;
                    MNQmainFrame.clientPane.appendln(CorbaFacility.toString(ue.except, true),
                            "Exception");
                    // if (except != null) {
                    // if (compareAny(ue.except, except.toAny())) {
                    // MNQmainFrame.clientPane
                    // .appendln("IdlExcept Successful!!!!!!!");
                    // } else {
                    // MNQmainFrame.clientPane
                    // .appendln("IdlExcept Failiure!!!!!!!");
                    // }
                    // } else {
                    // MNQmainFrame.clientPane
                    // .appendln("IdlExcept Failiure!!!!!!!");
                    // }
                } catch (Exception ex) {
                    MNQmainFrame.clientPane.appendln(LoggerTool.stackToStr(e));
                }
                XlsUtil.saveResult(opnode, result, null, e, tree, topPara);
            } else {
                MNQmainFrame.clientPane.appendln("Return:", "Output");
                MNQmainFrame.clientPane.appendln(CorbaFacility.toString(r.return_value(), true));

                // if (compareAny(r.return_value(), rt.toAny())) {
                // MNQmainFrame.clientPane
                // .appendln("Return value Successful!!!!!!!");
                // } else {
                // MNQmainFrame.clientPane
                // .appendln("Return value Failure!!!!!!!");
                // }
                for (int j = 0; j < outAll.size(); j++) {
                    Any one = (Any) outAll.get(j);
                    TypeBase two = (TypeBase) allRes.get(j);
                    MNQmainFrame.clientPane.appendln(two.toString(), "Output");
                    MNQmainFrame.clientPane.appendln(CorbaFacility.toString(one, true));
                    // if (compareAny(one, two.toAny())) {
                    // MNQmainFrame.clientPane.appendln(two.toString()
                    // + " Successful!!!!!!!");
                    // } else {
                    // MNQmainFrame.clientPane.appendln(two.toString()
                    // + " Failure!!!!!!!");
                    // }
                }

                MNQmainFrame.clientPane.appendln("");
                XlsUtil.saveResult(opnode, result, r.return_value(), null, tree, topPara);
            }

        } catch (Exception e) {
            LoggerTool.logStackTrace(e, LOG);
        }
    }

    private static boolean compareAny(Any ori, Any ref) {
        if (ori == null && ref == null)
            return true;
        if (ori == null || ref == null)
            return false;
        String s_ori = ori.toString();
        String s_ref = ref.toString();
        if (s_ori.equals("null") && s_ref.equals("null"))
            return true;
        if (s_ori.equals("null") || s_ref.equals("null"))
            return false;

        return ori.equal(ref);
    }

    /**
     * Method: "invokeWithoutCompare"
     * 
     * @param opnode
     * @param allArg
     * @param excep
     * @param allRes
     * @param tree
     * @param topPara
     * @param fok
     *            true -- output will be displayed in Client Output,
     *            otherwise, no display
     * @param iterator ""
     *            no iterator, any other value means iterator is
     *            enabled.
     * @return boolean ture--need to redo this operation again,
     *         false--normal operation
     */
    public static boolean invokeWithoutCompare(IdlOperation opnode, List allArg, List excep,
            List allRes, JTree tree, MNQMutableTreeNode topPara, boolean fok, String iterator) {
        org.omg.CORBA.ORB orb = TypeBase.orb;
        boolean iter = false;

        try {
            if (fok) {
                // prepare in arguments
                MNQmainFrame.clientPane.appendln("Input ( " + opnode.sName + " ) :", "Title");
                String res = "";
                for (int i = 0; i < allArg.size(); i++) {
                    // // ////////
                    TypeBase tmp = ((TypeBase) allArg.get(i));
                    if (tmp.argModes.equalsIgnoreCase("out"))
                        continue;
                    Any a = TypeBase.orb.create_any();
                    tmp.insert(a, tmp.val);
                    res = CorbaFacility.toString(a, true);
                    MNQmainFrame.clientPane.appendln(tmp.toString(), "Input");
                    MNQmainFrame.clientPane.appendln(res);
                    // // ///////////
                }
                MNQmainFrame.clientPane.appendln("----------------");
            }

            String str = opnode.getIor();
            org.omg.CORBA.Object obj = TypeBase.orb.string_to_object(str);
            String op = opnode.sName;
            TypeCode ret = opnode.getReturnType().type();
            boolean oneWay = opnode.oneway;

            // a simple request
            List outAll = new Vector();
            Any tmp;
            // List result include in & inout & out
            List result = new Vector();

            org.omg.CORBA.Request r = obj._request(op);

            if (ret != null) {
                r.set_return_type(ret);
            } else {
                r.set_return_type(orb.get_primitive_tc(org.omg.CORBA.TCKind.tk_void));
            }

            // prepare in arguments
            for (int i = 0; i < allArg.size(); i++) {
                TypeBase arg = (TypeBase) allArg.get(i);
                if (arg.argModes.equalsIgnoreCase("in")) {
                    tmp = r.add_in_arg();
                    arg.insert(tmp, arg.val);
                    result.add(tmp);
                } else if (arg.argModes.equalsIgnoreCase("inout")) {
                    tmp = r.add_inout_arg();
                    arg.insert(tmp, arg.val);
                    outAll.add(tmp);
                    result.add(tmp);
                } else if (arg.argModes.equalsIgnoreCase("out")) {
                    tmp = r.add_out_arg();
                    tmp.type(arg.type());
                    outAll.add(tmp);
                    result.add(tmp);
                } else {
                    // nothing to do
                }
            }

            // prepare exception lists
            org.omg.CORBA.ExceptionList exceptions = r.exceptions();
            for (int i = 0; i < excep.size(); i++) {
                exceptions.add(((CTExcept) excep.get(i)).type());
            }

            if (oneWay) {
                r.send_oneway();
            } else {
                r.invoke();
            }

            Exception e = r.env().exception();
            if (e != null) {
                if (fok) {
                    try {
                        org.omg.CORBA.UnknownUserException ue = (UnknownUserException) e;
                        MNQmainFrame.clientPane.appendln(CorbaFacility.toString(ue.except, true),
                                "Exception");
                    } catch (Exception ex) {
                        MNQmainFrame.clientPane.appendln(LoggerTool.stackToStr(e));
                    }
                }
                XlsUtil.saveResult(opnode, result, null, e, tree, topPara);
            } else {
                if (fok) {
                    MNQmainFrame.clientPane.appendln("Return:", "Output");
                    MNQmainFrame.clientPane
                            .appendln(CorbaFacility.toString(r.return_value(), true));

                    // check whether iterator is used
                    if (!iterator.equalsIgnoreCase("")) {
                        iter = CorbaFacility.toString(r.return_value(), false).equalsIgnoreCase(
                                iterator);
                    }

                    for (int j = 0; j < outAll.size(); j++) {
                        // Any one = (Any) outAll.get(j);
                        TypeBase two = (TypeBase) allRes.get(j);
                        MNQmainFrame.clientPane.appendln(two.toString(), "Output");
                        MNQmainFrame.clientPane.appendln(CorbaFacility.toString(
                                (Any) outAll.get(j), true));
                    }
                    // MNQmainFrame.clientPane.appendln("");
                }
                XlsUtil.saveResult(opnode, result, r.return_value(), null, tree, topPara);
            }
            if (fok) {
                MNQmainFrame.clientPane
                        .appendln("--------------------------------------------------------------------------------------------");
            }
        } catch (Exception e) {
            LoggerTool.logStackTrace(e, LOG);
        }
        return iter;
    }
}
/* EOF */

⌨️ 快捷键说明

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