Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Dynamic Cast (one more) and CORBA

Reply
Thread Tools

Dynamic Cast (one more) and CORBA

 
 
Julien Klein
Guest
Posts: n/a
 
      05-04-2004
Hi !

I know this subject has already been discusses several times, but no
one situation seems to correspond to mine, so I decided to start a new
thread about it. I will try to be as clear as possible, yet if need
more information, just tell me..

To begin, just something about CORBA :
- I have a reference on an object (thanks to an IOR) which type is
org.omg.CORBA.Object

- I need to "narrow" this object to get a "real object"

- in the simple case (which is not mine), I just need to do the
following :

(1) pfmalarmService service =
(pfmalarmService)pfmalarmServiceHelper.narrow(obj)

where pfmalarmService is an interface and pfmalarmServiceHelper a
class (which implements no interface)

- my problem is that the name of the interface I need to cast my
object with is given as a string (here pfmalarmService)

- how can I do (is it possible ?), whatever the name X I receive as a
string, to execute the following (X is an interface) :

(2) X service = (X)XHelper.narrow(obj)

- I had a look on reflection in Java, I read a lot of threads about
dynamic casting and I am a bit lost in all these information. Yet, it
seems that there is no way for me to do what I want...

- During compile time, pfmalarm... classes are unknown, they are
generated later from an IDL file, so I can't modify these generated
files.

- all the interfaces I need to use (X interfaces as used above)
extends another interface which is called inService, so I can write :

(3) inService service = (inService)inServiceHelper.narrow(obj)

but after, it is not possible for me to call methods specific to one
particular X interface.

Let's take an example : imagine my interface pfmalarmeService extends
inService interface. In pfmalarmService, I have a method called
count(...) which is not defined in inService interface. So if I
execute (3), it is not possible for me to call count(...) method,
isn't it ?

Does someone have a idea or can someone tell me it is not possible for
me to do what I want ?

Thanks !!

Julien
 
Reply With Quote
 
 
 
 
Mike Schilling
Guest
Posts: n/a
 
      05-06-2004
>
> - in the simple case (which is not mine), I just need to do the
> following :
>
> (1) pfmalarmService service =
> (pfmalarmService)pfmalarmServiceHelper.narrow(obj)
>
> where pfmalarmService is an interface and pfmalarmServiceHelper a
> class (which implements no interface)
>
> - my problem is that the name of the interface I need to cast my
> object with is given as a string (here pfmalarmService)
>
> - how can I do (is it possible ?), whatever the name X I receive as a
> string, to execute the following (X is an interface) :
>
> (2) X service = (X)XHelper.narrow(obj)
>
> - I had a look on reflection in Java, I read a lot of threads about
> dynamic casting and I am a bit lost in all these information. Yet, it
> seems that there is no way for me to do what I want...
>
> - During compile time, pfmalarm... classes are unknown, they are
> generated later from an IDL file, so I can't modify these generated
> files.
>
> - all the interfaces I need to use (X interfaces as used above)
> extends another interface which is called inService, so I can write :
>
> (3) inService service = (inService)inServiceHelper.narrow(obj)
>
> but after, it is not possible for me to call methods specific to one
> particular X interface.
>
> Let's take an example : imagine my interface pfmalarmeService extends
> inService interface. In pfmalarmService, I have a method called
> count(...) which is not defined in inService interface. So if I
> execute (3), it is not possible for me to call count(...) method,
> isn't it ?


The difficulty I always have with dicussions like this is that people say
what they don't know when writing the code, but not what they do know. In
this case, you don't know the type of the object. Do you know the method
name you want to call, or its signature, or what argumetns you want to pass
to it, or its return type? If, hypothetically, you knew everything but the
object type, the method name, and the return type, you could easily do
class.forName() to get the Class object followed by a reflective method call
using java.lang.reflect.Method.invoke(). It's trickier if you don't know
the signature, since you'd somehow have to write code that determines at
runtime how many arguments to pass in

Another option, of course, is to generate classes to make these calls using
the information in the IDL files, and compile them together with the
IDL-generated files..



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Is the result of valid dynamic cast always equal to the result ofcorrespondent static cast? Pavel C++ 7 09-18-2010 11:35 PM
CORBA ORB for Linux and C#.NET CORBA ORB Tomek C++ 1 06-01-2006 03:26 AM
error C2440: 'return' : cannot convert from 'const char *' to 'const unsigned short *' Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast Abhijit Bhadra C++ 2 12-01-2004 04:43 PM
malloc - to cast or not to cast, that is the question... EvilRix C Programming 8 02-14-2004 12:08 PM
to cast or not to cast malloc ? MSG C Programming 38 02-10-2004 03:13 PM



Advertisments