|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
|
|
package sun.management; |
|
|
|
import java.io.Serializable; |
|
import java.util.*; |
|
import javax.management.openmbean.ArrayType; |
|
import javax.management.openmbean.CompositeData; |
|
import javax.management.openmbean.CompositeType; |
|
import javax.management.openmbean.OpenType; |
|
import javax.management.openmbean.TabularType; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public abstract class LazyCompositeData |
|
implements CompositeData, Serializable { |
|
|
|
private CompositeData compositeData; |
|
|
|
|
|
@Override |
|
public boolean containsKey(String key) { |
|
return compositeData().containsKey(key); |
|
} |
|
|
|
@Override |
|
public boolean containsValue(Object value) { |
|
return compositeData().containsValue(value); |
|
} |
|
|
|
@Override |
|
public boolean equals(Object obj) { |
|
return compositeData().equals(obj); |
|
} |
|
|
|
@Override |
|
public Object get(String key) { |
|
return compositeData().get(key); |
|
} |
|
|
|
@Override |
|
public Object[] getAll(String[] keys) { |
|
return compositeData().getAll(keys); |
|
} |
|
|
|
@Override |
|
public CompositeType getCompositeType() { |
|
return compositeData().getCompositeType(); |
|
} |
|
|
|
@Override |
|
public int hashCode() { |
|
return compositeData().hashCode(); |
|
} |
|
|
|
@Override |
|
public String toString() { |
|
|
|
return compositeData().toString(); |
|
} |
|
|
|
@Override |
|
public Collection<?> values() { |
|
return compositeData().values(); |
|
} |
|
|
|
|
|
|
|
*/ |
|
private synchronized CompositeData compositeData() { |
|
if (compositeData != null) |
|
return compositeData; |
|
compositeData = getCompositeData(); |
|
return compositeData; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
protected Object writeReplace() throws java.io.ObjectStreamException { |
|
return compositeData(); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
protected abstract CompositeData getCompositeData(); |
|
|
|
|
|
static String getString(CompositeData cd, String itemName) { |
|
if (cd == null) |
|
throw new IllegalArgumentException("Null CompositeData"); |
|
|
|
return (String) cd.get(itemName); |
|
} |
|
|
|
static boolean getBoolean(CompositeData cd, String itemName) { |
|
if (cd == null) |
|
throw new IllegalArgumentException("Null CompositeData"); |
|
|
|
return ((Boolean) cd.get(itemName)); |
|
} |
|
|
|
static long getLong(CompositeData cd, String itemName) { |
|
if (cd == null) |
|
throw new IllegalArgumentException("Null CompositeData"); |
|
|
|
return ((Long) cd.get(itemName)); |
|
} |
|
|
|
static int getInt(CompositeData cd, String itemName) { |
|
if (cd == null) |
|
throw new IllegalArgumentException("Null CompositeData"); |
|
|
|
return ((Integer) cd.get(itemName)); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
protected static boolean isTypeMatched(CompositeType type1, CompositeType type2) { |
|
if (type1 == type2) return true; |
|
|
|
// We can't use CompositeType.isValue() since it returns false |
|
|
|
Set<String> allItems = type1.keySet(); |
|
|
|
|
|
if (!type2.keySet().containsAll(allItems)) |
|
return false; |
|
|
|
return allItems.stream().allMatch( |
|
item -> isTypeMatched(type1.getType(item), type2.getType(item)) |
|
); |
|
} |
|
|
|
protected static boolean isTypeMatched(TabularType type1, TabularType type2) { |
|
if (type1 == type2) return true; |
|
|
|
List<String> list1 = type1.getIndexNames(); |
|
List<String> list2 = type2.getIndexNames(); |
|
|
|
|
|
if (!list1.equals(list2)) |
|
return false; |
|
|
|
return isTypeMatched(type1.getRowType(), type2.getRowType()); |
|
} |
|
|
|
protected static boolean isTypeMatched(ArrayType<?> type1, ArrayType<?> type2) { |
|
if (type1 == type2) return true; |
|
|
|
int dim1 = type1.getDimension(); |
|
int dim2 = type2.getDimension(); |
|
|
|
|
|
if (dim1 != dim2) |
|
return false; |
|
|
|
return isTypeMatched(type1.getElementOpenType(), type2.getElementOpenType()); |
|
} |
|
|
|
private static boolean isTypeMatched(OpenType<?> ot1, OpenType<?> ot2) { |
|
if (ot1 instanceof CompositeType) { |
|
if (! (ot2 instanceof CompositeType)) |
|
return false; |
|
if (!isTypeMatched((CompositeType) ot1, (CompositeType) ot2)) |
|
return false; |
|
} else if (ot1 instanceof TabularType) { |
|
if (! (ot2 instanceof TabularType)) |
|
return false; |
|
if (!isTypeMatched((TabularType) ot1, (TabularType) ot2)) |
|
return false; |
|
} else if (ot1 instanceof ArrayType) { |
|
if (! (ot2 instanceof ArrayType)) |
|
return false; |
|
if (!isTypeMatched((ArrayType<?>) ot1, (ArrayType<?>) ot2)) { |
|
return false; |
|
} |
|
} else if (!ot1.equals(ot2)) { |
|
return false; |
|
} |
|
return true; |
|
} |
|
|
|
private static final long serialVersionUID = -2190411934472666714L; |
|
} |