KickJava   Java API By Example, From Geeks To Geeks.

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


1 package jfun.yan.xml.nuts;
2
3
4 import jfun.yan.Component;
5 import jfun.yan.xml.nut.ComponentNut;
6
7 /**
8  * Any Nut that instantiates linear collection
9  * such as java.util.Collection, array or any other non-standard linear
10  * collection.
11  * <p>
12  * @author Ben Yu
13  * Nov 30, 2005 10:41:45 PM
14  */

15 public abstract class CollectionNut extends ComponentNut {
16   private Class JavaDoc elem_type;
17   private Class JavaDoc type;
18   private Component[] elements;
19   public void setType(Class JavaDoc type){
20     this.type = type;
21   }
22   public Class JavaDoc getType(){
23     return type;
24   }
25   /**
26    * get the type attribute.
27    * @param deftype The default type if the type is not set.
28    * @return the type.
29    */

30   public Class JavaDoc getType(Class JavaDoc deftype){
31     return type==null?deftype:type;
32   }
33   public void setOf(Class JavaDoc etype){
34     this.elem_type = etype;
35   }
36   public Class JavaDoc getOf(){
37     return elem_type;
38   }
39   public void setElements(Component[] ccs){
40     this.elements = ccs;
41   }
42   public void set(Component[] ccs){
43     checkDuplicate("elements", elements);
44     this.elements = ccs;
45   }
46   /**
47    * Get the mandatory elements. Conversion is done if necessary.
48    */

49   public Component[] getMandatoryElements(){
50     checkMandatory("elements", elements);
51     if(elem_type==null)
52       return elements;
53     else
54       return Util.convert(this, elem_type, elements);
55   }
56   public Component[] getElements(){
57     return elements;
58   }
59 }
60
Popular Tags