KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > terracotta > dso > BootClassHelper


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 org.terracotta.dso;
5
6 import org.eclipse.core.runtime.IPath;
7 import org.eclipse.jdt.core.IClassFile;
8 import org.eclipse.jdt.core.ICompilationUnit;
9 import org.eclipse.jdt.core.IType;
10 import org.eclipse.jdt.core.JavaModelException;
11
12 import com.tc.object.tools.BootJar;
13 import com.tc.object.tools.BootJarSignature;
14
15 import java.io.File JavaDoc;
16 import java.util.HashSet JavaDoc;
17 import java.util.Iterator JavaDoc;
18 import java.util.Set JavaDoc;
19
20 /**
21  * Utility for determining if a type is a pre-instrumented class in the bootjar.
22  */

23
24 public class BootClassHelper {
25   private static BootClassHelper m_helper;
26   private Set JavaDoc<String JavaDoc> m_bootClasses;
27   
28   public static BootClassHelper getHelper() {
29     return m_helper;
30   }
31   
32   static BootClassHelper initialize() throws Exception JavaDoc {
33     return m_helper = new BootClassHelper();
34   }
35
36   /*
37    * Initialize from the boot-jar that would be used by the VM
38    * Eclipse is running in. Eclipse can be running in one VM version
39    * while the user can specify that internally it use another
40    * version. If that is the case, BootJar.getBootJarForReading will
41    * fail complaining that we're trying to read an incompatible
42    * version.
43    */

44   public BootClassHelper() throws Exception JavaDoc {
45     TcPlugin plugin = TcPlugin.getDefault();
46     IPath libDirPath = plugin.getLibDirPath();
47     
48     if(libDirPath.append("tc.jar").toFile().exists()) {
49       String JavaDoc bootJarName = BootJarSignature.getBootJarNameForThisVM();
50       IPath bootJarPath = libDirPath.append("dso-boot").append(bootJarName);
51       File bootJarFile = bootJarPath.toFile();
52       BootJar bootJar = BootJar.getBootJarForReading(bootJarFile);
53     
54       m_bootClasses = new HashSet JavaDoc<String JavaDoc>();
55       Set JavaDoc classes = bootJar.getAllPreInstrumentedClasses();
56       Iterator JavaDoc iter = classes.iterator();
57       while(iter.hasNext()) {
58         m_bootClasses.add(iter.next().toString());
59       }
60     }
61     
62     if(m_bootClasses == null) {
63       m_bootClasses = new HashSet JavaDoc<String JavaDoc>();
64     }
65     
66     m_bootClasses.add("java.lang.Integer");
67     m_bootClasses.add("java.lang.String");
68     m_bootClasses.add("java.lang.Double");
69     m_bootClasses.add("java.lang.Boolean");
70     m_bootClasses.add("java.lang.Character");
71     m_bootClasses.add("java.lang.Float");
72     m_bootClasses.add("java.util.HashMap");
73     m_bootClasses.add("java.util.ArrayList");
74   }
75
76   public boolean isAdaptable(final ICompilationUnit module) {
77     return module != null ? isAdaptable(module.findPrimaryType()) : false;
78   }
79   
80   public boolean isAdaptable(final IClassFile classFile) {
81     try {
82       return classFile != null ? isAdaptable(classFile.getType()) : false;
83     } catch(JavaModelException jme) {
84       return false;
85     }
86   }
87   
88   public boolean isAdaptable(final IType type) {
89     if(type != null) {
90       return isAdaptable(PatternHelper.getFullyQualifiedName(type));
91     }
92     return false;
93   }
94   
95   public boolean isAdaptable(String JavaDoc fullName) {
96     return m_bootClasses != null && m_bootClasses.contains(fullName);
97   }
98 }
99
Popular Tags