View Javadoc

1   /*
2    * $Id: XmlListAttribute.java 471754 2006-11-06 14:55:09Z husted $
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  
22  package org.apache.struts.tiles.xmlDefinition;
23  
24  import java.util.ArrayList;
25  import java.util.List;
26  
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  public class XmlListAttribute extends XmlAttribute
36  {
37      /** List.
38       * We declare a List to avoid cast.
39       * Parent "value" property points to the same list.
40       */
41    private List list;
42  
43      /**
44       * Constructor.
45       */
46    public XmlListAttribute()
47      {
48      list = new ArrayList();
49      setValue(list);
50      }
51  
52      /**
53       * Constructor.
54       * @param name Name.
55       * @param value List.
56       */
57    public XmlListAttribute( String name, List value)
58      {
59      super( name, value );
60      list = value;
61      }
62  
63      /**
64       * Add an element in list.
65       * We use a property to avoid rewriting a new class.
66       * @param element XmlAttribute to add.
67       */
68    public void add( XmlAttribute element )
69      {
70      list.add( element.getValue() );
71      }
72  
73      /**
74       * Add an element in list.
75       * @param value Object to add.
76       */
77    public void add( Object value )
78      {
79      //list.add( value );
80        // To correct a bug in digester, we need to check the object type
81        // Digester doesn't call correct method according to object type ;-(
82      if(value instanceof XmlAttribute)
83        {
84        add((XmlAttribute)value);
85        return;
86        }
87       else
88        list.add( value );
89      }
90  
91      /**
92       * Add an element in list.
93       * @param value Object to add.
94       */
95    public void addObject( Object value )
96      {
97      list.add( value );
98      }
99  
100 
101 
102 }