Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/sun/facelets/tag/CompositeTagLibrary.java


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.tag;
16  
17  import java.lang.reflect.Method;
18  
19  import javax.faces.FacesException;
20  
21  import com.sun.facelets.util.ParameterCheck;
22  
23  /**
24   * A TagLibrary that is composed of 1 or more TagLibrary children. Uses the
25   * chain of responsibility pattern to stop searching as soon as one of the
26   * children handles the requested method.
27   * 
28   * @author Jacob Hookom
29   * @version $Id: CompositeTagLibrary.java,v 1.3 2005/08/24 04:38:47 jhook Exp $
30   */
31  public final class CompositeTagLibrary implements TagLibrary {
32  
33      private final TagLibrary[] libraries;
34  
35      public CompositeTagLibrary(TagLibrary[] libraries) {
36          ParameterCheck.notNull("libraries", libraries);
37          this.libraries = libraries;
38      }
39  
40      /*
41       * (non-Javadoc)
42       * 
43       * @see com.sun.facelets.tag.TagLibrary#containsNamespace(java.lang.String)
44       */
45      public boolean containsNamespace(String ns) {
46          for (int i = 0; i < this.libraries.length; i++) {
47              if (this.libraries[i].containsNamespace(ns)) {
48                  return true;
49              }
50          }
51          return false;
52      }
53  
54      /*
55       * (non-Javadoc)
56       * 
57       * @see com.sun.facelets.tag.TagLibrary#containsTagHandler(java.lang.String,
58       *      java.lang.String)
59       */
60      public boolean containsTagHandler(String ns, String localName) {
61          for (int i = 0; i < this.libraries.length; i++) {
62              if (this.libraries[i].containsTagHandler(ns, localName)) {
63                  return true;
64              }
65          }
66          return false;
67      }
68  
69      /*
70       * (non-Javadoc)
71       * 
72       * @see com.sun.facelets.tag.TagLibrary#createTagHandler(java.lang.String,
73       *      java.lang.String, com.sun.facelets.tag.TagConfig)
74       */
75      public TagHandler createTagHandler(String ns, String localName,
76              TagConfig tag) throws FacesException {
77          for (int i = 0; i < this.libraries.length; i++) {
78              if (this.libraries[i].containsTagHandler(ns, localName)) {
79                  return this.libraries[i].createTagHandler(ns, localName, tag);
80              }
81          }
82          return null;
83      }
84  
85      /*
86       * (non-Javadoc)
87       * 
88       * @see com.sun.facelets.tag.TagLibrary#containsFunction(java.lang.String,
89       *      java.lang.String)
90       */
91      public boolean containsFunction(String ns, String name) {
92          for (int i = 0; i < this.libraries.length; i++) {
93              if (this.libraries[i].containsFunction(ns, name)) {
94                  return true;
95              }
96          }
97          return false;
98      }
99  
100     /*
101      * (non-Javadoc)
102      * 
103      * @see com.sun.facelets.tag.TagLibrary#createFunction(java.lang.String,
104      *      java.lang.String)
105      */
106     public Method createFunction(String ns, String name) {
107         for (int i = 0; i < this.libraries.length; i++) {
108             if (this.libraries[i].containsFunction(ns, name)) {
109                 return this.libraries[i].createFunction(ns, name);
110             }
111         }
112         return null;
113     }
114 }