%line | %branch | |||||||||
---|---|---|---|---|---|---|---|---|---|---|
org.apache.commons.jelly.tags.core.UseListTag |
|
|
1 | /* |
|
2 | * Copyright 2002,2004 The Apache Software Foundation. |
|
3 | * |
|
4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
|
5 | * you may not use this file except in compliance with the License. |
|
6 | * You may obtain a copy of the License at |
|
7 | * |
|
8 | * http://www.apache.org/licenses/LICENSE-2.0 |
|
9 | * |
|
10 | * Unless required by applicable law or agreed to in writing, software |
|
11 | * distributed under the License is distributed on an "AS IS" BASIS, |
|
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
13 | * See the License for the specific language governing permissions and |
|
14 | * limitations under the License. |
|
15 | */ |
|
16 | package org.apache.commons.jelly.tags.core; |
|
17 | ||
18 | import java.util.ArrayList; |
|
19 | import java.util.Iterator; |
|
20 | import java.util.List; |
|
21 | import java.util.Map; |
|
22 | ||
23 | import org.apache.commons.jelly.JellyTagException; |
|
24 | import org.apache.commons.jelly.expression.Expression; |
|
25 | import org.apache.commons.jelly.impl.CollectionTag; |
|
26 | ||
27 | /** |
|
28 | * A tag which creates a List implementation and optionally |
|
29 | * adds all of the elements identified by the items attribute. |
|
30 | * The exact implementation of List can be specified via the |
|
31 | * class attribute |
|
32 | * </pre> |
|
33 | * |
|
34 | * @author <a href="mailto:jstrachan@apache.org">James Strachan</a> |
|
35 | * @version $Revision: 155420 $ |
|
36 | */ |
|
37 | public class UseListTag extends UseBeanTag implements CollectionTag { |
|
38 | ||
39 | private Expression items; |
|
40 | ||
41 | 0 | public UseListTag(){ |
42 | 0 | } |
43 | ||
44 | public List getList() { |
|
45 | 0 | return (List) getBean(); |
46 | } |
|
47 | ||
48 | ||
49 | // CollectionTag interface |
|
50 | //------------------------------------------------------------------------- |
|
51 | public void addItem(Object value) { |
|
52 | 0 | getList().add(value); |
53 | 0 | } |
54 | ||
55 | // DynaTag interface |
|
56 | //------------------------------------------------------------------------- |
|
57 | public Class getAttributeType(String name) throws JellyTagException { |
|
58 | 0 | if (name.equals("items")) { |
59 | 0 | return Expression.class; |
60 | } |
|
61 | 0 | return super.getAttributeType(name); |
62 | } |
|
63 | ||
64 | ||
65 | // Implementation methods |
|
66 | //------------------------------------------------------------------------- |
|
67 | ||
68 | protected void setBeanProperties(Object bean, Map attributes) throws JellyTagException { |
|
69 | 0 | items = (Expression) attributes.remove("items"); |
70 | 0 | super.setBeanProperties(bean, attributes); |
71 | 0 | } |
72 | ||
73 | protected void processBean(String var, Object bean) throws JellyTagException { |
|
74 | 0 | super.processBean(var, bean); |
75 | ||
76 | 0 | List list = getList(); |
77 | ||
78 | // if the items variable is specified lets append all the items |
|
79 | 0 | if (items != null) { |
80 | 0 | Iterator iter = items.evaluateAsIterator(context); |
81 | 0 | while (iter.hasNext()) { |
82 | 0 | list.add( iter.next() ); |
83 | 0 | } |
84 | } |
|
85 | 0 | } |
86 | ||
87 | protected Class getDefaultClass() { |
|
88 | 0 | return ArrayList.class; |
89 | } |
|
90 | } |
This report is generated by jcoverage, Maven and Maven JCoverage Plugin. |