KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > cache > tests > aop > Person


1 /*
2  * JBoss, the OpenSource J2EE webOS
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  */

7 package org.jboss.cache.tests.aop;
8
9 import java.util.*;
10
11
12 /**
13  * Test class for TreeCacheAOP.
14  * Person is a POJO that will be instrumented with CacheInterceptor
15  *
16  * @version $Revision: 1.3 $
17  * <p>Below is the annotation that signifies this class is "prepared" under JBossAop. This is used in
18  * conjunction with a special jboss-aop.xml (supplied by JBossCache). In addition, this is JDK1.4 style,
19  * so a annoc Ant build target is needed to pre-compile it.</p>
20  * <p>To use this approach, just apply this line to your pojo and run annoc (and possibly aopc).</p>
21  * @@org.jboss.cache.aop.InstanceOfAopMarker
22  */

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