KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > cache > test > standAloneAop > 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.cache.test.standAloneAop;
23
24 import java.util.*;
25
26
27 /**
28  * Test class for TreeCacheAOP.
29  * Person is a POJO that will be instrumented with CacheInterceptor
30  *
31  * @version $Revision: 37406 $
32  */

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