1 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 ; 15 import java.util.Collection ; 16 import java.util.HashMap ; 17 import java.util.IdentityHashMap ; 18 import java.util.Map ; 19 20 23 public class TestClientObjectManager implements ClientObjectManager { 24 public final Map objects = new HashMap (); 25 public final Map object2TCObject = new IdentityHashMap (); 26 private int idSequence = 1; 27 private Object root = new IdentityHashMap (); 28 private boolean isManaged; 29 private ReferenceQueue referenceQueue; 30 private ClientTransactionManager txManager; 31 32 public void add(Object 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 pojo) { 42 return this.object2TCObject.containsKey(pojo) || isManaged; 43 } 44 45 public boolean isPortableInstance(Object pojo) { 46 return true; 47 } 48 49 public boolean isPortableClass(Class clazz) { 50 return true; 51 } 52 53 public synchronized TCObject lookupOrCreate(Object obj) { 54 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 obj) { 67 TCObject rv = (TCObject) object2TCObject.get(obj); 68 return rv; 69 } 70 71 public Object lookupOrCreateRoot(String name, Object candidate) { 72 Object 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 getAllObjectIDsAndClear(Collection 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 lookupObject(ObjectID id) { 101 return ((TCObject) objects.get(id)).getPeerObject(); 102 } 103 104 public TCClass getOrCreateClass(Class clazz) { 105 throw new ImplementMe(); 106 } 107 108 public void setTransactionManager(ClientTransactionManager txManager) { 109 this.txManager = txManager; 110 } 111 112 public void setReferenceQueue(ReferenceQueue rq) { 113 this.referenceQueue = rq; 114 } 115 116 public ReferenceQueue getReferenceQueue() { 117 return this.referenceQueue; 118 } 119 120 public ObjectID lookupExistingObjectID(Object obj) { 121 return ((TCObject) this.object2TCObject.get(obj)).getObjectID(); 122 } 123 124 public void markReferenced(TCObject tcobj) { 125 } 127 128 public void shutdown() { 129 } 131 132 public ClientTransactionManager getTransactionManager() { 133 return txManager; 134 } 135 136 public Class getClassFor(String className, String loaderDesc) { 137 throw new ImplementMe(); 138 } 139 140 public TCObject lookupExistingOrNull(Object pojo) { 141 if (isManaged) { 142 lookupOrCreate(pojo); 143 } 144 145 return (TCObject) this.object2TCObject.get(pojo); 146 } 147 148 public Object lookupRoot(String 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 value, String fieldName, Class target) throws TCNonPortableObjectError { 165 return; 166 } 167 168 public void checkPortabilityOfLogicalAction(Object p, String methodName, Class 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 deepCopy(Object source, OptimisticTransactionManager optimisticTxManager) { 178 throw new ImplementMe(); 179 } 180 181 public Object createNewCopyInstance(Object source, Object parent) { 182 throw new ImplementMe(); 183 } 184 185 public Object createParentCopyInstanceIfNecessary(Map visited, Map cloned, Object v) { 186 throw new ImplementMe(); 187 } 188 189 public void replaceRootIDIfNecessary(String rootName, ObjectID newRootID) { 190 throw new ImplementMe(); 191 } 192 193 public Object lookupOrCreateRoot(String name, Object obj, boolean dsoFinal) { 194 throw new ImplementMe(); 195 } 196 197 public TCObject lookupOrShare(Object pojo) { 198 throw new ImplementMe(); 199 } 200 201 public boolean isCreationInProgress() { 202 return false; 203 } 204 205 public void addPendingCreateObjectsToTransaction() { 206 } 208 209 public boolean hasPendingCreateObjects() { 210 return false; 211 } 212 213 public Object lookupObjectNoDepth(ObjectID id) { 214 throw new ImplementMe(); 215 } 216 217 public Object lookupOrCreateRootNoDepth(String rootName, Object object) { 218 throw new ImplementMe(); 219 } 220 221 public Object createOrReplaceRoot(String rootName, Object r) { 222 throw new ImplementMe(); 223 } 224 } 225 | Popular Tags |