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.deprec;
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: 59755 $
031: * annotation marker that is needed for fine-grained replication.
032: * @@org.jboss.web.tomcat.tc5.session.InstanceOfAopMarker
033: */
034: public class Person {
035: String name = null;
036: int age = 0;
037: Map hobbies = null;
038: Address address = null;
039: Set skills;
040: List languages;
041: // Test for transient field non-replication
042: transient String currentStatus = "Active";
043: // Test swapping out the Collection ref with proxy one
044: // medication will be different when age limit is exceeded.
045: List medication = null;
046: static final int AGE1 = 50;
047: static final int AGE2 = 60;
048:
049: public Person() {
050:
051: }
052:
053: public String getName() {
054: return name;
055: }
056:
057: public void setName(String name) {
058: this .name = name;
059: }
060:
061: public void setCurrentStatus(String status) {
062: currentStatus = status;
063: }
064:
065: public String getCurrentStatus() {
066: return currentStatus;
067: }
068:
069: public void setName(Object obj) {
070: this .name = (String) obj;
071: }
072:
073: public int getAge() {
074: return age;
075: }
076:
077: public void setAge(int age) {
078:
079: this .age = age;
080:
081: // This will swap out the reference dynamically
082: if (age < AGE1) {
083: if (medication != null) {
084: medication.clear();
085: medication = null;
086: }
087: } else {
088: if (age >= AGE1) {
089: addMedication("Lipitor");
090: }
091:
092: if (age >= AGE2) {
093: addMedication("Vioxx");
094: }
095: }
096:
097: }
098:
099: void addMedication(String name) {
100: if (medication == null)
101: medication = new ArrayList();
102: if (!medication.contains(name))
103: medication.add(name);
104: }
105:
106: public Map getHobbies() {
107: return hobbies;
108: }
109:
110: public void setHobbies(Map hobbies) {
111: this .hobbies = hobbies;
112: }
113:
114: public Address getAddress() {
115: return address;
116: }
117:
118: public void setAddress(Address address) {
119: this .address = address;
120: }
121:
122: public Set getSkills() {
123: return skills;
124: }
125:
126: public void setSkills(Set skills) {
127: this .skills = skills;
128: }
129:
130: public List getMedication() {
131: return medication;
132: }
133:
134: public void setMedication(List medication) {
135: this .medication = medication;
136: }
137:
138: public List getLanguages() {
139: return languages;
140: }
141:
142: public void setLanguages(List languages) {
143: this .languages = languages;
144: }
145:
146: public String toString() {
147: StringBuffer sb = new StringBuffer();
148: sb.append("name=").append(getName()).append(", age=").append(
149: getAge()).append(", hobbies=").append(
150: print(getHobbies())).append(", address=").append(
151: getAddress()).append(", skills=").append(skills)
152: .append(", languages=").append(languages).toString();
153: if (medication != null)
154: sb.append(", medication=" + medication);
155: return sb.toString();
156: }
157:
158: public String print(Map m) {
159: StringBuffer sb = new StringBuffer();
160: Map.Entry entry;
161: if (m != null) {
162: for (Iterator it = m.entrySet().iterator(); it.hasNext();) {
163: entry = (Map.Entry) it.next();
164: sb.append(entry.getKey()).append(": ").append(
165: entry.getValue());
166: sb.append("\n");
167: }
168: }
169: return sb.toString();
170: }
171: }
|