Source code: org/apache/struts/tiles/xmlDefinition/XmlListAttribute.java
1 /*
2 * $Id: XmlListAttribute.java 54929 2004-10-16 16:38:42Z germuska $
3 *
4 * Copyright 1999-2004 The Apache Software Foundation.
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * 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, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18
19
20 package org.apache.struts.tiles.xmlDefinition;
21
22 import java.util.ArrayList;
23 import java.util.List;
24
25
26 /**
27 * An attribute as a <code>List</code>.
28 * This attribute associates a name with a list. The list can be found by the
29 * property name.
30 * Elements in list are retrieved using List methods.
31 * This class is used to read configuration files.
32 */
33 public class XmlListAttribute extends XmlAttribute
34 {
35 /** List.
36 * We declare a List to avoid cast.
37 * Parent "value" property points to the same list.
38 */
39 private List list;
40
41 /**
42 * Constructor.
43 */
44 public XmlListAttribute()
45 {
46 list = new ArrayList();
47 setValue(list);
48 }
49
50 /**
51 * Constructor.
52 * @param name Name.
53 * @param value List.
54 */
55 public XmlListAttribute( String name, List value)
56 {
57 super( name, value );
58 list = value;
59 }
60
61 /**
62 * Add an element in list.
63 * We use a property to avoid rewriting a new class.
64 * @param element XmlAttribute to add.
65 */
66 public void add( XmlAttribute element )
67 {
68 list.add( element.getValue() );
69 }
70
71 /**
72 * Add an element in list.
73 * @param value Object to add.
74 */
75 public void add( Object value )
76 {
77 //list.add( value );
78 // To correct a bug in digester, we need to check the object type
79 // Digester doesn't call correct method according to object type ;-(
80 if(value instanceof XmlAttribute)
81 {
82 add((XmlAttribute)value);
83 return;
84 }
85 else
86 list.add( value );
87 }
88
89 /**
90 * Add an element in list.
91 * @param value Object to add.
92 */
93 public void addObject( Object value )
94 {
95 list.add( value );
96 }
97
98
99
100 }