KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > facelets > compiler > CompilationUnit


1 /**
2  * Licensed under the Common Development and Distribution License,
3  * you may not use this file except in compliance with the License.
4  * You may obtain a copy of the License at
5  *
6  * http://www.sun.com/cddl/
7  *
8  * Unless required by applicable law or agreed to in writing, software
9  * distributed under the License is distributed on an "AS IS" BASIS,
10  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
11  * implied. See the License for the specific language governing
12  * permissions and limitations under the License.
13  */

14
15 package com.sun.facelets.compiler;
16
17 import java.io.IOException JavaDoc;
18 import java.util.ArrayList JavaDoc;
19 import java.util.List JavaDoc;
20
21 import javax.el.ELException;
22 import javax.faces.FacesException;
23 import javax.faces.component.UIComponent;
24
25 import com.sun.facelets.FaceletContext;
26 import com.sun.facelets.FaceletException;
27 import com.sun.facelets.FaceletHandler;
28 import com.sun.facelets.tag.CompositeFaceletHandler;
29
30 /**
31  *
32  * @author Jacob Hookom
33  * @version $Id: CompilationUnit.java,v 1.6 2005/08/24 04:38:53 jhook Exp $
34  */

35 class CompilationUnit {
36
37     protected final static FaceletHandler LEAF = new FaceletHandler() {
38         public void apply(FaceletContext ctx, UIComponent parent)
39                 throws IOException JavaDoc, FacesException, FaceletException,
40                 ELException {
41         }
42         public String JavaDoc toString() {
43             return "FaceletHandler Tail";
44         }
45     };
46
47     private List JavaDoc children;
48
49     public CompilationUnit() {
50     }
51
52     public void addChild(CompilationUnit unit) {
53         if (this.children == null) {
54             this.children = new ArrayList JavaDoc();
55         }
56         this.children.add(unit);
57     }
58
59     public FaceletHandler createFaceletHandler() {
60         return this.getNextFaceletHandler();
61     }
62
63     protected final FaceletHandler getNextFaceletHandler() {
64         if (this.children == null || this.children.size() == 0) {
65             return LEAF;
66         }
67         if (this.children.size() == 1) {
68             CompilationUnit u = (CompilationUnit) this.children.get(0);
69             return u.createFaceletHandler();
70         }
71         FaceletHandler[] fh = new FaceletHandler[this.children.size()];
72         for (int i = 0; i < fh.length; i++) {
73             fh[i] = ((CompilationUnit) this.children.get(i))
74                     .createFaceletHandler();
75         }
76         return new CompositeFaceletHandler(fh);
77     }
78
79 }
80
Popular Tags