How can I return a java.lang.Object value to client on CORBA in my case?

995 views Asked by At

I am developing a Corba application. My IDL interface look like this:

interface Transaction {
    ???????? addResource(in TransactionResource resource);
}; 

I would like when a client invoke addResource method for the Transaction reference object, that can be able to return a returned value of Proxy.newProxyInstance(....) to client.

Exemple of the addResource implementation:

public ?????? addResource(TransactionResource resource) {
        // creation of a proxy. 
            java.lang.Object o = Proxy.newProxyInstance(ManageDemand.class.getClassLoader() , new Class[] {ManageDemand.class}, new MyInvocationHandler());

        return o;
    }

I would like to return the "o" to client, how can I do that?

What is the type of the returned value of addResource() method ? is it org.omg.CORBA.Object? or other type ?

2

There are 2 answers

4
Adrian Shum On BEST ANSWER

I don't think you can do it with normal way.

from my understanding, the idea of CORBA is, it kind of define its internal message representation which is platform neutral (hence its cross platform interoperability). Just think, if it allow you to give an arbitrary Java Object, if the receive side is C++, then how can it suppose to convert it to the C++ representation?

In brief, you can simply use the structures you defined in IDL, and if you really want to return arbitrary object, CORBA is probably not what you want. Consider things like RMI.

If you really really need to do it, I believe the only way you can do is to do the serialization/deserialization by yourself, and return the "object" as an octet sequence or string. However, you need to be aware that the object receiver got is still a separate instance of object (and hence the proxies around it). If the works of those proxies need resources of the server side, then I believe you need to rethink your design. I don't think there is any solution that can magically link up the remote object with the server side object in such way.

9
Ashish On

You should return type of java.lang.Object and then at the client side you should be casting it back.