001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jboss.test.cluster.web.aop;
023:
024: import java.util.*;
025:
026: /**
027: * Test class for TreeCacheAOP.
028: * Person is a POJO that will be instrumented with CacheInterceptor
029: *
030: * @version $Revision: 60216 $
031: */
032: @org.jboss.cache.aop.annotation.InstanceOfPojoCacheable
033: public class Person {
034: String name = null;
035: int age = 0;
036: Map hobbies = null;
037: Address address = null;
038: Set skills;
039: List languages;
040: // Test for transient field non-replication
041: transient String currentStatus = "Active";
042: // Test swapping out the Collection ref with proxy one
043: // medication will be different when age limit is exceeded.
044: List medication = null;
045: static final int AGE1 = 50;
046: static final int AGE2 = 60;
047:
048: public Person() {
049:
050: }
051:
052: public String getName() {
053: return name;
054: }
055:
056: public void setName(String name) {
057: this .name = name;
058: }
059:
060: public void setCurrentStatus(String status) {
061: currentStatus = status;
062: }
063:
064: public String getCurrentStatus() {
065: return currentStatus;
066: }
067:
068: public void setName(Object obj) {
069: this .name = (String) obj;
070: }
071:
072: public int getAge() {
073: return age;
074: }
075:
076: public void setAge(int age) {
077:
078: this .age = age;
079:
080: // This will swap out the reference dynamically
081: if (age < AGE1) {
082: if (medication != null) {
083: medication.clear();
084: medication = null;
085: }
086: } else {
087: if (age >= AGE1) {
088: addMedication("Lipitor");
089: }
090:
091: if (age >= AGE2) {
092: addMedication("Vioxx");
093: }
094: }
095:
096: }
097:
098: void addMedication(String name) {
099: if (medication == null)
100: medication = new ArrayList();
101: if (!medication.contains(name))
102: medication.add(name);
103: }
104:
105: public Map getHobbies() {
106: return hobbies;
107: }
108:
109: public void setHobbies(Map hobbies) {
110: this .hobbies = hobbies;
111: }
112:
113: public Address getAddress() {
114: return address;
115: }
116:
117: public void setAddress(Address address) {
118: this .address = address;
119: }
120:
121: public Set getSkills() {
122: return skills;
123: }
124:
125: public void setSkills(Set skills) {
126: this .skills = skills;
127: }
128:
129: public List getMedication() {
130: return medication;
131: }
132:
133: public void setMedication(List medication) {
134: this .medication = medication;
135: }
136:
137: public List getLanguages() {
138: return languages;
139: }
140:
141: public void setLanguages(List languages) {
142: this .languages = languages;
143: }
144:
145: public String toString() {
146: StringBuffer sb = new StringBuffer();
147: sb.append("name=").append(getName()).append(", age=").append(
148: getAge()).append(", hobbies=").append(
149: print(getHobbies())).append(", address=").append(
150: getAddress()).append(", skills=").append(skills)
151: .append(", languages=").append(languages).toString();
152: if (medication != null)
153: sb.append(", medication=" + medication);
154: return sb.toString();
155: }
156:
157: public String print(Map m) {
158: StringBuffer sb = new StringBuffer();
159: Map.Entry entry;
160: if (m != null) {
161: for (Iterator it = m.entrySet().iterator(); it.hasNext();) {
162: entry = (Map.Entry) it.next();
163: sb.append(entry.getKey()).append(": ").append(
164: entry.getValue());
165: sb.append("\n");
166: }
167: }
168: return sb.toString();
169: }
170: }
|