View Javadoc

1   /*
2    * $Id: ListAttribute.java 527536 2007-04-11 15:44:51Z apetrelli $
3    *
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   * http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
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          //list.add( value );
81          // To correct a bug in digester, we need to check the object type
82          // Digester doesn't call correct method according to object type ;-(
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  }