Print
Real Advanced Tags

binder

<binder> tag evaluates to a Binder object.

It mandatorily requires a "var" attribute, which is used as the formal parameter variable in the Binder.bind() method.

Other than that difference, binder tag has the same rule as sequence. They both allow a list of sub-elements that evaluate to Component, they both enforce sequencing. An example would be:

<local>
  ...
  <binder id="bean_setter" var="c">
    <bean component="$c" autowire="bytype"/>
  </binder>
  ...
</local>

bind

<bind> tag binds a component and a binder together. For example, we can use the binder we just declared to set properties to an object created by a method:

<method id="acct_before_properties_set" class="BankAccount"
      name="create" autowire="bytype"/>
<bind id="acct_after_properties_set" component="$acct_before_properties_set"
      binder="$bean_setter"/>

This has exactly the same effect as:

<method id="acct_before_properties_set" class="BankAccount"
      name="create" autowire="bytype"/>
<bean id="acct_after_properties_set" component="$acct_before_properties_set"
      autowire="bytype"/>

Except that the first example encapsulates part of the dependency injection logic into the binder tag.

callcc

Starting from version 0.7.3, Nuts supports a <callcc> tag that stands for "call-with-current-continuation". "call-with-current-continuation" is a very useful feature that can be found in programming languages such as Scheme and Ruby. I will not cover the details of it here. Please see Scheme callcc and Ruby callcc.

In Nuts, callcc can be used to exit a sequential component combination from the middle. For example:

<callcc exit="return">
  ...
  <call function="$return" args="10"/>
  <!--
    value 10 is returned and components from the point on until
    the end of the callcc tag are ignored.
  -->
  ...
</callcc>

<callcc> tag supports an "exit" attribute that is used to specify the name of the exit function. When this function is called anywhere within the scope of <callcc>, the sequential execution is aborted and the function argument is taken as the value of the <callcc> tag.

It should be noted that Nuts' <callcc> is an "escape-only" continuation. Java exception is used to implement the continuation. Therefore, the performance cost of an exception will be paid when <callcc> is used.

Powered by Atlassian Confluence