Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/java.management/share/classes/javax/management/ClassAttributeValueExp.java
41155 views
1
/*
2
* Copyright (c) 1999, 2021, Oracle and/or its affiliates. All rights reserved.
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. Oracle designates this
8
* particular file as subject to the "Classpath" exception as provided
9
* by Oracle 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 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.
24
*/
25
26
package javax.management;
27
28
import java.security.AccessController;
29
30
import com.sun.jmx.mbeanserver.GetPropertyAction;
31
32
/**
33
* This class represents the name of the Java implementation class of
34
* the MBean. It is used for performing queries based on the class of
35
* the MBean.
36
* @serial include
37
*
38
* <p>The <b>serialVersionUID</b> of this class is <code>-1081892073854801359L</code>.
39
*
40
* @since 1.5
41
*/
42
@SuppressWarnings("serial") // serialVersionUID is not constant
43
class ClassAttributeValueExp extends AttributeValueExp {
44
45
// Serialization compatibility stuff:
46
// Two serial forms are supported in this class. The selected form depends
47
// on system property "jmx.serial.form":
48
// - "1.0" for JMX 1.0
49
// - any other value for JMX 1.1 and higher
50
//
51
// Serial version for old serial form
52
private static final long oldSerialVersionUID = -2212731951078526753L;
53
//
54
// Serial version for new serial form
55
private static final long newSerialVersionUID = -1081892073854801359L;
56
57
private static final long serialVersionUID;
58
static {
59
boolean compat = false;
60
try {
61
GetPropertyAction act = new GetPropertyAction("jmx.serial.form");
62
@SuppressWarnings("removal")
63
String form = AccessController.doPrivileged(act);
64
compat = (form != null && form.equals("1.0"));
65
} catch (Exception e) {
66
// OK: exception means no compat with 1.0, too bad
67
}
68
if (compat)
69
serialVersionUID = oldSerialVersionUID;
70
else
71
serialVersionUID = newSerialVersionUID;
72
}
73
74
/**
75
* @serial The name of the attribute
76
*
77
* <p>The <b>serialVersionUID</b> of this class is <code>-1081892073854801359L</code>.
78
*/
79
private String attr;
80
81
/**
82
* Basic Constructor.
83
*/
84
public ClassAttributeValueExp() {
85
/* Compatibility: we have an attr field that we must hold on to
86
for serial compatibility, even though our parent has one too. */
87
super("Class");
88
attr = "Class";
89
}
90
91
92
/**
93
* Applies the ClassAttributeValueExp on an MBean. Returns the name of
94
* the Java implementation class of the MBean.
95
*
96
* @param name The name of the MBean on which the ClassAttributeValueExp will be applied.
97
*
98
* @return The ValueExp.
99
*
100
* @exception BadAttributeValueExpException
101
* @exception InvalidApplicationException
102
*/
103
public ValueExp apply(ObjectName name)
104
throws BadStringOperationException, BadBinaryOpValueExpException,
105
BadAttributeValueExpException, InvalidApplicationException {
106
// getAttribute(name);
107
Object result = getValue(name);
108
if (result instanceof String) {
109
return new StringValueExp((String)result);
110
} else {
111
throw new BadAttributeValueExpException(result);
112
}
113
}
114
115
/**
116
* Returns the string "Class" representing its value
117
*/
118
public String toString() {
119
return attr;
120
}
121
122
123
protected Object getValue(ObjectName name) {
124
try {
125
// Get the class of the object
126
MBeanServer server = QueryEval.getMBeanServer();
127
return server.getObjectInstance(name).getClassName();
128
} catch (Exception re) {
129
return null;
130
/* In principle the MBean does exist because otherwise we
131
wouldn't be evaluating the query on it. But it could
132
potentially have disappeared in between the time we
133
discovered it and the time the query is evaluated.
134
135
Also, the exception could be a SecurityException.
136
137
Returning null from here will cause
138
BadAttributeValueExpException, which will in turn cause
139
this MBean to be omitted from the query result. */
140
}
141
}
142
143
}
144
145