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