corbasupport.java
来自「openmap java写的开源数字地图程序. 用applet实现,可以像g」· Java 代码 · 共 464 行 · 第 1/2 页
JAVA
464 行
// **********************************************************************// // <copyright>// // BBN Technologies// 10 Moulton Street// Cambridge, MA 02138// (617) 873-8000// // Copyright (C) BBNT Solutions LLC. All rights reserved.// // </copyright>// **********************************************************************// // $Source: /cvs/distapps/openmap/src/corba/com/bbn/openmap/util/corba/CORBASupport.java,v $// $RCSfile: CORBASupport.java,v $// $Revision: 1.3.2.1 $// $Date: 2004/10/14 18:26:34 $// $Author: dietrick $// // **********************************************************************package com.bbn.openmap.util.corba;import com.bbn.openmap.Environment;import com.bbn.openmap.util.Debug;import java.io.*;import java.net.URL;import java.net.URLConnection;import java.util.Vector;import org.omg.CORBA.*;import org.omg.CORBA.portable.ObjectImpl;import org.omg.CosNaming.*;import org.omg.PortableServer.POA;import org.omg.PortableServer.POAHelper;import org.omg.PortableServer.Servant;/** * CORBASupport provides common functions for OpenMap servers. */public class CORBASupport { /** * Return a static reference to the ORB. Figures out which * environment (applet or application) the jre is in, and * initialize the orb accordingly. */ public ORB initORB(String[] args) { Debug.message("corba", "CORBAManager.getORB(): initializing ORB"); if (Environment.isApplet()) { // initialize the Environment with the properties passed // in. if (Debug.debugging("corba")) { System.out.println("CORBAManager: initializing applet"); } return ORB.init(Environment.getApplet(), Environment.getProperties()); } if (Debug.debugging("corba")) { System.out.println("CORBAManager: initializing application"); } return ORB.init((String[]) null, System.getProperties()); } /** * Read a IOR file from an URL, return the org.omg.CORBA.Object * for that IOR. */ public org.omg.CORBA.Object readIOR(URL iorURL) throws IOException { org.omg.CORBA.Object object = null; if (iorURL != null) { URLConnection urlConnection = iorURL.openConnection(); InputStream is = urlConnection.getInputStream(); InputStreamReader isr = new InputStreamReader(is); BufferedReader reader = new BufferedReader(isr); String ior = reader.readLine(); if (Debug.debugging("corba")) { Debug.output("CORBASupport.readIOR() using ior: " + ior); } reader.close(); if (ior != null) { object = initORB(null).string_to_object(ior); } } return object; } /** * Write the IOR for a object to a file. * * @param iorFile where to write the file * @param iorObj the object to represent in the IOR file. */ public void writeIOR(String iorFile, org.omg.CORBA.Object iorObj) throws IOException { if (iorFile != null) { ORB orb = initORB(null); java.io.FileWriter outFile = new java.io.FileWriter(iorFile); java.io.PrintWriter writer = new java.io.PrintWriter(outFile); String ior = orb.object_to_string(iorObj); writer.println(ior); writer.close(); if (Debug.debugging("corba")) { Debug.output(orb.object_to_string(iorObj)); } } } /** * Set up the CORBA NamingService with the name for an object. */ public void setUpNamingService(String naming, org.omg.CORBA.Object namingObj) { ORB orb = initORB(null); if (naming != null) { //*** Naming server stuff org.omg.CORBA.Object obj = null; try { obj = orb.resolve_initial_references("NameService"); if (Debug.debugging("corba")) { Debug.output("CORBASupport.setUpNamingService(): NameService Object OK"); } } catch (org.omg.CORBA.ORBPackage.InvalidName e) { Debug.error("CORBASupport.setUpNamingService(): Invalid Name exception \n" + e.getMessage()); } NamingContext rootContext = NamingContextHelper.narrow(obj); if (rootContext == null) { if (Debug.debugging("corba")) { Debug.output("CORBASupport.setUpNamingService(): Root context null!!"); } } 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.setUpNamingService(): Adding Name component: " + temporaryTemp); } components.addElement(temporaryTemp); temp = temp.substring(tindex + 1); tindex = temp.indexOf("/"); } if (Debug.debugging("corba")) { Debug.output("CORBASupport.setUpNamingService(): Adding final Name component: " + temp); } components.addElement(temp); NamingContext newContext = null; NamingContext oldContext = rootContext; for (int i = 0; i < components.size() - 1; i++) { NameComponent[] newName = new NameComponent[1]; newName[0] = new NameComponent((String) (components.elementAt(i)), ""); String debugName = (String) (components.elementAt(i)); if (Debug.debugging("corba")) { Debug.output("CORBASupport.setUpNamingService(): Working on: " + debugName); } try { newContext = NamingContextHelper.narrow(oldContext.resolve(newName)); } catch (org.omg.CosNaming.NamingContextPackage.NotFound nfe) { try { if (Debug.debugging("corba")) { Debug.output("CORBASupport.setUpNamingService(): Doing a bind new context"); } newContext = oldContext.bind_new_context(newName); } catch (org.omg.CosNaming.NamingContextPackage.AlreadyBound abe) { Debug.output("CORBASupport.setUpNamingService(): Already bound for new context"); } catch (org.omg.CosNaming.NamingContextPackage.CannotProceed cpe0) { Debug.output("CORBASupport.setUpNamingService(): Cannot proceed for new context"); } catch (org.omg.CosNaming.NamingContextPackage.InvalidName ine0) { Debug.output("CORBASupport.setUpNamingService(): Invalid Name for new context"); } catch (org.omg.CosNaming.NamingContextPackage.NotFound nfe0) { Debug.output("CORBASupport.setUpNamingService(): Not found for new context"); } } catch (org.omg.CosNaming.NamingContextPackage.InvalidName ine) { Debug.output("CORBASupport.setUpNamingService(): Invalid name"); } catch (org.omg.CosNaming.NamingContextPackage.CannotProceed cpe) { Debug.output("CORBASupport.setUpNamingService(): Cannot proceed"); } oldContext = newContext; } NameComponent[] finalName = new NameComponent[1]; finalName[0] = new NameComponent((String) (components.elementAt(components.size() - 1)), ""); String debugName = (String) (components.elementAt(components.size() - 1)); if (Debug.debugging("corba")) { Debug.output("CORBASupport.setUpNamingService: Finally working on: " + debugName); } try { if (Debug.debugging("corba")) { Debug.output("CORBASupport.setUpNamingService(): Doing a rebind :" + orb.object_to_string(oldContext)); } oldContext.rebind(finalName, namingObj); if (Debug.debugging("corba")) { Debug.output("CORBASupport.setUpNamingService(): Completed rebind for " + finalName); } } catch (org.omg.CosNaming.NamingContextPackage.CannotProceed cpe1) { Debug.output("CORBASupport.setUpNamingService(): Cannot proceed in rebind"); } catch (org.omg.CosNaming.NamingContextPackage.InvalidName ine1) { Debug.output("CORBASupport.setUpNamingService(): Invalid Name in rebind"); } catch (org.omg.CosNaming.NamingContextPackage.NotFound nfe1) { Debug.output("CORBASupport.setUpNamingService(): Not found in rebind"); } } }
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?