KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > cluster > web > aop > jdk5 > 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.jdk5;
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$
32  * Annotation marker that is needed for fine-grained replication.
33  * Note that we do it in 1.4 style now so it needs annotation compiler,
34  * annotationc.
35  */

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