Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
CompositeTagDecorator |
|
| 2.5;2.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 javax.faces.view.facelets.Tag; | |
22 | import javax.faces.view.facelets.TagDecorator; | |
23 | ||
24 | import org.apache.myfaces.view.facelets.util.ParameterCheck; | |
25 | ||
26 | /** | |
27 | * A TagDecorator that is composed of 1 or more TagDecorator instances. It uses the chain of responsibility pattern to | |
28 | * stop processing if any of the TagDecorators return a value other than null. | |
29 | * | |
30 | * @author Jacob Hookom | |
31 | * @version $Id$ | |
32 | */ | |
33 | public final class CompositeTagDecorator implements TagDecorator | |
34 | { | |
35 | ||
36 | private final TagDecorator[] decorators; | |
37 | ||
38 | public CompositeTagDecorator(TagDecorator[] decorators) | |
39 | 0 | { |
40 | 0 | ParameterCheck.notNull("decorators", decorators); |
41 | 0 | this.decorators = decorators; |
42 | 0 | } |
43 | ||
44 | /** | |
45 | * Uses the chain of responsibility pattern to stop processing if any of the TagDecorators return a value other than | |
46 | * null. | |
47 | * | |
48 | * @see javax.faces.view.facelets.TagDecorator#decorate(javax.faces.view.facelets.Tag) | |
49 | */ | |
50 | public Tag decorate(Tag tag) | |
51 | { | |
52 | 0 | Tag t = null; |
53 | 0 | for (int i = 0; i < this.decorators.length; i++) |
54 | { | |
55 | 0 | t = this.decorators[i].decorate(tag); |
56 | 0 | if (t != null) |
57 | { | |
58 | 0 | return t; |
59 | } | |
60 | } | |
61 | 0 | return tag; |
62 | } | |
63 | ||
64 | } | |
65 |