• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Manually updating object references for Holder(T) In/Out Parameters

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What the heck does my title mean

In the only book I could find jax-ws mentioned, "SOA Using Java Web Serices" the author states:

"(Holder<T> for Out and In/Out Parameters) mechanism works, but I think it has dubious value and can even be dangerous. Suppose that you have other objects referencing your PurchaseOrder instance. These object references are not updated as a result of the Web service invocation�only the Holder class instance gets updated. Therefore, these references are now invalid and you will have to manually update them. In my opinion, the Holder concept (along with in/out and out parameters other than a return value) is misguided. You can�t pass an object reference to a Web service, and trying to make it seem as though you are leads to confusing and error-prone code."

What does it mean to "manually update" the object references?
 
Bartender
Posts: 2968
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to JavaRanch "ypomonh ypomonh"

You may have overlooked the JavaRanch Official policy on registered names upon registration. Please adjust your display name to comply with the stated policy. Thank You for your cooperation.
 
Peer Reynders
Bartender
Posts: 2968
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
  • Your PO is a Java object, java objects are addressed via "java object references".
  • To give your Holder object the "PO" you have to pass the PO instance's object reference to the holder via the holder's constructor Holder(aPO) or setter holder.setPO(aPO).
  • A "copy" of aPO is made and sent with the request.
  • The "modified version" of the PO is sent back in the response.
  • The "aPO" object inside the Holder is replaced with the modified version "anotherPO"
  • At this point (after the web service completes) the Holder contains "anotherPO". However the java object reference "aPO" that was used to initialize the holder is still referring to the "old" PO instance.
  • You have to manually update aPO to synchronize it with the modified PO inside the holder, i.e.: aPO = holder.getPO();


  • The holder concept was introduced because WSDL can specify interfaces that return multiple parameters (rather than just one single return value). In Java the you can only return directly a single new object through a return value. To return multiple objects you have to return a collection object (which is still only a single object) or some other "container" object. To return a new object through a parameter, you need a holder object. Java's object reference parameters only allow the modification of existing object instances.
     
    Aliki Vougiouklaki
    Greenhorn
    Posts: 5
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Peer I appreciate the reply

    To become more specific to my implementation:

    1.) I create the holder:
    BigInteger bi = new BigInteger("0", 10);
    Holder<BigInteger> status = new Holder<BigInteger>(bi);

    2.) And then call the service:
    port.existsUser(subsystemID, userNumber, status, errorMessage, userName);


    After that, should I get the value of status like this:
    System.out.println(status.value);

    or is there a more appropriate way like:
    System.out.println(status.getClass());

    The holder concept is a bit misleading to newbies and there is not much sample code around.
     
    Peer Reynders
    Bartender
    Posts: 2968
    6
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Personally I would "discard" the holder as soon as possible.


    Note that Holder does have a no arg constructor (for OUT parameters; javax.xml.ws.Holder<T>).


    In general I would prefer the first option as a you can initialize the reference to a Null Object. However the web service may return "null" anyway - in which case you have to check regardless.
     
    Don't get me started about those stupid light bulbs.
    reply
      Bookmark Topic Watch Topic
    • New Topic