GrxCorbaUtil.java
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008, AIST, the University of Tokyo and General Robotix Inc.
3  * All rights reserved. This program is made available under the terms of the
4  * Eclipse Public License v1.0 which accompanies this distribution, and is
5  * available at http://www.eclipse.org/legal/epl-v10.html
6  * Contributors:
7  * General Robotix Inc.
8  * National Institute of Advanced Industrial Science and Technology (AIST)
9  */
10 /*
11  * GrxConfigPane.java
12  *
13  * Copyright (C) 2007 GeneralRobotix, Inc.
14  * All Rights Reserved
15  *
16  * @author Yuichiro Kawasumi (General Robotix, Inc.)
17  * 2004/03/19
18  */
19 
20 package com.generalrobotix.ui.util;
21 
22 import java.util.HashMap;
23 
24 import org.omg.CORBA.*;
25 import org.omg.CORBA.ORBPackage.InvalidName;
26 import org.omg.CosNaming.*;
27 import org.omg.PortableServer.POA;
28 
30 
34 public class GrxCorbaUtil {
35 
36  private static ORB orb_ = null;
37  private static HashMap<String, NamingContext> namingContextList_ = null;
38 
45  public static org.omg.CORBA.ORB getORB(String[] argv) {
46  if (orb_ == null) {
47  java.util.Properties props = null;
48  props = System.getProperties();
49  orb_ = ORB.init(argv, props);
50  }
51  return orb_;
52  }
53 
58  public static org.omg.CORBA.ORB getORB() {
59  return getORB(null);
60  }
61 
66  public static int nsPort() {
68  }
69 
74  public static String nsHost() {
76  }
77 
82  public static NamingContext getNamingContext() {
83  return getNamingContext(nsHost(), nsPort());
84  }
85 
95  public static NamingContext getNamingContext(String nsHost, int nsPort) {
96  getORB();
97  String nameServiceURL = "corbaloc:iiop:" + nsHost + ":" + nsPort + "/NameService";
98  NamingContext ncxt = getNamingContextList().get(nameServiceURL);
99  try {
100  if (ncxt == null) {
101  org.omg.CORBA.Object obj = orb_.string_to_object(nameServiceURL);
102  ncxt = NamingContextHelper.narrow(obj);
103  getNamingContextList().put(nameServiceURL, ncxt);
104  }
105  ncxt._non_existent();
106  } catch (Exception excep) {
107  ncxt = null;
108  getNamingContextList().remove(nameServiceURL);
109  }
110  return ncxt;
111  }
112 
117  private static HashMap<String, NamingContext> getNamingContextList() {
118  if (namingContextList_ == null) {
119  namingContextList_ = new HashMap<String, NamingContext>();
120  }
121  return namingContextList_;
122  }
123 
130  public static org.omg.CORBA.Object getReference(String id) {
131  return getReference(id, nsHost(), nsPort());
132  }
133 
144  public static org.omg.CORBA.Object getReference(String id, String nsHost, int nsPort) {
145  return getReference(id, "", nsHost, nsPort);
146  }
147 
148  public static org.omg.CORBA.Object getReference(String id, String kind, String nsHost, int nsPort){
149  NamingContext namingContext = getNamingContext(nsHost, nsPort);
150  org.omg.CORBA.Object obj = null;
151  try {
152  NameComponent[] nc = new NameComponent[1];
153  nc[0] = new NameComponent(id, kind);
154  obj = namingContext.resolve(nc);
155  } catch (Exception excep) {
156  obj = null;
157  GrxDebugUtil.printErr("getReference:NG(" + id + "," + nsHost + "," + nsPort + ")");
158  }
159  return obj;
160  }
161 
162  public static org.omg.CORBA.Object getReferenceURL(String id, String nsHost, int nsPort) {
163  org.omg.CORBA.Object obj = null;
164  try {
165  obj = getORB().string_to_object("corbaloc:iiop:" + nsHost + ":" + nsPort + "/" + id);
166  } catch (Exception e) {
167  obj = null;
168  GrxDebugUtil.printErr("getReferenceURL:NG" + id + "," + nsHost + "," + nsPort + ")");
169  }
170  return obj;
171  }
172 
173  public static String getIOR(org.omg.CORBA.Object obj) {
174  return getORB().object_to_string(obj);
175  }
176 
177  static String getIOR(String id, String nsHost, int nsPort) {
178  return getIOR(getReference(id, nsHost, nsPort));
179  }
180 
181  public static POA getRootPOA()
182  throws InvalidName {
183  org.omg.CORBA.Object CORBA_obj = getORB().resolve_initial_references("RootPOA");
184  org.omg.PortableServer.POA rootPOA = org.omg.PortableServer.POAHelper.narrow(CORBA_obj);
185  return rootPOA;
186  }
187 
188  public static org.omg.PortableServer.POAManager getRootPOAManager()
189  throws InvalidName {
190  org.omg.PortableServer.POAManager manager = getRootPOA().the_POAManager();
191  return manager;
192  }
193 
194  public static boolean isConnected(org.omg.CORBA.Object obj) {
195  try {
196  obj._non_existent();
197  } catch (Exception ex) {
198  return false;
199  }
200  return true;
201  }
202 
203  public static boolean isConnected(String id, String nsHost, int nsPort) {
204  org.omg.CORBA.Object obj = GrxCorbaUtil.getReference(id, nsHost, nsPort);
205  return isConnected(obj);
206  }
207 
208  public static String[] getObjectNameList() {
210  }
211 
212  public static void removeNameServiceFromList() {
213  StringBuffer nsHost = new StringBuffer("");
214  StringBuffer nsPort = new StringBuffer("");
216  namingContextList_.remove("corbaloc:iiop:" + nsHost + ":" + nsPort + "/NameService");
217  }
218 
219  public static void clearOrb() {
220  orb_ = null;
221  }
222 
223  public static String[] getObjectNameList(String nsHost, int nsPort) {
225  }
226 
227  public static boolean isAliveNameService() {
228  boolean ret = false;
229  try{
230  ORB orb = getORB();
231  String nameServiceURL = "corbaloc:iiop:" + nsHost() + ":" + nsPort() + "/NameService";
232  org.omg.CORBA.Object obj = orb.string_to_object(nameServiceURL);
233  ret = !obj._non_existent();
234  }catch (Exception ex){
235  System.out.println("[GrxCorbaUtil] Name server is not alive!");
236  }
237  return ret;
238  }
239 
240 
241  private static String[] _getObjectNameList(NamingContext cxt) {
242  int a = 100;
243  BindingListHolder bl = new BindingListHolder();
244  BindingIteratorHolder bi = new BindingIteratorHolder();
245  String[] ret = null;
246  try {
247  cxt.list(a, bl, bi);
248  ret = new String[bl.value.length];
249  for (int i = 0; i < bl.value.length; i++) {
250  ret[i] = bl.value[i].binding_name[0].id;
251  }
252  } catch (Exception ex) {
253  ret = null;
254  GrxDebugUtil.printErr("getObjectList:NG", ex);
255  }
256 
257  return ret;
258  }
259 }
com.generalrobotix.ui.util.GrxCorbaUtil.orb_
static ORB orb_
Definition: GrxCorbaUtil.java:36
com.generalrobotix.ui.util.GrxCorbaUtil.getReferenceURL
static org.omg.CORBA.Object getReferenceURL(String id, String nsHost, int nsPort)
Definition: GrxCorbaUtil.java:162
com.generalrobotix.ui.grxui.Activator
Definition: GrxUIonEclipse-project-0.9.8/src/com/generalrobotix/ui/grxui/Activator.java:58
com.generalrobotix.ui.util.GrxDebugUtil.printErr
static void printErr(String s)
Definition: GrxDebugUtil.java:50
i
png_uint_32 i
Definition: png.h:2732
com.generalrobotix.ui.grxui
Definition: GrxUIonEclipse-project-0.9.8/src/com/generalrobotix/ui/grxui/Activator.java:1
com.generalrobotix.ui.util.GrxCorbaUtil.getRootPOA
static POA getRootPOA()
Definition: GrxCorbaUtil.java:181
com.generalrobotix.ui.util.GrxCorbaUtil._getObjectNameList
static String[] _getObjectNameList(NamingContext cxt)
Definition: GrxCorbaUtil.java:241
com.generalrobotix.ui.util.GrxCorbaUtil.nsPort
static int nsPort()
get port number where naming server is listening
Definition: GrxCorbaUtil.java:66
com.generalrobotix.ui.util.GrxCorbaUtil.isConnected
static boolean isConnected(org.omg.CORBA.Object obj)
Definition: GrxCorbaUtil.java:194
com.generalrobotix.ui.util.GrxCorbaUtil.getReference
static org.omg.CORBA.Object getReference(String id)
get CORBA object which is associated with id
Definition: GrxCorbaUtil.java:130
com.generalrobotix.ui.util.GrxServerManager.NAME_SERVER_HOST_
static String NAME_SERVER_HOST_
Definition: GrxServerManager.java:40
com.generalrobotix.ui.grxui.Activator.refNSHostPort
static void refNSHostPort(StringBuffer nsHost, StringBuffer nsPort)
Definition: GrxUIonEclipse-project-0.9.8/src/com/generalrobotix/ui/grxui/Activator.java:332
com.generalrobotix.ui.util.GrxCorbaUtil.isAliveNameService
static boolean isAliveNameService()
Definition: GrxCorbaUtil.java:227
com.generalrobotix.ui.util.GrxCorbaUtil.removeNameServiceFromList
static void removeNameServiceFromList()
Definition: GrxCorbaUtil.java:212
com.generalrobotix.ui.util.GrxCorbaUtil.getIOR
static String getIOR(org.omg.CORBA.Object obj)
Definition: GrxCorbaUtil.java:173
com.generalrobotix.ui.util.GrxCorbaUtil.getORB
static org.omg.CORBA.ORB getORB(String[] argv)
initialize and get ORB
Definition: GrxCorbaUtil.java:45
com.generalrobotix.ui.util.GrxCorbaUtil.clearOrb
static void clearOrb()
Definition: GrxCorbaUtil.java:219
com.generalrobotix.ui.util.GrxServerManager.NAME_SERVER_PORT_
static int NAME_SERVER_PORT_
Definition: GrxServerManager.java:39
com.generalrobotix.ui.util.GrxDebugUtil
Definition: GrxDebugUtil.java:25
com.generalrobotix.ui.util.GrxCorbaUtil.getRootPOAManager
static org.omg.PortableServer.POAManager getRootPOAManager()
Definition: GrxCorbaUtil.java:188
com.generalrobotix.ui.util.GrxCorbaUtil.getReference
static org.omg.CORBA.Object getReference(String id, String kind, String nsHost, int nsPort)
Definition: GrxCorbaUtil.java:148
com.generalrobotix.ui.util.GrxCorbaUtil.getNamingContext
static NamingContext getNamingContext()
get naming context
Definition: GrxCorbaUtil.java:82
com.generalrobotix.ui.util.GrxCorbaUtil.getNamingContext
static NamingContext getNamingContext(String nsHost, int nsPort)
get naming context from name server which is running on the specified hostname and port number
Definition: GrxCorbaUtil.java:95
viewSimTest.obj
obj
Definition: viewSimTest.py:6
com.generalrobotix.ui.util.GrxCorbaUtil.getORB
static org.omg.CORBA.ORB getORB()
initialize and get ORB
Definition: GrxCorbaUtil.java:58
com.generalrobotix
com.generalrobotix.ui.util.GrxServerManager
Definition: GrxServerManager.java:30
hrpPrep.NamingContext
NamingContext
Definition: hrpPrep.py:134
com.generalrobotix.ui.util.GrxCorbaUtil.getObjectNameList
static String[] getObjectNameList(String nsHost, int nsPort)
Definition: GrxCorbaUtil.java:223
com
hrpPrep.NameComponent
NameComponent
Definition: hrpPrep.py:128
test.a
int a
Definition: test.py:1
com.generalrobotix.ui.util.GrxCorbaUtil.getReference
static org.omg.CORBA.Object getReference(String id, String nsHost, int nsPort)
get CORBA object which is associated with id
Definition: GrxCorbaUtil.java:144
com.generalrobotix.ui
com.generalrobotix.ui.util.GrxCorbaUtil.isConnected
static boolean isConnected(String id, String nsHost, int nsPort)
Definition: GrxCorbaUtil.java:203
com.generalrobotix.ui.util.GrxCorbaUtil.namingContextList_
static HashMap< String, NamingContext > namingContextList_
Definition: GrxCorbaUtil.java:37
com.generalrobotix.ui.util.GrxCorbaUtil.getObjectNameList
static String[] getObjectNameList()
Definition: GrxCorbaUtil.java:208
com.generalrobotix.ui.util.GrxCorbaUtil.getNamingContextList
static HashMap< String, NamingContext > getNamingContextList()
get map between naming service location and naming context
Definition: GrxCorbaUtil.java:117
com.generalrobotix.ui.util.GrxCorbaUtil
corba utility functions
Definition: GrxCorbaUtil.java:34
com.generalrobotix.ui.util.GrxCorbaUtil.nsHost
static String nsHost()
get hostname where naming server is running
Definition: GrxCorbaUtil.java:74


openhrp3
Author(s): AIST, General Robotix Inc., Nakamura Lab of Dept. of Mechano Informatics at University of Tokyo
autogenerated on Wed Sep 7 2022 02:51:02