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("");
215  Activator.refNSHostPort(nsHost, nsPort);
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) {
224  return _getObjectNameList(getNamingContext(nsHost, 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 }
static org.omg.CORBA.ORB getORB()
initialize and get ORB
static org.omg.CORBA.Object getReference(String id, String kind, String nsHost, int nsPort)
static String[] _getObjectNameList(NamingContext cxt)
static org.omg.PortableServer.POAManager getRootPOAManager()
static org.omg.CORBA.Object getReferenceURL(String id, String nsHost, int nsPort)
#define null
our own NULL pointer
Definition: IceTypes.h:57
RTC::ReturnCode_t ret(RTC::Local::ReturnCode_t r)
manager
static NamingContext getNamingContext(String nsHost, int nsPort)
get naming context from name server which is running on the specified hostname and port number ...
png_uint_32 i
Definition: png.h:2735
static String nsHost()
get hostname where naming server is running
static org.omg.CORBA.ORB getORB(String[] argv)
initialize and get ORB
static org.omg.CORBA.Object getReference(String id, String nsHost, int nsPort)
get CORBA object which is associated with id
string a
static boolean isConnected(String id, String nsHost, int nsPort)
static org.omg.CORBA.Object getReference(String id)
get CORBA object which is associated with id
static int nsPort()
get port number where naming server is listening
static boolean isConnected(org.omg.CORBA.Object obj)
static HashMap< String, NamingContext > getNamingContextList()
get map between naming service location and naming context
static String[] getObjectNameList(String nsHost, int nsPort)
org
static HashMap< String, NamingContext > namingContextList_
static String getIOR(org.omg.CORBA.Object obj)
static NamingContext getNamingContext()
get naming context
NamingContext
Definition: hrpPrep.py:134
NameComponent
Definition: hrpPrep.py:128


openhrp3
Author(s): AIST, General Robotix Inc., Nakamura Lab of Dept. of Mechano Informatics at University of Tokyo
autogenerated on Sat May 8 2021 02:42:38