author | weijun |
Thu, 11 Dec 2014 15:23:02 +0800 | |
changeset 27957 | 24b4e6082f19 |
parent 25859 | 3317bb8137f4 |
child 36511 | 9d0388c6b336 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
5506 | 2 |
* Copyright (c) 2005, 2008, Oracle and/or its affiliates. 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 |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 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 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
||
26 |
package sun.management; |
|
27 |
||
28 |
import javax.management.openmbean.CompositeType; |
|
29 |
import javax.management.openmbean.CompositeData; |
|
30 |
import javax.management.openmbean.CompositeDataSupport; |
|
31 |
import javax.management.openmbean.OpenDataException; |
|
32 |
||
33 |
/** |
|
34 |
* A CompositeData for StackTraceElement for the local management support. |
|
35 |
* This class avoids the performance penalty paid to the |
|
36 |
* construction of a CompositeData use in the local case. |
|
37 |
*/ |
|
38 |
public class StackTraceElementCompositeData extends LazyCompositeData { |
|
39 |
private final StackTraceElement ste; |
|
40 |
||
41 |
private StackTraceElementCompositeData(StackTraceElement ste) { |
|
42 |
this.ste = ste; |
|
43 |
} |
|
44 |
||
45 |
public StackTraceElement getStackTraceElement() { |
|
46 |
return ste; |
|
47 |
} |
|
48 |
||
49 |
public static StackTraceElement from(CompositeData cd) { |
|
50 |
validateCompositeData(cd); |
|
51 |
||
52 |
return new StackTraceElement(getString(cd, CLASS_NAME), |
|
53 |
getString(cd, METHOD_NAME), |
|
54 |
getString(cd, FILE_NAME), |
|
55 |
getInt(cd, LINE_NUMBER)); |
|
56 |
} |
|
57 |
||
58 |
public static CompositeData toCompositeData(StackTraceElement ste) { |
|
59 |
StackTraceElementCompositeData cd = new StackTraceElementCompositeData(ste); |
|
60 |
return cd.getCompositeData(); |
|
61 |
} |
|
62 |
||
63 |
protected CompositeData getCompositeData() { |
|
64 |
// CONTENTS OF THIS ARRAY MUST BE SYNCHRONIZED WITH |
|
65 |
// stackTraceElementItemNames! |
|
66 |
final Object[] stackTraceElementItemValues = { |
|
67 |
ste.getClassName(), |
|
68 |
ste.getMethodName(), |
|
69 |
ste.getFileName(), |
|
25522
10d789df41bb
8049892: Replace uses of 'new Integer()' with appropriate alternative across core classes
prr
parents:
24685
diff
changeset
|
70 |
ste.getLineNumber(), |
24685
215fa91e1b4c
8044461: Cleanup new Boolean and single character strings
rriggs
parents:
5506
diff
changeset
|
71 |
ste.isNativeMethod(), |
2 | 72 |
}; |
73 |
try { |
|
74 |
return new CompositeDataSupport(stackTraceElementCompositeType, |
|
75 |
stackTraceElementItemNames, |
|
76 |
stackTraceElementItemValues); |
|
77 |
} catch (OpenDataException e) { |
|
78 |
// Should never reach here |
|
401
ef01e0dccd63
6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
2
diff
changeset
|
79 |
throw new AssertionError(e); |
2 | 80 |
} |
81 |
} |
|
82 |
||
83 |
private static final CompositeType stackTraceElementCompositeType; |
|
84 |
static { |
|
85 |
try { |
|
86 |
stackTraceElementCompositeType = (CompositeType) |
|
87 |
MappedMXBeanType.toOpenType(StackTraceElement.class); |
|
88 |
} catch (OpenDataException e) { |
|
89 |
// Should never reach here |
|
401
ef01e0dccd63
6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
2
diff
changeset
|
90 |
throw new AssertionError(e); |
2 | 91 |
} |
92 |
} |
|
93 |
||
94 |
// Attribute names |
|
95 |
private static final String CLASS_NAME = "className"; |
|
96 |
private static final String METHOD_NAME = "methodName"; |
|
97 |
private static final String FILE_NAME = "fileName"; |
|
98 |
private static final String LINE_NUMBER = "lineNumber"; |
|
99 |
private static final String NATIVE_METHOD = "nativeMethod"; |
|
100 |
||
101 |
private static final String[] stackTraceElementItemNames = { |
|
102 |
CLASS_NAME, |
|
103 |
METHOD_NAME, |
|
104 |
FILE_NAME, |
|
105 |
LINE_NUMBER, |
|
106 |
NATIVE_METHOD, |
|
107 |
}; |
|
108 |
||
109 |
/** Validate if the input CompositeData has the expected |
|
110 |
* CompositeType (i.e. contain all attributes with expected |
|
111 |
* names and types). |
|
112 |
*/ |
|
113 |
public static void validateCompositeData(CompositeData cd) { |
|
114 |
if (cd == null) { |
|
115 |
throw new NullPointerException("Null CompositeData"); |
|
116 |
} |
|
117 |
||
118 |
if (!isTypeMatched(stackTraceElementCompositeType, cd.getCompositeType())) { |
|
119 |
throw new IllegalArgumentException( |
|
120 |
"Unexpected composite type for StackTraceElement"); |
|
121 |
} |
|
122 |
} |
|
4173
d01972926813
6895875: Missing serialVersionUID in sun.management classes
mchung
parents:
715
diff
changeset
|
123 |
|
d01972926813
6895875: Missing serialVersionUID in sun.management classes
mchung
parents:
715
diff
changeset
|
124 |
private static final long serialVersionUID = -2704607706598396827L; |
2 | 125 |
} |