Package jfun.yan.xml.nuts

Source Code of jfun.yan.xml.nuts.GetterNut

package jfun.yan.xml.nuts;

import java.beans.IntrospectionException;

import jfun.yan.Component;
import jfun.yan.xml.NutsUtils;
/**
* Nut class for <getter> tag.
* This Nut supports multi-level getters such that "a.b.c" corresponds to
* getA().getB().isC().
* <p>
* @author Ben Yu
* Nov 9, 2005 11:42:15 PM
*/
public class GetterNut extends DelegatingNut {
  private String name;
  private int ind = -1;
 
  public int getInd() {
    return ind;
  }
  public void setInd(int ind) {
    if(ind < 0)
      raise("invalid property index "+ind);
    this.ind = ind;
  }
  public String getName() {
    return name;
  }
  public void setName(String name) {
    this.name = name.trim();
  }
  private static Component getGetter1(Component c, String name, int ind)
  throws IntrospectionException{
    if(ind < 0)
      return c.getter(name.trim());
    else
      return c.getter(name.trim(), ind)
  }
  private static Component getGetterComponent(Component c, String name, int ind)
  throws IntrospectionException{
    if(name.indexOf('.')<0) return getGetter1(c, name, ind);
    final String[] parts = NutsUtils.split(name, ".");
    for(int i=0; i<parts.length-1; i++){
      c = c.getter(parts[i].trim());
    }
    final String last = parts[parts.length-1];
    return getGetter1(c, last, ind);
  }
  public Component eval()
  throws IntrospectionException{
    final Component component = getComponent();
    checkMandatory("component", component);
    checkMandatory("name", name);
    return getGetterComponent(component, name, ind);
  }

}
TOP

Related Classes of jfun.yan.xml.nuts.GetterNut

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.