KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jfun > yan > xml > nuts > FactoryNut


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 /**
8  * Nut class for <factory> tag.
9  * <p>
10  * @author Ben Yu
11  * Nov 9, 2005 11:42:03 PM
12  */

13 public class FactoryNut extends DelegatingNut {
14   private Class JavaDoc type = null;
15
16   private String JavaDoc toString;
17   
18   public String JavaDoc getToString() {
19     return toString;
20   }
21
22   public void setToString(String JavaDoc toString) {
23     this.toString = toString;
24   }
25
26   public Class JavaDoc getType() {
27     return type;
28   }
29
30   /**
31    * Set the factory interface. The default value is {@link jfun.yan.factory.Factory}
32    */

33   public void setType(Class JavaDoc 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 JavaDoc 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