01: /*
02: * All content copyright (c) 2003-2007 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
03: */
04: package org.terracotta.dso;
05:
06: import org.eclipse.jdt.core.IField;
07: import org.eclipse.jdt.core.IMethod;
08: import org.eclipse.jdt.core.IType;
09: import org.eclipse.jdt.core.JavaModelException;
10:
11: import com.tc.aspectwerkz.reflect.ClassInfo;
12: import com.tc.aspectwerkz.reflect.FieldInfo;
13: import com.tc.aspectwerkz.reflect.MethodInfo;
14:
15: import java.lang.ref.SoftReference;
16: import java.util.HashMap;
17: import java.util.Map;
18:
19: public class ClassInfoFactory extends
20: com.tc.object.bytecode.aspectwerkz.ClassInfoFactory {
21: private final Map<String, SoftReference> classInfoCache = new HashMap<String, SoftReference>();
22:
23: public ClassInfo getClassInfo(String className) {
24: ClassInfo info = null;
25: synchronized (classInfoCache) {
26: SoftReference ref = classInfoCache.get(className);
27: if (ref != null) {
28: info = (JavaModelClassInfo) ref.get();
29: }
30: if (info == null) {
31: info = new JavaModelClassInfo(className);
32: classInfoCache.put(className, new SoftReference(info));
33: }
34: }
35: return info;
36: }
37:
38: public ClassInfo getClassInfo(IType type) {
39: JavaModelClassInfo info = null;
40: synchronized (classInfoCache) {
41: String className = type.getFullyQualifiedName('$');
42: SoftReference ref = classInfoCache.get(className);
43: if (ref != null) {
44: info = (JavaModelClassInfo) ref.get();
45: }
46: if (info == null || info.isStale()) {
47: info = new JavaModelClassInfo(type);
48: classInfoCache.put(className, new SoftReference(info));
49: }
50: }
51: return info;
52: }
53:
54: public MethodInfo getMethodInfo(IMethod method)
55: throws JavaModelException {
56: JavaModelClassInfo classInfo = (JavaModelClassInfo) getClassInfo(method
57: .getDeclaringType());
58: return classInfo.getMethod(this , method);
59: }
60:
61: public FieldInfo getFieldInfo(IField field) {
62: JavaModelClassInfo classInfo = (JavaModelClassInfo) getClassInfo(field
63: .getDeclaringType());
64: return classInfo.getField(this, field);
65: }
66: }
|