001: /*
002: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright
003: * notice. All rights reserved.
004: */
005: package com.tc.object;
006:
007: import com.tc.exception.ImplementMe;
008: import com.tc.object.dna.api.DNA;
009: import com.tc.object.dna.api.DNAException;
010: import com.tc.object.dna.api.DNAWriter;
011:
012: import gnu.trove.TLinkable;
013:
014: import java.util.LinkedList;
015: import java.util.List;
016:
017: /**
018: * Mock implementation of TCObject for testing.
019: */
020: public class MockTCObject implements TCObject {
021: private ObjectID id;
022: private Object peer;
023: private List history = new LinkedList();
024: private final Object resolveLock = new Object();
025: private long version = 0;
026: private TCClass tcClazz;
027: private boolean accessed = false;
028:
029: private boolean dehydrateReturnValue = true;
030:
031: public MockTCObject(final ObjectID id, final Object obj) {
032: this (id, obj, false, false);
033: }
034:
035: public MockTCObject(final ObjectID id, final Object obj,
036: boolean isIndexed, boolean isLogical) {
037: this .peer = obj;
038: this .id = id;
039: this .tcClazz = new MockTCClass(isIndexed, isLogical);
040: }
041:
042: public void setDehydrateReturnValue(boolean dehydrateReturnValue) {
043: this .dehydrateReturnValue = dehydrateReturnValue;
044: }
045:
046: public List getHistory() {
047: return history;
048: }
049:
050: public ObjectID getObjectID() {
051: return this .id;
052: }
053:
054: public Object getPeerObject() {
055: return this .peer;
056: }
057:
058: public TCClass getTCClass() {
059: return this .tcClazz;
060: }
061:
062: public void booleanFieldChanged(String classname, String fieldname,
063: boolean newValue, int index) {
064: if ("java.lang.reflect.AccessibleObject.override"
065: .equals(fieldname)) {
066: // do nothing since the support for AccessibleObject looks up the
067: // TCObject instance in the currently active ClientObjectManager, which causes
068: // and exception to be thrown during the tests since their accessible status is
069: // always set to 'true' before execution
070: } else {
071: throw new ImplementMe();
072: }
073: }
074:
075: public void byteFieldChanged(String classname, String fieldname,
076: byte newValue, int index) {
077: throw new ImplementMe();
078: }
079:
080: public void charFieldChanged(String classname, String fieldname,
081: char newValue, int index) {
082: throw new ImplementMe();
083: }
084:
085: public void doubleFieldChanged(String classname, String fieldname,
086: double newValue, int index) {
087: throw new ImplementMe();
088: }
089:
090: public void floatFieldChanged(String classname, String fieldname,
091: float newValue, int index) {
092: throw new ImplementMe();
093: }
094:
095: public void intFieldChanged(String classname, String fieldname,
096: int newValue, int index) {
097: throw new ImplementMe();
098: }
099:
100: public void longFieldChanged(String classname, String fieldname,
101: long newValue, int index) {
102: throw new ImplementMe();
103: }
104:
105: public void shortFieldChanged(String classname, String fieldname,
106: short newValue, int index) {
107: throw new ImplementMe();
108: }
109:
110: public void hydrate(DNA from, boolean force) throws DNAException {
111: // do nothing
112: }
113:
114: public void resolveReference(String fieldName) {
115: throw new ImplementMe();
116: }
117:
118: public void resolveArrayReference(int index) {
119: return;
120: }
121:
122: public boolean dehydrateIfNew(DNAWriter writer) throws DNAException {
123: return dehydrateReturnValue;
124: }
125:
126: public void objectFieldChanged(String classname, String fieldname,
127: Object newValue, int index) {
128: return;
129: }
130:
131: public boolean isPhysical() {
132: return true;
133: }
134:
135: public boolean isLogical() {
136: return false;
137: }
138:
139: public static class MethodCall {
140: public int method;
141: public Object[] parameters;
142:
143: public MethodCall(int method, Object[] parameters) {
144: this .method = method;
145: this .parameters = parameters;
146: }
147:
148: public String toString() {
149: StringBuffer sb = new StringBuffer();
150: sb.append(method);
151: sb.append("(");
152: for (int i = 0; i < parameters.length; i++) {
153: sb.append(parameters[i].toString());
154: if (i + 1 < parameters.length) {
155: sb.append(',');
156: }
157: }
158: sb.append(")");
159: return sb.toString();
160: }
161: }
162:
163: public ObjectID setReference(String fieldName, ObjectID id) {
164: throw new ImplementMe();
165: }
166:
167: public void setArrayReference(int index, ObjectID id) {
168: throw new ImplementMe();
169: }
170:
171: public void setValue(String fieldName, Object obj) {
172: throw new ImplementMe();
173: }
174:
175: public long getVersion() {
176: return version;
177: }
178:
179: public void setVersion(long version) {
180: this .version = version;
181: }
182:
183: public int clearReferences(int toClear) {
184: return 0;
185: }
186:
187: public Object getResolveLock() {
188: return resolveLock;
189: }
190:
191: public void setNext(TLinkable link) {
192: throw new ImplementMe();
193: }
194:
195: public void setPrevious(TLinkable link) {
196: throw new ImplementMe();
197: }
198:
199: public TLinkable getNext() {
200: return null;
201: }
202:
203: public TLinkable getPrevious() {
204: return null;
205: }
206:
207: public ClassLoader getClassLoader() {
208: return null;
209: }
210:
211: public void markAccessed() {
212: this .accessed = true;
213: }
214:
215: public void clearAccessed() {
216: this .accessed = false;
217: }
218:
219: public boolean recentlyAccessed() {
220: return this .accessed;
221: }
222:
223: public int accessCount(int factor) {
224: throw new ImplementMe();
225: }
226:
227: public void clearReference(String fieldName) {
228: throw new ImplementMe();
229: }
230:
231: public void resolveAllReferences() {
232: //
233: }
234:
235: public void setIsNew() {
236: //
237: }
238:
239: public boolean isNew() {
240: return false;
241: }
242:
243: public boolean isShared() {
244: return true;
245: }
246:
247: public void objectFieldChangedByOffset(String classname,
248: long fieldOffset, Object newValue, int index) {
249: return;
250: }
251:
252: public void logicalInvoke(int method, String methodSignature,
253: Object[] params) {
254: history.add(new MethodCall(method, params));
255: }
256:
257: public String getFieldNameByOffset(long fieldOffset) {
258: throw new ImplementMe();
259: }
260:
261: public void disableAutoLocking() {
262: throw new ImplementMe();
263: }
264:
265: public boolean autoLockingDisabled() {
266: return false;
267: }
268:
269: public boolean canEvict() {
270: throw new ImplementMe();
271: }
272:
273: public void objectArrayChanged(int startPos, Object[] array,
274: int length) {
275: throw new ImplementMe();
276: }
277:
278: public void primitiveArrayChanged(int startPos, Object array,
279: int length) {
280: throw new ImplementMe();
281: }
282:
283: public void literalValueChanged(Object newValue, Object oldValue) {
284: throw new ImplementMe();
285: }
286:
287: public void setLiteralValue(Object newValue) {
288: throw new ImplementMe();
289: }
290:
291: public ArrayIndexOutOfBoundsException checkArrayIndex(int index) {
292: throw new ImplementMe();
293: }
294:
295: public boolean isFieldPortableByOffset(long fieldOffset) {
296: throw new ImplementMe();
297: }
298: }
|