Package jfun.yan.xml.nuts.optional

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

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="if" class="IfElseNut"/&gt;
* &lt;components&gt;
*   &lt;if cond="true" then="$a" else="$b"&gt;
* &lt;/components&gt;
* </pre>
* Evaluates to the component referenced by "b".
* <p>
* The "else" attribute is optional.
* </p>
* <p>
* @author Ben Yu
* Nov 10, 2005 12:01:47 AM
*/
public class IfElseNut 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(false):alt;
    }
  }
}
TOP

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

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.