Home Bug Reports

Java PrxHelper Subclass Issue

kantorhskantorhs Member Harry KantorOrganization: DODProject: Mine Hunting Combat Systems
I have a slice file similar to:

module test {

class Foo {
//
};

class Bar extends Foo {
//
};

class Manager {
void addFoo(Foo* f);
};
};

I am able to call addFoo with either a Foo or Bar but, in the addFoo method, f.getClass() always returns a FooPrxHelper. I looked at the BarPrxHelper.java file and noted that it does not extend FooPrxHelper.

I am running Ice 3.3.1 due to RHEL4 requirement of project. Has this been address is 3.4?

Comments

  • bernardbernard Jupiter, FLAdministrators, ZeroC Staff Bernard NormierOrganization: ZeroC, Inc.Project: Ice ZeroC Staff
    Hi Harry,

    This is the expected behavior. When you pass a proxy as parameter to a remote operation, the only information passed "on the wire" is the identity and addressing information for the target object. Ice does not pass any type information for the target object: the type of the proxy created by Ice on the receiving side comes from the signature of your Slice operation.

    (As an aside, if you pass an object by value as opposed to proxy, type-information is transmitted and the resulting behavior is different).

    If you need a BarPrx in your addFoo operation, you'll need to "downcast" f to a BarPrx with either checkedCast or uncheckedCast. checkedCast or uncheckedCast will manufacture a brand new proxy with the desired type that points to the same object.

    All the best,
    Bernard
  • kantorhskantorhs Member Harry KantorOrganization: DODProject: Mine Hunting Combat Systems
    Is there any way to pass by value without implementing an object factory? I'm trying to avoid downcasting since the subclasses will not be know in advance and I'd prefer to avoid huge amounts of reflection to determine who is subclassing Foo.
  • bernardbernard Jupiter, FLAdministrators, ZeroC Staff Bernard NormierOrganization: ZeroC, Inc.Project: Ice ZeroC Staff
    Hi Harry,

    The semantics of "pass by proxy" and "pass by value" are very different: when you pass an object by value, you copy the entire object, and all calls on this object are local calls on the local copy. So, please consider carefully your application before switching from one to the other.

    Whether or not a factory is needed for objects passed by value depends on the type of these objects: if it has operations, you need your own factory (Ice has no idea how to implement these operations!), otherwise Ice generates and registers a factory automatically.

    Best regards,
    Bernard
Sign In or Register to comment.