KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > oddjob > designer > model > ComponentElement


1 /*
2  * (c) Rob Gordon 2005.
3  */

4 package org.oddjob.designer.model;
5
6 import org.oddjob.designer.arooa.ElementWrapper;
7
8 /**
9  * Used for creating a component element. That is a component that
10  * is nested in an element. e.g. if where component is nested in child, then
11  * else, exception tags.
12  * <p>
13  * static factory methods are used which allow the component element to be
14  * empty.
15  *
16  */

17 public class ComponentElement {
18
19     private final ElementWrapper[] elements;
20     
21     private ComponentElement(DesignComponent dc) {
22         elements = new ElementWrapper[] {
23                 new ElementWrapper(dc.tag(), dc) };
24     }
25     
26     private ComponentElement(Object JavaDoc[] dcs) {
27         elements = new ElementWrapper[dcs.length];
28         for (int i = 0; i < dcs.length; ++i ) {
29             elements[i] = new ElementWrapper(((DesignComponent)dcs[i]).tag(), dcs[i]);
30         }
31     }
32
33     /**
34      * Used by reflection to produce the XML.
35      *
36      * @return The component object wrappped as elements.
37      */

38     public ElementWrapper[] elements() {
39         return elements;
40     }
41     
42     public static ComponentElement createNested(DesignComponent dc) {
43         if (dc == null) {
44             return null;
45         }
46         return new ComponentElement(dc);
47     }
48     
49     public static ComponentElement createNested(Object JavaDoc[] dcs) {
50         if (dcs == null) {
51             return null;
52         }
53         if (dcs.length == 0) {
54             return null;
55         }
56         return new ComponentElement(dcs);
57     }
58     
59 }
60
Popular Tags