Results 1 to 4 of 4

Thread: Java PrxHelper Subclass Issue

  1. #1
    kantorhs is offline Registered User
    Name: Harry Kantor
    Organization: DOD
    Project: Mine Hunting Combat Systems
    Join Date
    Apr 2009
    Posts
    14

    Java PrxHelper Subclass Issue

    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?

  2. #2
    bernard's Avatar
    bernard is offline ZeroC Staff
    Name: Bernard Normier
    Organization: ZeroC, Inc.
    Project: Ice
    Join Date
    Feb 2003
    Location
    Palm Beach Gardens, FL
    Posts
    1,294
    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
    Bernard Normier
    ZeroC, Inc.

  3. #3
    kantorhs is offline Registered User
    Name: Harry Kantor
    Organization: DOD
    Project: Mine Hunting Combat Systems
    Join Date
    Apr 2009
    Posts
    14
    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.

  4. #4
    bernard's Avatar
    bernard is offline ZeroC Staff
    Name: Bernard Normier
    Organization: ZeroC, Inc.
    Project: Ice
    Join Date
    Feb 2003
    Location
    Palm Beach Gardens, FL
    Posts
    1,294
    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
    Bernard Normier
    ZeroC, Inc.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Is the ICE for Java based on Java NIO?
    By Jiangyubao in forum Comments
    Replies: 1
    Last Post: 03-30-2008, 06:04 PM
  2. java:type:java.util.Vector
    By jesse in forum Help Center
    Replies: 1
    Last Post: 04-23-2007, 12:49 PM
  3. Replies: 2
    Last Post: 11-24-2006, 03:03 AM
  4. Replies: 0
    Last Post: 02-13-2006, 05:06 PM
  5. Blobject subclass examples?
    By bartley in forum Help Center
    Replies: 3
    Last Post: 02-08-2006, 09:57 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •