10

Can someone please explain this code?

public void getSupplierByZipCode(
    @WebParam(name = "zip", targetNamespace = "http://www.webservicex.net/")
    String zip,
    @WebParam(name = "GetSupplierByZipCodeResult", targetNamespace =  "http://www.webservicex.net/", mode = WebParam.Mode.OUT)
    Holder<Boolean> getSupplierByZipCodeResult,
    @WebParam(name = "SupplierDataLists", targetNamespace = "http://www.webservicex.net/", mode = WebParam.Mode.OUT)
    Holder<SupplierDataList> supplierDataLists);

I've never seen Holder before in Java. What are Holder<Boolean> and Holder<SupplierDataList> in the function? Are they like outputs?? I need the supplier data list from this function.

J0e3gan
  • 8,740
  • 10
  • 53
  • 80
Cim Took
  • 153
  • 1
  • 2
  • 9

1 Answers1

16

See Holder - The entire purpose is to "hold a value" while allowing side-effect modifications of itself (and thus change value it "holds").

The instance variable (value) representing the contained/"held" value can be reassigned; this is used to facilitate how [multiple] values are "returned" in the WS - through explicit modification of the holders supplied as parameters. (Note the usage of WebParam.Mode.OUT as well.)

This "extra layer" is required because Java is always Call By Value; the Holder then effectively fakes a pointer-indirection (let's call it "reference-indirection"), as what might be done in C, which leads to Call By (Object) Sharing semantics.

Imagine:

// Outside WS function - setup parameters and invoke
String zip = "98682";
Holder<Boolean> result = new Holder<Boolean>();
getSupplierByZipCode(zip, result, ..);

// Then inside the function the Holder is modified and a new value
// is assigned to it's value member.
getSupplierByZipCodeResult.value = true;

// And outside again, the mutations are visibile still
if (result.value) {
    // Yay!
}

Since strings are immutable and the zip is not wrapped in a Holder then the zip code cannot be changed (or "returned" by) the WS call.

See also:

user2864740
  • 60,010
  • 15
  • 145
  • 220
  • But if i want to get supplierdatalists, how do i access it??what should i pass as arguments for functions? – Cim Took Sep 11 '14 at 02:27
  • 1
    @SparshithP Same way; follow the template given in the usage of the `result` variable. Supply a `Holder` (since it is only an OUT parameter, no initial holder value must be supplied) which can be modified to "return" a value in the WS method. Then use the `value` after the call. – user2864740 Sep 11 '14 at 02:31