View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.myfaces.view.facelets.compiler;
20  
21  import java.io.IOException;
22  import java.util.ArrayList;
23  import java.util.List;
24  
25  import javax.el.ELException;
26  import javax.faces.FacesException;
27  import javax.faces.component.UIComponent;
28  import javax.faces.view.facelets.FaceletContext;
29  import javax.faces.view.facelets.FaceletException;
30  import javax.faces.view.facelets.FaceletHandler;
31  
32  /**
33   * 
34   * @author Jacob Hookom
35   * @version $Id$
36   */
37  class CompilationUnit
38  {
39  
40      protected final static FaceletHandler LEAF = new FaceletHandler()
41      {
42          public void apply(FaceletContext ctx, UIComponent parent) throws IOException, FacesException, FaceletException,
43                  ELException
44          {
45          }
46  
47          public String toString()
48          {
49              return "FaceletHandler Tail";
50          }
51      };
52  
53      private List<CompilationUnit> children;
54  
55      public CompilationUnit()
56      {
57      }
58  
59      public void addChild(CompilationUnit unit)
60      {
61          if (this.children == null)
62          {
63              this.children = new ArrayList<CompilationUnit>();
64          }
65          this.children.add(unit);
66      }
67  
68      public FaceletHandler createFaceletHandler()
69      {
70          return this.getNextFaceletHandler();
71      }
72  
73      protected final FaceletHandler getNextFaceletHandler()
74      {
75          if (this.children == null || this.children.size() == 0)
76          {
77              return LEAF;
78          }
79          if (this.children.size() == 1)
80          {
81              CompilationUnit u = (CompilationUnit) this.children.get(0);
82              return u.createFaceletHandler();
83          }
84          FaceletHandler[] fh = new FaceletHandler[this.children.size()];
85          for (int i = 0; i < fh.length; i++)
86          {
87              fh[i] = ((CompilationUnit) this.children.get(i)).createFaceletHandler();
88          }
89          return new javax.faces.view.facelets.CompositeFaceletHandler(fh);
90      }
91  
92  }