Archived

This forum has been archived. Please start a new discussion on GitHub.

Java reflection / design issues

Dear ZeroC people,

I'm porting a Java application to the Ice platform.

A crucial component of this application is a property sheet widget: Given an object (java bean), this widget uses the Java reflection API to inspect the getters/setters of that object and represent them in a table with appropriate editors for each type (textfield for strings, checkboxes for booleans, etc).

I understand Ice doesn't support reflection, so my problem is how to implement this property sheet over with ice.

Suppose I have
  • interface Something { public void setName(String s) {}; public String getName() {}; )
  • interface ExtSomething extends Something { public void setExtra(String s) {}; public String getExtra() {}; }
  • a method getSomeObject() : Something

and suppose getSomeObject() is called on the client side and returns an ExtSomething instance.

The client will not be able to reflect the get/setExtra(...) methods until the object is casted into an ExtSomeClass (or so it seems). I could someway auto cast maybe?

Anyway, it seems to me that a property sheet is quite common so i'm probably no the first person facing this problem in the context of Ice.
any suggestions, patterns, etc. more than welcome.

cheers
Jelle :D

Comments

  • For an interface X, the Java mapping generates two base classes, _XOperations and _XOperationsNC (the latter without the trailing Ice.Current parameter). You could reflect on those to figure out what operations are supported by an interface.

    Cheers,

    Michi.
  • bernard
    bernard Jupiter, FL
    Hi Jelle,

    It depends very much if you pass this object by 'value' or just a proxy to your object. It would be clearer to use Slice instead of Java to describe your example.

    If you pass your object by value, the client run-time will use the registered object factory to create a value of the proper type (or the best super-type if there is no exact match).

    If you pass a proxy, there is no type-information in the proxy. To find out the most derived interface/class of the target object, you have to pass this info along with the proxy or make a remote call: ice_id().

    Cheers,
    Bernard