corbasupport.java

来自「openmap java写的开源数字地图程序. 用applet实现,可以像g」· Java 代码 · 共 464 行 · 第 1/2 页

JAVA
464
字号
    public org.omg.CORBA.Object resolveName(String naming) {        if (naming != null) {            try {                ORB orb = initORB(null);                if (Debug.debugging("corbadetail")) {                    listServices(orb);                }                // Get the root context of the name service.                org.omg.CORBA.Object obj = null;                try {                    obj = orb.resolve_initial_references("NameService");                } catch (Exception e) {                    Debug.error("CORBASupport.resolveName(): Error getting root naming context.");                    e.printStackTrace();                }                NamingContext rootContext = NamingContextHelper.narrow(obj);                if (Debug.debugging("corba")) {                    if (rootContext == null) {                        Debug.error("CORBASupport.resolveName(): No root context!");                    }                }                // Resolve the specialist                String temp = naming;                Vector components = new Vector();                int numcomponents = 0;                String temporaryTemp = null;                int tindex = temp.indexOf("/");                while (tindex != -1) {                    numcomponents++;                    temporaryTemp = temp.substring(0, tindex);                    if (Debug.debugging("corba")) {                        Debug.output("CORBASupport.resolveName(): Adding Name component: "                                + temporaryTemp);                    }                    components.addElement(temporaryTemp);                    temp = temp.substring(tindex + 1);                    tindex = temp.indexOf("/");                }                if (Debug.debugging("corba")) {                    Debug.output("CORBASupport.resolveName(): Adding final Name component: "                            + temp);                }                components.addElement(temp);                NameComponent[] objectName = new NameComponent[components.size()];                for (int i = 0; i < components.size(); i++) {                    objectName[i] = new NameComponent((String) (components.elementAt(i)), "");                }                obj = null; // reset                try {                    if (rootContext != null) {                        obj = rootContext.resolve(objectName);                    } else {                        Debug.output("CORBASupport.resolveName(): No Root Context for naming.");                    }                } catch (Exception e) {                    Debug.output("CORBASupport.resolveName(): Error resolving for the object.");                    e.printStackTrace();                }                if (obj == null) {                    if (Debug.debugging("corba")) {                        Debug.output("CORBASupport.resolveName(): no object after resolve");                    }                } else {                    if (Debug.debugging("corba")) {                        Debug.output("CORBASupport.resolveName(): "                                + orb.object_to_string(obj));                    }                }                return obj;            } catch (org.omg.CORBA.SystemException e) {                Debug.error("CORBASupport.resolveName(): " + e);            } catch (Throwable t) {                Debug.output("CORBASupport.resolveName(): " + t);            }        }        return null;    }    protected void listServices(ORB orb) {        String[] services = orb.list_initial_services();        if (services != null) {            Debug.output("CORBASupport: Listing services:");            for (int k = 0; k < services.length; k++) {                Debug.output("  service " + k + ": " + services[k]);            }        } else {            Debug.output("CORBASupport: no services available");        }    }    /**     * This is a default start method that initializes the server     * represented by a Servant. This is a POA method. The args should     * be command line arguments, and the ior file is written and     * naming service is started from here.     *      * @param servant the Servant of the POA object to hook up to the     *        ORB.     * @param args a String[] of args to pass to orb on     *        initialization.     * @param iorFile the path of the ior file to write, can be null     *        to not write a file.     * @param naming the name of the Servant to pass to the     *        NamingService, can be null to not register a name.     */    public void start(Servant servant, String[] args, String iorFile,                      String naming) {        start(servant, args, iorFile, naming, true);    }    /**     * This is a default start method that initializes the server     * represented by a Servant. This is a POA method. The args should     * be command line arguments, and the ior file is written and     * naming service is started from here.     *      * @param servant the Servant of the POA object to hook up to the     *        ORB.     * @param args a String[] of args to pass to orb on     *        initialization.     * @param iorFile the path of the ior file to write, can be null     *        to not write a file.     * @param naming the name of the Servant to pass to the     *        NamingService, can be null to not register a name.     * @param runORB flag to call orb.run() at the end of the method.     *        This will block the current thread! If the servant is a     *        server, then this should be true. If you have a callback     *        object that you just want to register with the orb, this     *        should be false.     */    public void start(Servant servant, String[] args, String iorFile,                      String naming, boolean runORB) {        // Initialize the ORB        ORB orb = initORB(args);        POA poa = null;        if (Debug.debugging("corbadetail")) {            listServices(orb);        }        // find root poa        try {            org.omg.CORBA.Object raw = orb.resolve_initial_references("RootPOA");            poa = POAHelper.narrow(raw);            poa.the_POAManager().activate();        } catch (Exception error) {            Debug.error("Error getting root POA: " + error);            error.printStackTrace();        }        try {            poa.activate_object(servant);        } catch (Exception e) {            Debug.error("Caught exception activating POA object: \n"                    + e.getMessage());        }        // write the IOR out        try {            writeIOR(iorFile, servant._this_object());        } catch (IOException ioe) {            Debug.error("CORBASupport caught IOException writing IOR file to "                    + iorFile);        }        // Set up naming service        setUpNamingService(naming, servant._this_object());        // Announce ourselves to the world        Debug.output(servant.toString() + " is ready.");        if (runORB) {            orb.run();        }    }    /**     * This is a default start method that initializes a CORBA server     * This is a BOA method, and the main BOA method calls are     * commented out because the BOA isn't available in the jdk by     * default. If you are using a CORBA installation with a BOA     * implementation, uncomment the lines below and recompile. The     * args should be command line arguments, and the ior file is     * written and naming service is started from here.     */    public void start(ObjectImpl obj, String[] args, String iorFile,                      String naming) {        ORB orb = initORB(args);        // Initialize the BOA        //      org.omg.CORBA.BOA boa = orb.BOA_init();        //      // Export the newly created object        //      boa.obj_is_ready(obj);        if (Debug.debugging("corbadetail")) {            listServices(orb);        }        // write the IOR        try {            writeIOR(iorFile, obj);        } catch (IOException ioe) {            Debug.error("CORBASupport caught IOException writing IOR file to "                    + iorFile);        }        // Set up naming service        setUpNamingService(naming, obj);        // Announce ourselves to the world        Debug.output(obj.toString() + " is ready.");        //      // Wait for incoming requests        //      boa.impl_is_ready();    }}

⌨️ 快捷键说明

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