1 package jfun.yan.xml.nuts; 2 3 import jfun.util.Misc; 4 import jfun.yan.Component; 5 import jfun.yan.factory.Factory; 6 7 13 public class FactoryNut extends DelegatingNut { 14 private Class type = null; 15 16 private String toString; 17 18 public String getToString() { 19 return toString; 20 } 21 22 public void setToString(String toString) { 23 this.toString = toString; 24 } 25 26 public Class getType() { 27 return type; 28 } 29 30 33 public void setType(Class type) { 34 if(type!=null&&!type.isInterface()){ 35 raise(Misc.getTypeName(type) + " is not an interface"); 36 } 37 this.type = type; 38 } 39 40 public Component eval(){ 41 checkMandatory("component", getComponent()); 42 final String text = toString==null?getTagLocation().toString():toString; 43 return type==null||Factory.class.equals(type)? 44 getComponent().factory(text): 45 getComponent().factory(type, getComponentClassLoader(), text); 46 } 47 } 48 | Popular Tags |