KickJava   Java API By Example, From Geeks To Geeks.

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


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.object.dna.api.DNA;
8 import com.tc.object.dna.api.DNAException;
9 import com.tc.object.dna.api.DNAWriter;
10
11 import gnu.trove.TLinkable;
12
13 import java.util.LinkedList JavaDoc;
14 import java.util.List JavaDoc;
15
16 /**
17  * Mock implementation of TCObject for testing.
18  */

19 public class MockTCObject implements TCObject {
20   private ObjectID id;
21   private Object JavaDoc peer;
22   private List JavaDoc history = new LinkedList JavaDoc();
23   private final Object JavaDoc resolveLock = new Object JavaDoc();
24   private long version = 0;
25   private TCClass tcClazz;
26   private boolean accessed = false;
27
28   public MockTCObject(final ObjectID id, final Object JavaDoc obj) {
29     this(id, obj, false, false);
30   }
31
32   public MockTCObject(final ObjectID id, final Object JavaDoc obj, boolean isIndexed, boolean isLogical) {
33     this.peer = obj;
34     this.id = id;
35     this.tcClazz = new MockTCClass(isIndexed, isLogical);
36   }
37
38   public List JavaDoc getHistory() {
39     return history;
40   }
41
42   public ObjectID getObjectID() {
43     return this.id;
44   }
45
46   public Object JavaDoc getPeerObject() {
47     return this.peer;
48   }
49
50   public TCClass getTCClass() {
51     return this.tcClazz;
52   }
53
54   public void booleanFieldChanged(String JavaDoc classname, String JavaDoc fieldname, boolean newValue, int index) {
55     throw new ImplementMe();
56   }
57
58   public void byteFieldChanged(String JavaDoc classname, String JavaDoc fieldname, byte newValue, int index) {
59     throw new ImplementMe();
60   }
61
62   public void charFieldChanged(String JavaDoc classname, String JavaDoc fieldname, char newValue, int index) {
63     throw new ImplementMe();
64   }
65
66   public void doubleFieldChanged(String JavaDoc classname, String JavaDoc fieldname, double newValue, int index) {
67     throw new ImplementMe();
68   }
69
70   public void floatFieldChanged(String JavaDoc classname, String JavaDoc fieldname, float newValue, int index) {
71     throw new ImplementMe();
72   }
73
74   public void intFieldChanged(String JavaDoc classname, String JavaDoc fieldname, int newValue, int index) {
75     throw new ImplementMe();
76   }
77
78   public void longFieldChanged(String JavaDoc classname, String JavaDoc fieldname, long newValue, int index) {
79     throw new ImplementMe();
80   }
81
82   public void shortFieldChanged(String JavaDoc classname, String JavaDoc fieldname, short newValue, int index) {
83     throw new ImplementMe();
84   }
85
86   public void hydrate(DNA from, boolean force) throws DNAException {
87     // do nothing
88
}
89
90   public void resolveReference(String JavaDoc fieldName) {
91     throw new ImplementMe();
92   }
93
94   public void resolveArrayReference(int index) {
95     return;
96   }
97
98   public void dehydrate(DNAWriter writer) throws DNAException {
99     return;
100   }
101
102   public void objectFieldChanged(String JavaDoc classname, String JavaDoc fieldname, Object JavaDoc newValue, int index) {
103     return;
104   }
105
106   public boolean isPhysical() {
107     return true;
108   }
109
110   public boolean isLogical() {
111     return false;
112   }
113
114   public static class MethodCall {
115     public int method;
116     public Object JavaDoc[] parameters;
117
118     public MethodCall(int method, Object JavaDoc[] parameters) {
119       this.method = method;
120       this.parameters = parameters;
121     }
122
123     public String JavaDoc toString() {
124       StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
125       sb.append(method);
126       sb.append("(");
127       for (int i = 0; i < parameters.length; i++) {
128         sb.append(parameters[i].toString());
129         if (i + 1 < parameters.length) {
130           sb.append(',');
131         }
132       }
133       sb.append(")");
134       return sb.toString();
135     }
136   }
137
138   public void setReference(String JavaDoc fieldName, ObjectID id) {
139     throw new ImplementMe();
140   }
141
142   public void setValue(String JavaDoc fieldName, Object JavaDoc obj) {
143     throw new ImplementMe();
144   }
145
146   public long getVersion() {
147     return version;
148   }
149
150   public void setVersion(long version) {
151     this.version = version;
152   }
153
154   public int clearReferences(int toClear) {
155     return 0;
156   }
157
158   public Object JavaDoc getResolveLock() {
159     return resolveLock;
160   }
161
162   public void setNext(TLinkable link) {
163     throw new ImplementMe();
164   }
165
166   public void setPrevious(TLinkable link) {
167     throw new ImplementMe();
168   }
169
170   public TLinkable getNext() {
171     return null;
172   }
173
174   public TLinkable getPrevious() {
175     return null;
176   }
177
178   public ClassLoader JavaDoc getClassLoader() {
179     return null;
180   }
181
182   public void markAccessed() {
183     this.accessed = true;
184   }
185
186   public void clearAccessed() {
187     this.accessed = false;
188   }
189
190   public boolean recentlyAccessed() {
191     return this.accessed;
192   }
193
194   public int accessCount(int factor) {
195     throw new ImplementMe();
196   }
197
198   public void clearReference(String JavaDoc fieldName) {
199     throw new ImplementMe();
200   }
201
202   public void resolveAllReferences() {
203     //
204
}
205
206   public boolean getAndResetNew() {
207     return false;
208   }
209
210   public void setIsNew() {
211     //
212
}
213
214   public boolean isNew() {
215     return false;
216   }
217
218   public boolean isShared() {
219     return true;
220   }
221
222   public void objectFieldChangedByOffset(String JavaDoc classname, long fieldOffset, Object JavaDoc newValue, int index) {
223     return;
224   }
225
226   public void logicalInvoke(int method, String JavaDoc methodSignature, Object JavaDoc[] params) {
227     history.add(new MethodCall(method, params));
228     System.out.println("This:" + this + " logging:" + methodSignature + " params:" + params + " history:" + history);
229   }
230
231   public String JavaDoc getFieldNameByOffset(long fieldOffset) {
232     throw new ImplementMe();
233   }
234
235   public void disableAutoLocking() {
236     throw new ImplementMe();
237   }
238
239   public boolean autoLockingDisabled() {
240     return false;
241   }
242
243   public boolean canEvict() {
244     throw new ImplementMe();
245   }
246
247   public void objectArrayChanged(int startPos, Object JavaDoc[] array, int length) {
248     throw new ImplementMe();
249   }
250
251   public void primitiveArrayChanged(int startPos, Object JavaDoc array, int length) {
252     throw new ImplementMe();
253   }
254
255   public void literalValueChanged(Object JavaDoc newValue, Object JavaDoc oldValue) {
256     throw new ImplementMe();
257   }
258
259   public void setLiteralValue(Object JavaDoc newValue) {
260     throw new ImplementMe();
261   }
262
263   public ArrayIndexOutOfBoundsException JavaDoc checkArrayIndex(int index) {
264     throw new ImplementMe();
265   }
266 }
267
Popular Tags