KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > cluster > web > aop > Person


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

22 package org.jboss.test.cluster.web.aop;
23
24 import java.util.*;
25
26 import org.jboss.cache.pojo.annotation.InstanceOfPojoCacheable;
27
28
29 /**
30  * Test class for PojoCache.
31  * Person is a POJO that will be instrumented with CacheInterceptor
32  *
33  * @version $Revision: 58605 $
34  */

35 @InstanceOfPojoCacheable
36 public class Person
37 {
38    String JavaDoc name = null;
39    int age = 0;
40    Map hobbies = null;
41    Address address = null;
42    Set skills;
43    List languages;
44    // Test for transient field non-replication
45
transient String JavaDoc currentStatus = "Active";
46    // Test swapping out the Collection ref with proxy one
47
// medication will be different when age limit is exceeded.
48
List medication = null;
49    static final int AGE1 = 50;
50    static final int AGE2 = 60;
51
52    public Person() {
53
54    }
55
56    public String JavaDoc getName()
57    {
58       return name;
59    }
60
61    public void setName(String JavaDoc name)
62    {
63       this.name = name;
64    }
65
66    public void setCurrentStatus(String JavaDoc status) {
67       currentStatus = status;
68    }
69
70    public String JavaDoc getCurrentStatus() {
71       return currentStatus;
72    }
73
74    public void setName(Object JavaDoc obj)
75    {
76       this.name = (String JavaDoc)obj;
77    }
78
79    public int getAge()
80    {
81       return age;
82    }
83
84    public void setAge(int age)
85    {
86
87       this.age = age;
88
89       // This will swap out the reference dynamically
90
if(age < AGE1) {
91          if(medication != null) {
92             medication.clear();
93             medication=null;
94          }
95       }
96       else {
97          if( age >= AGE1 ) {
98             addMedication("Lipitor");
99          }
100
101          if (age >= AGE2) {
102             addMedication("Vioxx");
103          }
104       }
105
106
107    }
108
109    void addMedication(String JavaDoc name) {
110       if( medication == null )
111          medication = new ArrayList();
112       if(!medication.contains(name))
113          medication.add(name);
114    }
115
116    public Map getHobbies()
117    {
118       return hobbies;
119    }
120
121    public void setHobbies(Map hobbies)
122    {
123       this.hobbies = hobbies;
124    }
125
126    public Address getAddress()
127    {
128       return address;
129    }
130
131    public void setAddress(Address address)
132    {
133       this.address = address;
134    }
135
136    public Set getSkills()
137    {
138       return skills;
139    }
140
141    public void setSkills(Set skills)
142    {
143       this.skills = skills;
144    }
145
146    public List getMedication()
147    {
148       return medication;
149    }
150
151    public void setMedication(List medication)
152    {
153       this.medication = medication;
154    }
155
156    public List getLanguages()
157    {
158       return languages;
159    }
160
161    public void setLanguages(List languages)
162    {
163       this.languages = languages;
164    }
165
166    public String JavaDoc toString()
167    {
168       StringBuffer JavaDoc sb=new StringBuffer JavaDoc();
169       sb.append("name=").append(getName()).append(", age=").append(getAge()).append(", hobbies=")
170             .append(print(getHobbies())).append(", address=").append(getAddress()).append(", skills=")
171             .append(skills).append(", languages=").append(languages).toString();
172       if(medication != null)
173          sb.append(", medication=" + medication);
174       return sb.toString();
175    }
176
177    public String JavaDoc print(Map m)
178    {
179       StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
180       Map.Entry entry;
181       if (m != null) {
182          for (Iterator it = m.entrySet().iterator(); it.hasNext();) {
183             entry = (Map.Entry) it.next();
184             sb.append(entry.getKey()).append(": ").append(entry.getValue());
185             sb.append("\n");
186          }
187       }
188       return sb.toString();
189    }
190 }
191
Popular Tags