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.bean;
17  
18  import java.util.ArrayList;
19  import java.util.List;
20  
21  import org.apache.commons.jelly.JellyTagException;
22  import org.apache.commons.jelly.TagSupport;
23  import org.apache.commons.jelly.XMLOutput;
24  import org.apache.commons.jelly.impl.CollectionTag;
25  
26  /***
27   * A simple tag which demonstrates how to process beans generically.
28   *
29   * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
30   * @version  $Revision: 155420 $
31   */
32  public class MyContainerTag extends TagSupport implements CollectionTag {
33  
34      private List list = new ArrayList();
35      private String var;
36  
37      public MyContainerTag() {
38      }
39  
40      // Tag interface
41      //-------------------------------------------------------------------------
42      public void doTag(XMLOutput output) throws JellyTagException {
43          invokeBody(output);
44          context.setVariable(var, list);
45          list = new ArrayList();
46      }
47  
48      // CollectionTag interface
49      //-------------------------------------------------------------------------
50      public void addItem(Object value) {
51          list.add(value);
52      }
53  
54      // Properties
55      //-------------------------------------------------------------------------
56      /***
57       * @return String
58       */
59      public String getVar() {
60          return var;
61      }
62  
63      /***
64       * Sets the var.
65       * @param var The var to set
66       */
67      public void setVar(String var) {
68          this.var = var;
69      }
70  
71  }