author | redestad |
Tue, 08 Oct 2019 15:48:36 +0200 | |
changeset 58499 | d62c7224d5b7 |
parent 47216 | 71c04702a3d5 |
child 58766 | 54ffb15c4839 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
30355
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
25859
diff
changeset
|
2 |
* Copyright (c) 2004, 2015, 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 java.io.Serializable; |
|
29 |
import java.util.*; |
|
33260
af1ca24593aa
8139870: sun.management.LazyCompositeData.isTypeMatched() fails for composite types with items of ArrayType
jbachorik
parents:
30355
diff
changeset
|
30 |
import javax.management.openmbean.ArrayType; |
2 | 31 |
import javax.management.openmbean.CompositeData; |
32 |
import javax.management.openmbean.CompositeType; |
|
33 |
import javax.management.openmbean.OpenType; |
|
34 |
import javax.management.openmbean.TabularType; |
|
35 |
||
36 |
/** |
|
37 |
* This abstract class provides the implementation of the CompositeData |
|
38 |
* interface. A CompositeData object will be lazily created only when |
|
39 |
* the CompositeData interface is used. |
|
40 |
* |
|
41 |
* Classes that extends this abstract class will implement the |
|
42 |
* getCompositeData() method. The object returned by the |
|
43 |
* getCompositeData() is an instance of CompositeData such that |
|
44 |
* the instance serializes itself as the type CompositeDataSupport. |
|
45 |
*/ |
|
46 |
public abstract class LazyCompositeData |
|
47 |
implements CompositeData, Serializable { |
|
48 |
||
49 |
private CompositeData compositeData; |
|
50 |
||
51 |
// Implementation of the CompositeData interface |
|
33260
af1ca24593aa
8139870: sun.management.LazyCompositeData.isTypeMatched() fails for composite types with items of ArrayType
jbachorik
parents:
30355
diff
changeset
|
52 |
@Override |
2 | 53 |
public boolean containsKey(String key) { |
54 |
return compositeData().containsKey(key); |
|
55 |
} |
|
56 |
||
33260
af1ca24593aa
8139870: sun.management.LazyCompositeData.isTypeMatched() fails for composite types with items of ArrayType
jbachorik
parents:
30355
diff
changeset
|
57 |
@Override |
2 | 58 |
public boolean containsValue(Object value) { |
59 |
return compositeData().containsValue(value); |
|
60 |
} |
|
61 |
||
33260
af1ca24593aa
8139870: sun.management.LazyCompositeData.isTypeMatched() fails for composite types with items of ArrayType
jbachorik
parents:
30355
diff
changeset
|
62 |
@Override |
2 | 63 |
public boolean equals(Object obj) { |
64 |
return compositeData().equals(obj); |
|
65 |
} |
|
66 |
||
33260
af1ca24593aa
8139870: sun.management.LazyCompositeData.isTypeMatched() fails for composite types with items of ArrayType
jbachorik
parents:
30355
diff
changeset
|
67 |
@Override |
2 | 68 |
public Object get(String key) { |
69 |
return compositeData().get(key); |
|
70 |
} |
|
71 |
||
33260
af1ca24593aa
8139870: sun.management.LazyCompositeData.isTypeMatched() fails for composite types with items of ArrayType
jbachorik
parents:
30355
diff
changeset
|
72 |
@Override |
2 | 73 |
public Object[] getAll(String[] keys) { |
74 |
return compositeData().getAll(keys); |
|
75 |
} |
|
76 |
||
33260
af1ca24593aa
8139870: sun.management.LazyCompositeData.isTypeMatched() fails for composite types with items of ArrayType
jbachorik
parents:
30355
diff
changeset
|
77 |
@Override |
2 | 78 |
public CompositeType getCompositeType() { |
79 |
return compositeData().getCompositeType(); |
|
80 |
} |
|
81 |
||
33260
af1ca24593aa
8139870: sun.management.LazyCompositeData.isTypeMatched() fails for composite types with items of ArrayType
jbachorik
parents:
30355
diff
changeset
|
82 |
@Override |
2 | 83 |
public int hashCode() { |
84 |
return compositeData().hashCode(); |
|
85 |
} |
|
86 |
||
33260
af1ca24593aa
8139870: sun.management.LazyCompositeData.isTypeMatched() fails for composite types with items of ArrayType
jbachorik
parents:
30355
diff
changeset
|
87 |
@Override |
2 | 88 |
public String toString() { |
89 |
/** FIXME: What should this be?? */ |
|
90 |
return compositeData().toString(); |
|
91 |
} |
|
92 |
||
33260
af1ca24593aa
8139870: sun.management.LazyCompositeData.isTypeMatched() fails for composite types with items of ArrayType
jbachorik
parents:
30355
diff
changeset
|
93 |
@Override |
11530
a9d059c15b80
7117570: Warnings in sun.mangement.* and its subpackages
mchung
parents:
5506
diff
changeset
|
94 |
public Collection<?> values() { |
2 | 95 |
return compositeData().values(); |
96 |
} |
|
97 |
||
98 |
/* Lazy creation of a CompositeData object |
|
99 |
* only when the CompositeData interface is used. |
|
100 |
*/ |
|
101 |
private synchronized CompositeData compositeData() { |
|
102 |
if (compositeData != null) |
|
103 |
return compositeData; |
|
104 |
compositeData = getCompositeData(); |
|
105 |
return compositeData; |
|
106 |
} |
|
107 |
||
108 |
/** |
|
109 |
* Designate to a CompositeData object when writing to an |
|
110 |
* output stream during serialization so that the receiver |
|
111 |
* only requires JMX 1.2 classes but not any implementation |
|
112 |
* specific class. |
|
113 |
*/ |
|
114 |
protected Object writeReplace() throws java.io.ObjectStreamException { |
|
115 |
return compositeData(); |
|
116 |
} |
|
117 |
||
118 |
/** |
|
119 |
* Returns the CompositeData representing this object. |
|
120 |
* The returned CompositeData object must be an instance |
|
121 |
* of javax.management.openmbean.CompositeDataSupport class |
|
122 |
* so that no implementation specific class is required |
|
123 |
* for unmarshalling besides JMX 1.2 classes. |
|
124 |
*/ |
|
125 |
protected abstract CompositeData getCompositeData(); |
|
126 |
||
127 |
// Helper methods |
|
30355
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
25859
diff
changeset
|
128 |
public static String getString(CompositeData cd, String itemName) { |
2 | 129 |
if (cd == null) |
130 |
throw new IllegalArgumentException("Null CompositeData"); |
|
131 |
||
132 |
return (String) cd.get(itemName); |
|
133 |
} |
|
134 |
||
30355
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
25859
diff
changeset
|
135 |
public static boolean getBoolean(CompositeData cd, String itemName) { |
2 | 136 |
if (cd == null) |
137 |
throw new IllegalArgumentException("Null CompositeData"); |
|
138 |
||
33260
af1ca24593aa
8139870: sun.management.LazyCompositeData.isTypeMatched() fails for composite types with items of ArrayType
jbachorik
parents:
30355
diff
changeset
|
139 |
return ((Boolean) cd.get(itemName)); |
2 | 140 |
} |
141 |
||
30355
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
25859
diff
changeset
|
142 |
public static long getLong(CompositeData cd, String itemName) { |
2 | 143 |
if (cd == null) |
144 |
throw new IllegalArgumentException("Null CompositeData"); |
|
145 |
||
33260
af1ca24593aa
8139870: sun.management.LazyCompositeData.isTypeMatched() fails for composite types with items of ArrayType
jbachorik
parents:
30355
diff
changeset
|
146 |
return ((Long) cd.get(itemName)); |
2 | 147 |
} |
148 |
||
30355
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
25859
diff
changeset
|
149 |
public static int getInt(CompositeData cd, String itemName) { |
2 | 150 |
if (cd == null) |
151 |
throw new IllegalArgumentException("Null CompositeData"); |
|
152 |
||
33260
af1ca24593aa
8139870: sun.management.LazyCompositeData.isTypeMatched() fails for composite types with items of ArrayType
jbachorik
parents:
30355
diff
changeset
|
153 |
return ((Integer) cd.get(itemName)); |
2 | 154 |
} |
155 |
||
156 |
/** |
|
157 |
* Compares two CompositeTypes and returns true if |
|
158 |
* all items in type1 exist in type2 and their item types |
|
159 |
* are the same. |
|
33260
af1ca24593aa
8139870: sun.management.LazyCompositeData.isTypeMatched() fails for composite types with items of ArrayType
jbachorik
parents:
30355
diff
changeset
|
160 |
* @param type1 the base composite type |
af1ca24593aa
8139870: sun.management.LazyCompositeData.isTypeMatched() fails for composite types with items of ArrayType
jbachorik
parents:
30355
diff
changeset
|
161 |
* @param type2 the checked composite type |
af1ca24593aa
8139870: sun.management.LazyCompositeData.isTypeMatched() fails for composite types with items of ArrayType
jbachorik
parents:
30355
diff
changeset
|
162 |
* @return {@code true} if all items in type1 exist in type2 and their item |
af1ca24593aa
8139870: sun.management.LazyCompositeData.isTypeMatched() fails for composite types with items of ArrayType
jbachorik
parents:
30355
diff
changeset
|
163 |
* types are the same. |
2 | 164 |
*/ |
165 |
protected static boolean isTypeMatched(CompositeType type1, CompositeType type2) { |
|
166 |
if (type1 == type2) return true; |
|
167 |
||
168 |
// We can't use CompositeType.isValue() since it returns false |
|
169 |
// if the type name doesn't match. |
|
11530
a9d059c15b80
7117570: Warnings in sun.mangement.* and its subpackages
mchung
parents:
5506
diff
changeset
|
170 |
Set<String> allItems = type1.keySet(); |
2 | 171 |
|
172 |
// Check all items in the type1 exist in type2 |
|
173 |
if (!type2.keySet().containsAll(allItems)) |
|
174 |
return false; |
|
175 |
||
33260
af1ca24593aa
8139870: sun.management.LazyCompositeData.isTypeMatched() fails for composite types with items of ArrayType
jbachorik
parents:
30355
diff
changeset
|
176 |
return allItems.stream().allMatch( |
af1ca24593aa
8139870: sun.management.LazyCompositeData.isTypeMatched() fails for composite types with items of ArrayType
jbachorik
parents:
30355
diff
changeset
|
177 |
item -> isTypeMatched(type1.getType(item), type2.getType(item)) |
af1ca24593aa
8139870: sun.management.LazyCompositeData.isTypeMatched() fails for composite types with items of ArrayType
jbachorik
parents:
30355
diff
changeset
|
178 |
); |
2 | 179 |
} |
180 |
||
181 |
protected static boolean isTypeMatched(TabularType type1, TabularType type2) { |
|
182 |
if (type1 == type2) return true; |
|
183 |
||
11530
a9d059c15b80
7117570: Warnings in sun.mangement.* and its subpackages
mchung
parents:
5506
diff
changeset
|
184 |
List<String> list1 = type1.getIndexNames(); |
a9d059c15b80
7117570: Warnings in sun.mangement.* and its subpackages
mchung
parents:
5506
diff
changeset
|
185 |
List<String> list2 = type2.getIndexNames(); |
2 | 186 |
|
187 |
// check if the list of index names are the same |
|
188 |
if (!list1.equals(list2)) |
|
189 |
return false; |
|
190 |
||
191 |
return isTypeMatched(type1.getRowType(), type2.getRowType()); |
|
192 |
} |
|
4173
d01972926813
6895875: Missing serialVersionUID in sun.management classes
mchung
parents:
2
diff
changeset
|
193 |
|
33260
af1ca24593aa
8139870: sun.management.LazyCompositeData.isTypeMatched() fails for composite types with items of ArrayType
jbachorik
parents:
30355
diff
changeset
|
194 |
protected static boolean isTypeMatched(ArrayType<?> type1, ArrayType<?> type2) { |
af1ca24593aa
8139870: sun.management.LazyCompositeData.isTypeMatched() fails for composite types with items of ArrayType
jbachorik
parents:
30355
diff
changeset
|
195 |
if (type1 == type2) return true; |
af1ca24593aa
8139870: sun.management.LazyCompositeData.isTypeMatched() fails for composite types with items of ArrayType
jbachorik
parents:
30355
diff
changeset
|
196 |
|
af1ca24593aa
8139870: sun.management.LazyCompositeData.isTypeMatched() fails for composite types with items of ArrayType
jbachorik
parents:
30355
diff
changeset
|
197 |
int dim1 = type1.getDimension(); |
af1ca24593aa
8139870: sun.management.LazyCompositeData.isTypeMatched() fails for composite types with items of ArrayType
jbachorik
parents:
30355
diff
changeset
|
198 |
int dim2 = type2.getDimension(); |
af1ca24593aa
8139870: sun.management.LazyCompositeData.isTypeMatched() fails for composite types with items of ArrayType
jbachorik
parents:
30355
diff
changeset
|
199 |
|
af1ca24593aa
8139870: sun.management.LazyCompositeData.isTypeMatched() fails for composite types with items of ArrayType
jbachorik
parents:
30355
diff
changeset
|
200 |
// check if the array dimensions are the same |
af1ca24593aa
8139870: sun.management.LazyCompositeData.isTypeMatched() fails for composite types with items of ArrayType
jbachorik
parents:
30355
diff
changeset
|
201 |
if (dim1 != dim2) |
af1ca24593aa
8139870: sun.management.LazyCompositeData.isTypeMatched() fails for composite types with items of ArrayType
jbachorik
parents:
30355
diff
changeset
|
202 |
return false; |
af1ca24593aa
8139870: sun.management.LazyCompositeData.isTypeMatched() fails for composite types with items of ArrayType
jbachorik
parents:
30355
diff
changeset
|
203 |
|
af1ca24593aa
8139870: sun.management.LazyCompositeData.isTypeMatched() fails for composite types with items of ArrayType
jbachorik
parents:
30355
diff
changeset
|
204 |
return isTypeMatched(type1.getElementOpenType(), type2.getElementOpenType()); |
af1ca24593aa
8139870: sun.management.LazyCompositeData.isTypeMatched() fails for composite types with items of ArrayType
jbachorik
parents:
30355
diff
changeset
|
205 |
} |
af1ca24593aa
8139870: sun.management.LazyCompositeData.isTypeMatched() fails for composite types with items of ArrayType
jbachorik
parents:
30355
diff
changeset
|
206 |
|
af1ca24593aa
8139870: sun.management.LazyCompositeData.isTypeMatched() fails for composite types with items of ArrayType
jbachorik
parents:
30355
diff
changeset
|
207 |
private static boolean isTypeMatched(OpenType<?> ot1, OpenType<?> ot2) { |
af1ca24593aa
8139870: sun.management.LazyCompositeData.isTypeMatched() fails for composite types with items of ArrayType
jbachorik
parents:
30355
diff
changeset
|
208 |
if (ot1 instanceof CompositeType) { |
af1ca24593aa
8139870: sun.management.LazyCompositeData.isTypeMatched() fails for composite types with items of ArrayType
jbachorik
parents:
30355
diff
changeset
|
209 |
if (! (ot2 instanceof CompositeType)) |
af1ca24593aa
8139870: sun.management.LazyCompositeData.isTypeMatched() fails for composite types with items of ArrayType
jbachorik
parents:
30355
diff
changeset
|
210 |
return false; |
af1ca24593aa
8139870: sun.management.LazyCompositeData.isTypeMatched() fails for composite types with items of ArrayType
jbachorik
parents:
30355
diff
changeset
|
211 |
if (!isTypeMatched((CompositeType) ot1, (CompositeType) ot2)) |
af1ca24593aa
8139870: sun.management.LazyCompositeData.isTypeMatched() fails for composite types with items of ArrayType
jbachorik
parents:
30355
diff
changeset
|
212 |
return false; |
af1ca24593aa
8139870: sun.management.LazyCompositeData.isTypeMatched() fails for composite types with items of ArrayType
jbachorik
parents:
30355
diff
changeset
|
213 |
} else if (ot1 instanceof TabularType) { |
af1ca24593aa
8139870: sun.management.LazyCompositeData.isTypeMatched() fails for composite types with items of ArrayType
jbachorik
parents:
30355
diff
changeset
|
214 |
if (! (ot2 instanceof TabularType)) |
af1ca24593aa
8139870: sun.management.LazyCompositeData.isTypeMatched() fails for composite types with items of ArrayType
jbachorik
parents:
30355
diff
changeset
|
215 |
return false; |
af1ca24593aa
8139870: sun.management.LazyCompositeData.isTypeMatched() fails for composite types with items of ArrayType
jbachorik
parents:
30355
diff
changeset
|
216 |
if (!isTypeMatched((TabularType) ot1, (TabularType) ot2)) |
af1ca24593aa
8139870: sun.management.LazyCompositeData.isTypeMatched() fails for composite types with items of ArrayType
jbachorik
parents:
30355
diff
changeset
|
217 |
return false; |
af1ca24593aa
8139870: sun.management.LazyCompositeData.isTypeMatched() fails for composite types with items of ArrayType
jbachorik
parents:
30355
diff
changeset
|
218 |
} else if (ot1 instanceof ArrayType) { |
af1ca24593aa
8139870: sun.management.LazyCompositeData.isTypeMatched() fails for composite types with items of ArrayType
jbachorik
parents:
30355
diff
changeset
|
219 |
if (! (ot2 instanceof ArrayType)) |
af1ca24593aa
8139870: sun.management.LazyCompositeData.isTypeMatched() fails for composite types with items of ArrayType
jbachorik
parents:
30355
diff
changeset
|
220 |
return false; |
af1ca24593aa
8139870: sun.management.LazyCompositeData.isTypeMatched() fails for composite types with items of ArrayType
jbachorik
parents:
30355
diff
changeset
|
221 |
if (!isTypeMatched((ArrayType<?>) ot1, (ArrayType<?>) ot2)) { |
af1ca24593aa
8139870: sun.management.LazyCompositeData.isTypeMatched() fails for composite types with items of ArrayType
jbachorik
parents:
30355
diff
changeset
|
222 |
return false; |
af1ca24593aa
8139870: sun.management.LazyCompositeData.isTypeMatched() fails for composite types with items of ArrayType
jbachorik
parents:
30355
diff
changeset
|
223 |
} |
af1ca24593aa
8139870: sun.management.LazyCompositeData.isTypeMatched() fails for composite types with items of ArrayType
jbachorik
parents:
30355
diff
changeset
|
224 |
} else if (!ot1.equals(ot2)) { |
af1ca24593aa
8139870: sun.management.LazyCompositeData.isTypeMatched() fails for composite types with items of ArrayType
jbachorik
parents:
30355
diff
changeset
|
225 |
return false; |
af1ca24593aa
8139870: sun.management.LazyCompositeData.isTypeMatched() fails for composite types with items of ArrayType
jbachorik
parents:
30355
diff
changeset
|
226 |
} |
af1ca24593aa
8139870: sun.management.LazyCompositeData.isTypeMatched() fails for composite types with items of ArrayType
jbachorik
parents:
30355
diff
changeset
|
227 |
return true; |
af1ca24593aa
8139870: sun.management.LazyCompositeData.isTypeMatched() fails for composite types with items of ArrayType
jbachorik
parents:
30355
diff
changeset
|
228 |
} |
af1ca24593aa
8139870: sun.management.LazyCompositeData.isTypeMatched() fails for composite types with items of ArrayType
jbachorik
parents:
30355
diff
changeset
|
229 |
|
4173
d01972926813
6895875: Missing serialVersionUID in sun.management classes
mchung
parents:
2
diff
changeset
|
230 |
private static final long serialVersionUID = -2190411934472666714L; |
2 | 231 |
} |