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.Iterator;
20  import java.util.List;
21  
22  /***
23   * A sample bean that we can construct via Jelly tags
24   *
25   * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
26   * @version $Revision: 155420 $
27   */
28  public class Customer {
29  
30      private String name;
31      private String location;
32      private List orders = new ArrayList();
33  
34  
35      public Customer() {
36      }
37  
38      public Customer(String name) {
39          setName(name);
40      }
41  
42      public Customer(String name, String location) {
43          setName(name);
44          setLocation(location);
45      }
46  
47      public Customer(String name, String location, Order anOrder) {
48          setName(name);
49          setLocation(location);
50          addOrder(anOrder);
51      }
52  
53      public Customer(Customer cust) {
54          setName(cust.getName());
55          setLocation(cust.getLocation());
56          List list = cust.getOrders();
57          if(null != list) {
58              for(Iterator iter = list.iterator();iter.hasNext();) {
59                  addOrder((Order)iter.next());
60              }
61          }
62      }
63  
64      public String toString() {
65          return super.toString() + "[name=" + name + ";location=" + location + "]";
66      }
67  
68      /***
69       * Creates a new Order object
70       */
71      public Order createOrder() {
72          return new Order();
73      }
74  
75      public List getOrders() {
76          return orders;
77      }
78  
79      public void addOrder(Order order) {
80          orders.add(order);
81      }
82  
83      public void removeOrder(Order order) {
84          orders.remove(order);
85      }
86  
87      /***
88       * Returns the location.
89       * @return String
90       */
91      public String getLocation() {
92          return location;
93      }
94  
95      /***
96       * Returns the name.
97       * @return String
98       */
99      public String getName() {
100         return name;
101     }
102 
103     /***
104      * Sets the location.
105      * @param location The location to set
106      */
107     public void setLocation(String location) {
108         this.location = location;
109     }
110 
111     /***
112      * Sets the name.
113      * @param name The name to set
114      */
115     public void setName(String name) {
116         this.name = name;
117     }
118 }