javax.management.openmbean.CompositeType Java Examples

The following examples show how to use javax.management.openmbean.CompositeType. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GarbageCollectionNotifInfoCompositeData.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
protected CompositeData getCompositeData() {
    // CONTENTS OF THIS ARRAY MUST BE SYNCHRONIZED WITH
    // gcNotifInfoItemNames!
    final Object[] gcNotifInfoItemValues;
    gcNotifInfoItemValues = new Object[] {
        gcNotifInfo.getGcName(),
        gcNotifInfo.getGcAction(),
        gcNotifInfo.getGcCause(),
        GcInfoCompositeData.toCompositeData(gcNotifInfo.getGcInfo())
    };

    CompositeType gict = getCompositeTypeByBuilder();

    try {
        return new CompositeDataSupport(gict,
                                        gcNotifInfoItemNames,
                                        gcNotifInfoItemValues);
    } catch (OpenDataException e) {
        // Should never reach here
        throw new AssertionError(e);
    }
}
 
Example #2
Source File: LazyCompositeData.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
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;
}
 
Example #3
Source File: DefaultMXBeanMappingFactory.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private MXBeanMapping
    makeTabularMapping(Type objType, boolean sortedMap,
                       Type keyType, Type valueType,
                       MXBeanMappingFactory factory)
        throws OpenDataException {

    final String objTypeName = typeName(objType);
    final MXBeanMapping keyMapping = factory.mappingForType(keyType, factory);
    final MXBeanMapping valueMapping = factory.mappingForType(valueType, factory);
    final OpenType<?> keyOpenType = keyMapping.getOpenType();
    final OpenType<?> valueOpenType = valueMapping.getOpenType();
    final CompositeType rowType =
        new CompositeType(objTypeName,
                          objTypeName,
                          keyValueArray,
                          keyValueArray,
                          new OpenType<?>[] {keyOpenType, valueOpenType});
    final TabularType tabularType =
        new TabularType(objTypeName, objTypeName, rowType, keyArray);
    return new TabularMapping(objType, sortedMap, tabularType,
                                keyMapping, valueMapping);
}
 
Example #4
Source File: DefaultMXBeanMappingFactory.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
private MXBeanMapping
    makeTabularMapping(Type objType, boolean sortedMap,
                       Type keyType, Type valueType,
                       MXBeanMappingFactory factory)
        throws OpenDataException {

    final String objTypeName = typeName(objType);
    final MXBeanMapping keyMapping = factory.mappingForType(keyType, factory);
    final MXBeanMapping valueMapping = factory.mappingForType(valueType, factory);
    final OpenType<?> keyOpenType = keyMapping.getOpenType();
    final OpenType<?> valueOpenType = valueMapping.getOpenType();
    final CompositeType rowType =
        new CompositeType(objTypeName,
                          objTypeName,
                          keyValueArray,
                          keyValueArray,
                          new OpenType<?>[] {keyOpenType, valueOpenType});
    final TabularType tabularType =
        new TabularType(objTypeName, objTypeName, rowType, keyArray);
    return new TabularMapping(objType, sortedMap, tabularType,
                                keyMapping, valueMapping);
}
 
Example #5
Source File: DefaultMXBeanMappingFactory.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
@Override
final Object toNonNullOpenValue(Object value)
        throws OpenDataException {
    CompositeType ct = (CompositeType) getOpenType();
    if (value instanceof CompositeDataView)
        return ((CompositeDataView) value).toCompositeData(ct);
    if (value == null)
        return null;

    Object[] values = new Object[getters.length];
    for (int i = 0; i < getters.length; i++) {
        try {
            Object got = MethodUtil.invoke(getters[i], value, (Object[]) null);
            values[i] = getterMappings[i].toOpenValue(got);
        } catch (Exception e) {
            throw openDataException("Error calling getter for " +
                                    itemNames[i] + ": " + e, e);
        }
    }
    return new CompositeDataSupport(ct, itemNames, values);
}
 
Example #6
Source File: StreamServiceTest.java    From cassandra-reaper with Apache License 2.0 6 votes vote down vote up
private CompositeDataSupport makeCompositeData_2_2_12() throws OpenDataException {

    Map<String, Object> fields = Maps.newTreeMap();
    fields.put("currentRxBytes", 0L);
    fields.put("currentTxBytes", 59875L);
    fields.put("description", "Repair");
    fields.put("planId", "636b1490-7d39-11e8-a943-973315b0e477");
    fields.put("rxPercentage", 100.0);
    fields.put("sessions", new CompositeData[] {makeSessions_2_2_12()});
    fields.put("totalRxBytes", 0L);
    fields.put("totalTxBytes", 44670289L);
    fields.put("txPercentage", 0.0);

    // C* 2.2.12 uses the same stream notification format like 2.1.10
    CompositeType compositeType = streamStateType_2_1_20();

    return new CompositeDataSupport(compositeType, fields);
  }
 
Example #7
Source File: DefaultMXBeanMappingFactory.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
@Override
final Object toNonNullOpenValue(Object value)
        throws OpenDataException {
    CompositeType ct = (CompositeType) getOpenType();
    if (value instanceof CompositeDataView)
        return ((CompositeDataView) value).toCompositeData(ct);
    if (value == null)
        return null;

    Object[] values = new Object[getters.length];
    for (int i = 0; i < getters.length; i++) {
        try {
            Object got = MethodUtil.invoke(getters[i], value, (Object[]) null);
            values[i] = getterMappings[i].toOpenValue(got);
        } catch (Exception e) {
            throw openDataException("Error calling getter for " +
                                    itemNames[i] + ": " + e, e);
        }
    }
    return new CompositeDataSupport(ct, itemNames, values);
}
 
Example #8
Source File: DefaultMXBeanMappingFactory.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
@Override
final Object toNonNullOpenValue(Object value)
        throws OpenDataException {
    CompositeType ct = (CompositeType) getOpenType();
    if (value instanceof CompositeDataView)
        return ((CompositeDataView) value).toCompositeData(ct);
    if (value == null)
        return null;

    Object[] values = new Object[getters.length];
    for (int i = 0; i < getters.length; i++) {
        try {
            Object got = MethodUtil.invoke(getters[i], value, (Object[]) null);
            values[i] = getterMappings[i].toOpenValue(got);
        } catch (Exception e) {
            throw openDataException("Error calling getter for " +
                                    itemNames[i] + ": " + e, e);
        }
    }
    return new CompositeDataSupport(ct, itemNames, values);
}
 
Example #9
Source File: DefaultMXBeanMappingFactory.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
CompositeMapping(Class<?> targetClass,
                 CompositeType compositeType,
                 String[] itemNames,
                 Method[] getters,
                 MXBeanMappingFactory factory) throws OpenDataException {
    super(targetClass, compositeType);

    assert(itemNames.length == getters.length);

    this.itemNames = itemNames;
    this.getters = getters;
    this.getterMappings = new MXBeanMapping[getters.length];
    for (int i = 0; i < getters.length; i++) {
        Type retType = getters[i].getGenericReturnType();
        getterMappings[i] = factory.mappingForType(retType, factory);
    }
}
 
Example #10
Source File: GarbageCollectionNotifInfoCompositeData.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
protected CompositeData getCompositeData() {
    // CONTENTS OF THIS ARRAY MUST BE SYNCHRONIZED WITH
    // gcNotifInfoItemNames!
    final Object[] gcNotifInfoItemValues;
    gcNotifInfoItemValues = new Object[] {
        gcNotifInfo.getGcName(),
        gcNotifInfo.getGcAction(),
        gcNotifInfo.getGcCause(),
        GcInfoCompositeData.toCompositeData(gcNotifInfo.getGcInfo())
    };

    CompositeType gict = getCompositeTypeByBuilder();

    try {
        return new CompositeDataSupport(gict,
                                        gcNotifInfoItemNames,
                                        gcNotifInfoItemValues);
    } catch (OpenDataException e) {
        // Should never reach here
        throw new AssertionError(e);
    }
}
 
Example #11
Source File: LocalMBeanServer.java    From tomee with Apache License 2.0 6 votes vote down vote up
public static TabularData tabularData(final String typeName, final String typeDescription, final String[] names, final Object[] values) {
    if (names.length == 0) {
        return null;
    }

    final OpenType<?>[] types = new OpenType<?>[names.length];
    for (int i = 0; i < types.length; i++) {
        types[i] = SimpleType.STRING;
    }

    try {
        final CompositeType ct = new CompositeType(typeName, typeDescription, names, names, types);
        final TabularType type = new TabularType(typeName, typeDescription, ct, names);
        final TabularDataSupport data = new TabularDataSupport(type);

        final CompositeData line = new CompositeDataSupport(ct, names, values);
        data.put(line);

        return data;
    } catch (final OpenDataException e) {
        return null;
    }
}
 
Example #12
Source File: TypeConverters.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public Object fromModelNode(ModelNode node) {
    if (node == null || !node.isDefined()) {
        return null;
    }

    final OpenType<?> openType = getOpenType();
    if (openType instanceof CompositeType) {
        final CompositeType compositeType = (CompositeType)openType;
        //Create a composite
        final Map<String, Object> items = new HashMap<String, Object>();
        for (String attrName : compositeType.keySet()) {
            TypeConverter converter = getConverter(typeNode.get(attrName, TYPE), typeNode.get(attrName, VALUE_TYPE));
            items.put(attrName, converter.fromModelNode(node.get(attrName)));
        }

        try {
            return new CompositeDataSupport(compositeType, items);
        } catch (OpenDataException e) {
            throw new RuntimeException(e);
        }
    } else {
        return node.toJSONString(false);
    }
}
 
Example #13
Source File: DefaultMXBeanMappingFactory.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
private MXBeanMapping
    makeTabularMapping(Type objType, boolean sortedMap,
                       Type keyType, Type valueType,
                       MXBeanMappingFactory factory)
        throws OpenDataException {

    final String objTypeName = typeName(objType);
    final MXBeanMapping keyMapping = factory.mappingForType(keyType, factory);
    final MXBeanMapping valueMapping = factory.mappingForType(valueType, factory);
    final OpenType<?> keyOpenType = keyMapping.getOpenType();
    final OpenType<?> valueOpenType = valueMapping.getOpenType();
    final CompositeType rowType =
        new CompositeType(objTypeName,
                          objTypeName,
                          keyValueArray,
                          keyValueArray,
                          new OpenType<?>[] {keyOpenType, valueOpenType});
    final TabularType tabularType =
        new TabularType(objTypeName, objTypeName, rowType, keyArray);
    return new TabularMapping(objType, sortedMap, tabularType,
                                keyMapping, valueMapping);
}
 
Example #14
Source File: DefaultMXBeanMappingFactory.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
private MXBeanMapping
    makeTabularMapping(Type objType, boolean sortedMap,
                       Type keyType, Type valueType,
                       MXBeanMappingFactory factory)
        throws OpenDataException {

    final String objTypeName = typeName(objType);
    final MXBeanMapping keyMapping = factory.mappingForType(keyType, factory);
    final MXBeanMapping valueMapping = factory.mappingForType(valueType, factory);
    final OpenType<?> keyOpenType = keyMapping.getOpenType();
    final OpenType<?> valueOpenType = valueMapping.getOpenType();
    final CompositeType rowType =
        new CompositeType(objTypeName,
                          objTypeName,
                          keyValueArray,
                          keyValueArray,
                          new OpenType<?>[] {keyOpenType, valueOpenType});
    final TabularType tabularType =
        new TabularType(objTypeName, objTypeName, rowType, keyArray);
    return new TabularMapping(objType, sortedMap, tabularType,
                                keyMapping, valueMapping);
}
 
Example #15
Source File: DefaultMXBeanMappingFactory.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
@Override
final Object toNonNullOpenValue(Object value)
        throws OpenDataException {
    CompositeType ct = (CompositeType) getOpenType();
    if (value instanceof CompositeDataView)
        return ((CompositeDataView) value).toCompositeData(ct);
    if (value == null)
        return null;

    Object[] values = new Object[getters.length];
    for (int i = 0; i < getters.length; i++) {
        try {
            Object got = MethodUtil.invoke(getters[i], value, (Object[]) null);
            values[i] = getterMappings[i].toOpenValue(got);
        } catch (Exception e) {
            throw openDataException("Error calling getter for " +
                                    itemNames[i] + ": " + e, e);
        }
    }
    return new CompositeDataSupport(ct, itemNames, values);
}
 
Example #16
Source File: ExpressionTypeConverterUnitTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Test
public void testJsonObjectInComplexValue() throws Exception {
    ModelNode description = createDescription(ModelType.OBJECT);
    ModelNode complexValueType = new ModelNode();
    complexValueType.get("value", DESCRIPTION).set("A  value");
    complexValueType.get("value", TYPE).set(ModelType.OBJECT);
    description.get(VALUE_TYPE).set(complexValueType);

    TypeConverter converter = getConverter(description);

    CompositeType type = assertCast(CompositeType.class, converter.getOpenType());
    Set<String> keys = type.keySet();
    Assert.assertEquals(1, keys.size());

    Assert.assertEquals(SimpleType.STRING, type.getType("value"));

    ModelNode node = new ModelNode();
    node.get("value", "long").set(1L);
    node.get("value", "string").set("test");

    CompositeData data = assertCast(CompositeData.class, converter.fromModelNode(node));
    Assert.assertEquals(type, data.getCompositeType());
    Assert.assertEquals(ModelNode.fromJSONString(node.toJSONString(false)), converter.toModelNode(data));

}
 
Example #17
Source File: GarbageCollectionNotifInfoCompositeData.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
protected CompositeData getCompositeData() {
    // CONTENTS OF THIS ARRAY MUST BE SYNCHRONIZED WITH
    // gcNotifInfoItemNames!
    final Object[] gcNotifInfoItemValues;
    gcNotifInfoItemValues = new Object[] {
        gcNotifInfo.getGcName(),
        gcNotifInfo.getGcAction(),
        gcNotifInfo.getGcCause(),
        GcInfoCompositeData.toCompositeData(gcNotifInfo.getGcInfo())
    };

    CompositeType gict = getCompositeTypeByBuilder();

    try {
        return new CompositeDataSupport(gict,
                                        gcNotifInfoItemNames,
                                        gcNotifInfoItemValues);
    } catch (OpenDataException e) {
        // Should never reach here
        throw new AssertionError(e);
    }
}
 
Example #18
Source File: LazyCompositeData.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Compares two CompositeTypes and returns true if
 * all items in type1 exist in type2 and their item types
 * are the same.
 * @param type1 the base composite type
 * @param type2 the checked composite type
 * @return {@code true} if all items in type1 exist in type2 and their item
 *         types are the same.
 */
protected static boolean isTypeMatched(CompositeType type1, CompositeType type2) {
    if (type1 == type2) return true;

    // We can't use CompositeType.isValue() since it returns false
    // if the type name doesn't match.
    Set<String> allItems = type1.keySet();

    // Check all items in the type1 exist in type2
    if (!type2.keySet().containsAll(allItems))
        return false;

    return allItems.stream().allMatch(
        item -> isTypeMatched(type1.getType(item), type2.getType(item))
    );
}
 
Example #19
Source File: DefaultMXBeanMappingFactory.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
CompositeMapping(Class<?> targetClass,
                 CompositeType compositeType,
                 String[] itemNames,
                 Method[] getters,
                 MXBeanMappingFactory factory) throws OpenDataException {
    super(targetClass, compositeType);

    assert(itemNames.length == getters.length);

    this.itemNames = itemNames;
    this.getters = getters;
    this.getterMappings = new MXBeanMapping[getters.length];
    for (int i = 0; i < getters.length; i++) {
        Type retType = getters[i].getGenericReturnType();
        getterMappings[i] = factory.mappingForType(retType, factory);
    }
}
 
Example #20
Source File: LazyCompositeData.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
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;
}
 
Example #21
Source File: LegacyTypeConverterUnitTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Test
public void testJsonObjectInComplexValue() throws Exception {
    ModelNode description = createDescription(ModelType.OBJECT);
    ModelNode complexValueType = new ModelNode();
    complexValueType.get("value", DESCRIPTION).set("A  value");
    complexValueType.get("value", TYPE).set(ModelType.OBJECT);
    description.get(VALUE_TYPE).set(complexValueType);

    TypeConverter converter = getConverter(description);

    CompositeType type = assertCast(CompositeType.class, converter.getOpenType());
    Set<String> keys = type.keySet();
    Assert.assertEquals(1, keys.size());

    Assert.assertEquals(SimpleType.STRING, type.getType("value"));

    ModelNode node = new ModelNode();
    node.get("value", "long").set(1L);
    node.get("value", "string").set("test");

    CompositeData data = assertCast(CompositeData.class, converter.fromModelNode(node));
    Assert.assertEquals(type, data.getCompositeType());
    Assert.assertEquals(ModelNode.fromJSONString(node.toJSONString(false)), converter.toModelNode(data));

}
 
Example #22
Source File: GarbageCollectionNotifInfoCompositeData.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
protected CompositeData getCompositeData() {
    // CONTENTS OF THIS ARRAY MUST BE SYNCHRONIZED WITH
    // gcNotifInfoItemNames!
    final Object[] gcNotifInfoItemValues;
    gcNotifInfoItemValues = new Object[] {
        gcNotifInfo.getGcName(),
        gcNotifInfo.getGcAction(),
        gcNotifInfo.getGcCause(),
        GcInfoCompositeData.toCompositeData(gcNotifInfo.getGcInfo())
    };

    CompositeType gict = getCompositeTypeByBuilder();

    try {
        return new CompositeDataSupport(gict,
                                        gcNotifInfoItemNames,
                                        gcNotifInfoItemValues);
    } catch (OpenDataException e) {
        // Should never reach here
        throw new AssertionError(e);
    }
}
 
Example #23
Source File: AttributeArbitraryDataTypeTest.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public CompositeData getCompositeDataAttribute()
    throws OpenDataException {
    CompositeType ct = new CompositeType("CompositeDataAttribute",
                                         "Composite Data Attribute",
                                         itemNames,
                                         itemDescriptions,
                                         itemTypes);
    Object itemValues[] = { ia, da, sa };
    return new CompositeDataSupport(ct, itemNames, itemValues);
}
 
Example #24
Source File: OpenTypeSupport.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
protected <T> TabularType createTabularType(Class<T> type, OpenType openType) throws OpenDataException {
   String typeName = "java.util.Map<java.lang.String, " + type.getName() + ">";
   String[] keyValue = new String[]{"key", "value"};
   OpenType[] openTypes = new OpenType[]{SimpleType.STRING, openType};
   CompositeType rowType = new CompositeType(typeName, typeName, keyValue, keyValue, openTypes);
   return new TabularType(typeName, typeName, rowType, new String[]{"key"});
}
 
Example #25
Source File: TigerMXBean.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
static TabularType make(String typeName, String description,
                        CompositeType rowType, String[] indexNames) {
    try {
        return new TabularType(typeName, description, rowType,
                               indexNames);
    } catch (OpenDataException e) {
        throw new Error(e);
    }
}
 
Example #26
Source File: MerlinMXBean.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public CompositeData toCompositeData(CompositeType ct) {
    try {
        return new CompositeDataSupport(ct, new String[] {"whatsit"},
                                        new String[] {"!" + whatsit});
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
Example #27
Source File: JMXJsonServlet.java    From hadoop with Apache License 2.0 5 votes vote down vote up
private void writeObject(JsonGenerator jg, Object value) throws IOException {
  if(value == null) {
    jg.writeNull();
  } else {
    Class<?> c = value.getClass();
    if (c.isArray()) {
      jg.writeStartArray();
      int len = Array.getLength(value);
      for (int j = 0; j < len; j++) {
        Object item = Array.get(value, j);
        writeObject(jg, item);
      }
      jg.writeEndArray();
    } else if(value instanceof Number) {
      Number n = (Number)value;
      jg.writeNumber(n.toString());
    } else if(value instanceof Boolean) {
      Boolean b = (Boolean)value;
      jg.writeBoolean(b);
    } else if(value instanceof CompositeData) {
      CompositeData cds = (CompositeData)value;
      CompositeType comp = cds.getCompositeType();
      Set<String> keys = comp.keySet();
      jg.writeStartObject();
      for(String key: keys) {
        writeAttribute(jg, key, cds.get(key));
      }
      jg.writeEndObject();
    } else if(value instanceof TabularData) {
      TabularData tds = (TabularData)value;
      jg.writeStartArray();
      for(Object entry : tds.values()) {
        writeObject(jg, entry);
      }
      jg.writeEndArray();
    } else {
      jg.writeString(value.toString());
    }
  }
}
 
Example #28
Source File: LazyCompositeData.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Compares two CompositeTypes and returns true if
 * all items in type1 exist in type2 and their item types
 * are the same.
 */
protected static boolean isTypeMatched(CompositeType type1, CompositeType type2) {
    if (type1 == type2) return true;

    // We can't use CompositeType.isValue() since it returns false
    // if the type name doesn't match.
    Set<String> allItems = type1.keySet();

    // Check all items in the type1 exist in type2
    if (!type2.keySet().containsAll(allItems))
        return false;

    for (String item: allItems) {
        OpenType<?> ot1 = type1.getType(item);
        OpenType<?> ot2 = type2.getType(item);
        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.equals(ot2)) {
            return false;
        }
    }
    return true;
}
 
Example #29
Source File: LazyCompositeData.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Compares two CompositeTypes and returns true if
 * all items in type1 exist in type2 and their item types
 * are the same.
 */
protected static boolean isTypeMatched(CompositeType type1, CompositeType type2) {
    if (type1 == type2) return true;

    // We can't use CompositeType.isValue() since it returns false
    // if the type name doesn't match.
    Set<String> allItems = type1.keySet();

    // Check all items in the type1 exist in type2
    if (!type2.keySet().containsAll(allItems))
        return false;

    for (String item: allItems) {
        OpenType<?> ot1 = type1.getType(item);
        OpenType<?> ot2 = type2.getType(item);
        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.equals(ot2)) {
            return false;
        }
    }
    return true;
}
 
Example #30
Source File: MerlinMXBean.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
static CompositeType make(String className,
                          String description,
                          String[] itemNames,
                          String[] itemDescriptions,
                          OpenType[] itemTypes) {
    try {
        return new CompositeType(className,
                                 description,
                                 itemNames,
                                 itemDescriptions,
                                 itemTypes);
    } catch (OpenDataException e) {
        throw new Error(e);
    }
}