Package jfun.yan.xml.nuts.optional

Source Code of jfun.yan.xml.nuts.optional.UnlessNut

package jfun.yan.xml.nuts.optional;

import jfun.yan.Component;
import jfun.yan.Components;
/**
* Nut class for conditional statement. For example:
* <pre>
* &lt;nut name="unless" class="UnlessNut"/&gt;
* &lt;components&gt;
*   &lt;unless cond="true" then="$a" else="$b"&gt;
* &lt;/components&gt;
* </pre>
* Evaluates to the component referenced by "a".
* <p>
* The "else" attribute is optional.
* </p>
* <p>
* @author Ben Yu
* Nov 10, 2005 12:01:47 AM
*/
public class UnlessNut extends ConditionalNut {
  public Component eval(){
    final boolean c = isCond();
    final Component then = getThen();
    checkMandatory("then", then);
    if(!c)
      return then;
    else{
      final Component alt = getElse();
      return alt==null?Components.value(true):alt;
    }
  }

}
TOP

Related Classes of jfun.yan.xml.nuts.optional.UnlessNut

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.