73 |
* The prefix for classes that are placed instide the |
* The prefix for classes that are placed instide the |
74 |
* gnu.CORBA namespace. |
* gnu.CORBA namespace. |
75 |
*/ |
*/ |
76 |
public static final String CLASSPATH_PREFIX = "gnu.CORBA"; |
public static final String CLASSPATH_PREFIX = "gnu.CORBA."; |
77 |
|
|
78 |
/** |
/** |
79 |
* Try to instantiate an object with the given IDL name. |
* Try to instantiate an object with the given IDL name. |
266 |
} |
} |
267 |
|
|
268 |
/** |
/** |
269 |
|
* Converts the given IDL name to class name and tries to load the |
270 |
|
* matching class. The OMG prefix (omg.org) is replaced by |
271 |
|
* the java prefix org.omg. No other prefixes are added. |
272 |
|
* |
273 |
|
* @param IDL the idl name. |
274 |
|
* |
275 |
|
* TODO Cache the returned classes, avoiding these string manipulations |
276 |
|
* each time the conversion is required. |
277 |
|
* |
278 |
|
* @return the matching class or null if no such is available. |
279 |
|
*/ |
280 |
|
public static Class Idl2class(String IDL) |
281 |
|
{ |
282 |
|
String s = IDL; |
283 |
|
int a = s.indexOf(':') + 1; |
284 |
|
int b = s.lastIndexOf(':'); |
285 |
|
|
286 |
|
s = IDL.substring(a, b); |
287 |
|
|
288 |
|
if (s.startsWith(OMG_PREFIX)) |
289 |
|
s = JAVA_PREFIX + s.substring(OMG_PREFIX.length()); |
290 |
|
|
291 |
|
String cn = s.replace('/', '.'); |
292 |
|
|
293 |
|
try |
294 |
|
{ |
295 |
|
return Class.forName(cn); |
296 |
|
} |
297 |
|
catch (ClassNotFoundException ex) |
298 |
|
{ |
299 |
|
return null; |
300 |
|
} |
301 |
|
} |
302 |
|
|
303 |
|
/** |
304 |
|
* Converts the given IDL name to class name, tries to load the |
305 |
|
* matching class and create an object instance with parameterless |
306 |
|
* constructor. The OMG prefix (omg.org) is replaced by |
307 |
|
* the java prefix org.omg. No other prefixes are added. |
308 |
|
* |
309 |
|
* @param IDL the idl name. |
310 |
|
* |
311 |
|
* @return instantiated object instance or null if such attempt was not |
312 |
|
* successful. |
313 |
|
*/ |
314 |
|
public static java.lang.Object Idl2Object(String IDL) |
315 |
|
{ |
316 |
|
Class cx = Idl2class(IDL); |
317 |
|
|
318 |
|
try |
319 |
|
{ |
320 |
|
if (cx != null) |
321 |
|
return cx.newInstance(); |
322 |
|
else |
323 |
|
return null; |
324 |
|
} |
325 |
|
catch (Exception ex) |
326 |
|
{ |
327 |
|
return null; |
328 |
|
} |
329 |
|
} |
330 |
|
|
331 |
|
/** |
332 |
* Convert the class name to IDL name. |
* Convert the class name to IDL name. |
333 |
* |
* |
334 |
* @param cn the class name. |
* @param cn the class name. |
335 |
* |
* |
336 |
* @return the idl name. |
* @return the idl name. |
337 |
*/ |
*/ |
338 |
protected static String toIDL(String cn) |
public static String toIDL(String cn) |
339 |
{ |
{ |
340 |
if (cn.startsWith(JAVA_PREFIX)) |
if (cn.startsWith(JAVA_PREFIX)) |
341 |
cn = cn.substring(JAVA_PREFIX.length()); |
cn = OMG_PREFIX + cn.substring(JAVA_PREFIX.length()).replace('.', '/'); |
342 |
|
else if (cn.startsWith(CLASSPATH_PREFIX)) |
343 |
cn = cn.replace('.', '/'); |
cn = |
344 |
|
OMG_PREFIX + cn.substring(CLASSPATH_PREFIX.length()).replace('.', '/'); |
345 |
|
|
346 |
return "IDL:" + OMG_PREFIX + cn + ":1.0"; |
return "IDL:" + cn + ":1.0"; |
347 |
} |
} |
348 |
} |
} |