author | xdono |
Wed, 02 Jul 2008 12:55:45 -0700 | |
changeset 715 | f16baef3a20e |
parent 468 | 642c8c0be52e |
child 5506 | 202f599c92aa |
permissions | -rw-r--r-- |
2 | 1 |
/* |
715 | 2 |
* Copyright 1997-2008 Sun Microsystems, Inc. All Rights Reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. Sun designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Sun in the LICENSE file that accompanied this code. |
|
10 |
* |
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
21 |
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
|
22 |
* CA 95054 USA or visit www.sun.com if you need additional information or |
|
23 |
* have any questions. |
|
24 |
*/ |
|
25 |
||
26 |
||
468
642c8c0be52e
6695553: Cleanup GPLv2+SPL legal notices in hat sources
ohair
parents:
51
diff
changeset
|
27 |
/* |
2 | 28 |
* The Original Code is HAT. The Initial Developer of the |
29 |
* Original Code is Bill Foote, with contributions from others |
|
468
642c8c0be52e
6695553: Cleanup GPLv2+SPL legal notices in hat sources
ohair
parents:
51
diff
changeset
|
30 |
* at JavaSoft/Sun. |
2 | 31 |
*/ |
32 |
||
33 |
package com.sun.tools.hat.internal.server; |
|
34 |
||
35 |
import com.sun.tools.hat.internal.model.JavaClass; |
|
36 |
import com.sun.tools.hat.internal.model.Snapshot; |
|
37 |
||
38 |
import java.util.LinkedList; |
|
39 |
import java.io.InputStream; |
|
40 |
import java.io.Reader; |
|
41 |
import java.io.InputStreamReader; |
|
42 |
import java.io.BufferedReader; |
|
43 |
import java.io.IOException; |
|
44 |
||
45 |
/** |
|
46 |
* This class is a helper that determines if a class is a "platform" |
|
47 |
* class or not. It's a platform class if its name starts with one of |
|
48 |
* the prefixes to be found in /com/sun/tools/hat/resources/platform_names.txt. |
|
49 |
* |
|
50 |
* @author Bill Foote |
|
51 |
*/ |
|
52 |
||
53 |
public class PlatformClasses { |
|
54 |
||
55 |
static String[] names = null; |
|
56 |
||
57 |
||
58 |
public static synchronized String[] getNames() { |
|
59 |
if (names == null) { |
|
60 |
LinkedList<String> list = new LinkedList<String>(); |
|
61 |
InputStream str |
|
62 |
= PlatformClasses.class |
|
63 |
.getResourceAsStream("/com/sun/tools/hat/resources/platform_names.txt"); |
|
64 |
if (str != null) { |
|
65 |
try { |
|
66 |
BufferedReader rdr |
|
67 |
= new BufferedReader(new InputStreamReader(str)); |
|
68 |
for (;;) { |
|
69 |
String s = rdr.readLine(); |
|
70 |
if (s == null) { |
|
71 |
break; |
|
72 |
} else if (s.length() > 0) { |
|
73 |
list.add(s); |
|
74 |
} |
|
75 |
} |
|
76 |
rdr.close(); |
|
77 |
str.close(); |
|
78 |
} catch (IOException ex) { |
|
79 |
ex.printStackTrace(); |
|
80 |
// Shouldn't happen, and if it does, continuing |
|
81 |
// is the right thing to do anyway. |
|
82 |
} |
|
83 |
} |
|
51 | 84 |
names = list.toArray(new String[list.size()]); |
2 | 85 |
} |
86 |
return names; |
|
87 |
} |
|
88 |
||
89 |
||
90 |
public static boolean isPlatformClass(JavaClass clazz) { |
|
91 |
// all classes loaded by bootstrap loader are considered |
|
92 |
// platform classes. In addition, the older name based filtering |
|
93 |
// is also done for compatibility. |
|
94 |
if (clazz.isBootstrap()) { |
|
95 |
return true; |
|
96 |
} |
|
97 |
||
98 |
String name = clazz.getName(); |
|
99 |
// skip even the array classes of the skipped classes. |
|
100 |
if (name.startsWith("[")) { |
|
101 |
int index = name.lastIndexOf('['); |
|
102 |
if (index != -1) { |
|
103 |
if (name.charAt(index + 1) != 'L') { |
|
104 |
// some primitive array. |
|
105 |
return true; |
|
106 |
} |
|
107 |
// skip upto 'L' after the last '['. |
|
108 |
name = name.substring(index + 2); |
|
109 |
} |
|
110 |
} |
|
111 |
String[] nms = getNames(); |
|
112 |
for (int i = 0; i < nms.length; i++) { |
|
113 |
if (name.startsWith(nms[i])) { |
|
114 |
return true; |
|
115 |
} |
|
116 |
} |
|
117 |
return false; |
|
118 |
} |
|
119 |
} |