KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > object > TestClientObjectManager


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

4 package com.tc.object;
5
6 import com.tc.exception.ImplementMe;
7 import com.tc.exception.TCNonPortableObjectError;
8 import com.tc.object.bytecode.Manageable;
9 import com.tc.object.dna.api.DNA;
10 import com.tc.object.tx.ClientTransactionManager;
11 import com.tc.object.tx.optimistic.OptimisticTransactionManager;
12 import com.tc.util.Assert;
13
14 import java.lang.ref.ReferenceQueue JavaDoc;
15 import java.util.Collection JavaDoc;
16 import java.util.HashMap JavaDoc;
17 import java.util.IdentityHashMap JavaDoc;
18 import java.util.Map JavaDoc;
19
20 /**
21  * @author steve
22  */

23 public class TestClientObjectManager implements ClientObjectManager {
24   public final Map JavaDoc objects = new HashMap JavaDoc();
25   public final Map JavaDoc object2TCObject = new IdentityHashMap JavaDoc();
26   private int idSequence = 1;
27   private Object JavaDoc root = new IdentityHashMap JavaDoc();
28   private boolean isManaged;
29   private ReferenceQueue JavaDoc referenceQueue;
30   private ClientTransactionManager txManager;
31
32   public void add(Object JavaDoc id, TCObject tc) {
33     objects.put(id, tc);
34     this.object2TCObject.put(tc.getPeerObject(), tc);
35   }
36
37   public void setIsManaged(boolean b) {
38     this.isManaged = b;
39   }
40
41   public boolean isManaged(Object JavaDoc pojo) {
42     return this.object2TCObject.containsKey(pojo) || isManaged;
43   }
44
45   public boolean isPortableInstance(Object JavaDoc pojo) {
46     return true;
47   }
48
49   public boolean isPortableClass(Class JavaDoc clazz) {
50     return true;
51   }
52
53   public synchronized TCObject lookupOrCreate(Object JavaDoc obj) {
54     // System.out.println(this + ".lookupOrCreate(" + obj + ")");
55
TCObject rv = lookup(obj);
56     if (rv == null) {
57       rv = new MockTCObject(new ObjectID(idSequence++), obj);
58       object2TCObject.put(obj, rv);
59       if (obj instanceof Manageable) {
60         ((Manageable) obj).__tc_managed(rv);
61       }
62     }
63     return rv;
64   }
65
66   private synchronized TCObject lookup(Object JavaDoc obj) {
67     TCObject rv = (TCObject) object2TCObject.get(obj);
68     return rv;
69   }
70
71   public Object JavaDoc lookupOrCreateRoot(String JavaDoc name, Object JavaDoc candidate) {
72     Object JavaDoc rv = null;
73     if (candidate == null) {
74       rv = this.root;
75     } else {
76       rv = candidate;
77     }
78     Assert.assertNotNull(rv);
79     return rv;
80   }
81
82   public TCObject lookupIfLocal(ObjectID id) {
83     throw new ImplementMe();
84   }
85
86   public Collection JavaDoc getAllObjectIDsAndClear(Collection JavaDoc c) {
87     c.addAll(objects.keySet());
88     return c;
89   }
90
91   public TCObject lookup(ObjectID id) {
92     System.out.println(this + ".lookup(" + id + ")");
93     return (TCObject) objects.get(id);
94   }
95
96   public WeakObjectReference createNewPeer(TCClass clazz, int size, ObjectID id, ObjectID parentID) {
97     throw new ImplementMe();
98   }
99
100   public Object JavaDoc lookupObject(ObjectID id) {
101     return ((TCObject) objects.get(id)).getPeerObject();
102   }
103
104   public TCClass getOrCreateClass(Class JavaDoc clazz) {
105     throw new ImplementMe();
106   }
107
108   public void setTransactionManager(ClientTransactionManager txManager) {
109     this.txManager = txManager;
110   }
111
112   public void setReferenceQueue(ReferenceQueue JavaDoc rq) {
113     this.referenceQueue = rq;
114   }
115
116   public ReferenceQueue JavaDoc getReferenceQueue() {
117     return this.referenceQueue;
118   }
119
120   public ObjectID lookupExistingObjectID(Object JavaDoc obj) {
121     return ((TCObject) this.object2TCObject.get(obj)).getObjectID();
122   }
123
124   public void markReferenced(TCObject tcobj) {
125     // mark referenced
126
}
127
128   public void shutdown() {
129     //
130
}
131
132   public ClientTransactionManager getTransactionManager() {
133     return txManager;
134   }
135
136   public Class JavaDoc getClassFor(String JavaDoc className, String JavaDoc loaderDesc) {
137     throw new ImplementMe();
138   }
139
140   public TCObject lookupExistingOrNull(Object JavaDoc pojo) {
141     if (isManaged) {
142       lookupOrCreate(pojo);
143     }
144
145     return (TCObject) this.object2TCObject.get(pojo);
146   }
147
148   public Object JavaDoc lookupRoot(String JavaDoc name) {
149     throw new ImplementMe();
150   }
151
152   public void unpause() {
153     return;
154   }
155
156   public void pause() {
157     return;
158   }
159
160   public void starting() {
161     return;
162   }
163
164   public void checkPortabilityOfField(Object JavaDoc value, String JavaDoc fieldName, Class JavaDoc target) throws TCNonPortableObjectError {
165     return;
166   }
167
168   public void checkPortabilityOfLogicalAction(Object JavaDoc p, String JavaDoc methodName, Class JavaDoc pojo)
169       throws TCNonPortableObjectError {
170     return;
171   }
172
173   public WeakObjectReference createNewPeer(TCClass clazz, DNA dna) {
174     throw new ImplementMe();
175   }
176
177   public Object JavaDoc deepCopy(Object JavaDoc source, OptimisticTransactionManager optimisticTxManager) {
178     throw new ImplementMe();
179   }
180
181   public Object JavaDoc createNewCopyInstance(Object JavaDoc source, Object JavaDoc parent) {
182     throw new ImplementMe();
183   }
184
185   public Object JavaDoc createParentCopyInstanceIfNecessary(Map JavaDoc visited, Map JavaDoc cloned, Object JavaDoc v) {
186     throw new ImplementMe();
187   }
188
189   public void replaceRootIDIfNecessary(String JavaDoc rootName, ObjectID newRootID) {
190     throw new ImplementMe();
191   }
192
193   public Object JavaDoc lookupOrCreateRoot(String JavaDoc name, Object JavaDoc obj, boolean dsoFinal) {
194     throw new ImplementMe();
195   }
196
197   public TCObject lookupOrShare(Object JavaDoc pojo) {
198     throw new ImplementMe();
199   }
200
201   public boolean isCreationInProgress() {
202     return false;
203   }
204
205   public void addPendingCreateObjectsToTransaction() {
206     // do nothing
207
}
208
209   public boolean hasPendingCreateObjects() {
210     return false;
211   }
212
213   public Object JavaDoc lookupObjectNoDepth(ObjectID id) {
214     throw new ImplementMe();
215   }
216
217   public Object JavaDoc lookupOrCreateRootNoDepth(String JavaDoc rootName, Object JavaDoc object) {
218     throw new ImplementMe();
219   }
220
221   public Object JavaDoc createOrReplaceRoot(String JavaDoc rootName, Object JavaDoc r) {
222     throw new ImplementMe();
223   }
224 }
225
Popular Tags