KickJava   Java API By Example, From Geeks To Geeks.

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


1 package jfun.yan.xml.nuts;
2
3 import jfun.yan.Component;
4 import jfun.yan.xml.NutsUtils;
5 import jfun.yan.xml.nut.ComponentNut;
6
7 /**
8  * Super class for any Nut that supports a tag such that:<br>
9  * An optional <code>component</code> attribute is used to refer
10  * to another component.<br>
11  * An optional sub-element is used to define the component in-place.
12  * <p>
13  * @author Ben Yu
14  * Nov 9, 2005 11:44:54 PM
15  */

16 public abstract class DelegatingNut extends ComponentNut {
17   private Component cc;
18   
19   public Component getComponent() {
20     return cc;
21   }
22   /**
23    * Get the Component object.
24    * Exception is thrown if it has not been set yet.
25    */

26   protected Component getMandatory(){
27     checkMandatory("component", cc);
28     return cc;
29   }
30   public void setComponent(Component cc) {
31     if(cc==null)
32       raise("cannot set component to null");
33     delegateTo(cc);
34   }
35   /*
36   public void set(Component[] subs){
37     checkSingleChild(subs);
38     checkDuplicate("component", cc);
39     delegateTo(subs[0]);
40   }*/

41   public void add(Object JavaDoc sub){
42     checkDuplicate("component", this.cc);
43     delegateTo(NutsUtils.asComponent(sub));
44   }
45   /**
46    * Subclass override this method to wrap around the delegate target.
47    * @param cc the delegate target.
48    */

49   protected void delegateTo(Component cc){
50     this.cc = cc;
51   }
52 }
53
Popular Tags