1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.apache.tiles.context;
22
23 import org.apache.tiles.Attribute;
24
25 import java.util.ArrayList;
26 import java.util.List;
27
28 /***
29 * An attribute as a <code>List</code>.
30 * This attribute associates a name with a list. The list can be found by the
31 * property name.
32 * Elements in list are retrieved using List methods.
33 * This class is used to read configuration files.
34 *
35 * @version $Rev: 527536 $ $Date: 2007-04-11 17:44:51 +0200 (Wed, 11 Apr 2007) $
36 */
37 public class ListAttribute extends Attribute {
38 /***
39 * List.
40 * We declare a List to avoid cast.
41 * Parent "value" property points to the same list.
42 */
43 private List<Object> list;
44
45 /***
46 * Constructor.
47 */
48 public ListAttribute() {
49 list = new ArrayList<Object>();
50 setValue(list);
51 }
52
53 /***
54 * Constructor.
55 *
56 * @param name Name.
57 * @param value List.
58 */
59 public ListAttribute(String name, List<Object> value) {
60 super(name, value);
61 list = value;
62 }
63
64 /***
65 * Add an element in list.
66 * We use a property to avoid rewriting a new class.
67 *
68 * @param element XmlAttribute to add.
69 */
70 public void add(Attribute element) {
71 list.add(element);
72 }
73
74 /***
75 * Add an element in list.
76 *
77 * @param value Object to add.
78 */
79 public void add(Object value) {
80
81
82
83 if (value instanceof Attribute) {
84 add((Attribute) value);
85 } else {
86 list.add(value);
87 }
88 }
89
90 /***
91 * Add an element in list.
92 *
93 * @param value Object to add.
94 */
95 public void addObject(Object value) {
96 list.add(value);
97 }
98
99 }