01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright
03: * notice. All rights reserved.
04: */
05: package java.util;
06:
07: import com.tc.object.ObjectID;
08: import com.tc.object.bytecode.Manageable;
09: import com.tc.object.bytecode.ManagerUtil;
10:
11: import java.util.HashMap.Entry;
12: import java.util.HashMapTC.ValueWrapper;
13:
14: /*
15: * This class is merged with java.util.LinkedHashMap in the bootjar. Since HashMapTC will also be merged with
16: * java.util.HashMap, this class will inherit all behavior of HashMapTC including the Manageable methods and Clearable
17: * method. It is declared abstract to make the compiler happy
18: */
19: public abstract class LinkedHashMapTC extends LinkedHashMap implements
20: Manageable {
21:
22: private boolean accessOrder;
23:
24: // This is pretty much a C&P of the one in HashMapTC
25: public boolean containsValue(Object value) {
26: if (__tc_isManaged()) {
27: synchronized (__tc_managed().getResolveLock()) {
28: if (value != null) {
29: // XXX:: This is tied closely to HashMap implementation which calls equals on the passed value rather than the
30: // other way around
31: return super .containsValue(new ValueWrapper(value));
32: } else {
33: return super .containsValue(value);
34: }
35: }
36: } else {
37: return super .containsValue(value);
38: }
39: }
40:
41: public Object get(Object key) {
42: if (__tc_isManaged()) {
43: synchronized (__tc_managed().getResolveLock()) {
44: if (accessOrder) {
45: ManagerUtil.checkWriteAccess(this );
46: }
47:
48: // XXX: doing two lookups here!!
49: Entry entry = super .getEntry(key);
50: if (entry == null) {
51: return null;
52: }
53:
54: Object actualKey = entry.getKey();
55:
56: // do the original get logic
57: Object val = super .get(key);
58:
59: if (accessOrder) {
60: ManagerUtil
61: .logicalInvoke(
62: this ,
63: "get(Ljava/lang/Object;)Ljava/lang/Object;",
64: new Object[] { actualKey });
65: }
66: return lookUpAndStoreIfNecessary(key, val);
67: }
68: } else {
69: return super .get(key);
70: }
71: }
72:
73: private Object lookUpAndStoreIfNecessary(Object key, Object value) {
74: if (value instanceof ObjectID) {
75: Object newVal = ManagerUtil.lookupObject((ObjectID) value);
76: Map.Entry e = getEntry(key);
77: // e should not be null here
78: e.setValue(newVal);
79: return newVal;
80: } else {
81: return value;
82: }
83: }
84:
85: }
|