java类javax.management.openmbean.ArrayType的实例源码

ThreadInfoTest.java 文件源码 项目:cn1 阅读 19 收藏 0 点赞 0 评论 0
public void test_from_scenario12() throws Exception {
    initialValues[8] = null;
    ArrayType stackTraceArray = new ArrayType(1, stackTraceElementType);
    OpenType[] types = { SimpleType.LONG, SimpleType.STRING,
            SimpleType.STRING, SimpleType.BOOLEAN, SimpleType.BOOLEAN,
            SimpleType.LONG, SimpleType.LONG, SimpleType.LONG,
            SimpleType.LONG, SimpleType.STRING, SimpleType.LONG,
            SimpleType.STRING, stackTraceArray, SimpleType.STRING };
    CompositeType compositeType = getCompositeType(initialNames, types);
    CompositeData data = new CompositeDataSupport(compositeType,
            initialNames, initialValues);
    try {
        ThreadInfo.from(data);
        fail("should throw NullPointerException");
    } catch (NullPointerException e) {
        // Expected
    }
}
ThreadInfoTest.java 文件源码 项目:cn1 阅读 16 收藏 0 点赞 0 评论 0
public void test_from_scenario14() throws Exception {
    initialValues[10] = null;
    ArrayType stackTraceArray = new ArrayType(1, stackTraceElementType);
    OpenType[] types = { SimpleType.LONG, SimpleType.STRING,
            SimpleType.STRING, SimpleType.BOOLEAN, SimpleType.BOOLEAN,
            SimpleType.LONG, SimpleType.LONG, SimpleType.LONG,
            SimpleType.LONG, SimpleType.STRING, SimpleType.LONG,
            SimpleType.STRING, stackTraceArray, SimpleType.STRING };
    CompositeType compositeType = getCompositeType(initialNames, types);
    CompositeData data = new CompositeDataSupport(compositeType,
            initialNames, initialValues);
    try {
        ThreadInfo.from(data);
        fail("should throw NullPointerException");
    } catch (NullPointerException e) {
        // Expected
    }
}
ThreadInfoTest.java 文件源码 项目:cn1 阅读 17 收藏 0 点赞 0 评论 0
public void test_from_scenario16() throws Exception {
    initialValues[12] = null;
    ArrayType stackTraceArray = new ArrayType(1, stackTraceElementType);
    OpenType[] types = { SimpleType.LONG, SimpleType.STRING,
            SimpleType.STRING, SimpleType.BOOLEAN, SimpleType.BOOLEAN,
            SimpleType.LONG, SimpleType.LONG, SimpleType.LONG,
            SimpleType.LONG, SimpleType.STRING, SimpleType.LONG,
            SimpleType.STRING, stackTraceArray, SimpleType.STRING };
    CompositeType compositeType = getCompositeType(initialNames, types);
    CompositeData data = new CompositeDataSupport(compositeType,
            initialNames, initialValues);
    try {
        ThreadInfo.from(data);
        fail("should throw IllegalArgumentException");
    } catch (IllegalArgumentException e) {
        // Expected
    }
}
ExpressionTypeConverterUnitTestCase.java 文件源码 项目:wildfly-core 阅读 20 收藏 0 点赞 0 评论 0
@Test
public void testByteArrayObject() throws Exception {
    ModelNode description = createDescription(ModelType.OBJECT, ModelType.BYTES);
    TypeConverter converter = getConverter(description);

    assertMapType(assertCast(TabularType.class, converter.getOpenType()), SimpleType.STRING, ArrayType.getPrimitiveArrayType(byte[].class));

    ModelNode node = new ModelNode();
    node.get("one").set(new byte[] {1,2});
    node.get("two").set(new byte[] {3,4});

    TabularData tabularData = assertCast(TabularData.class, converter.fromModelNode(node));
    Assert.assertEquals(2, tabularData.size());
    Assert.assertTrue(Arrays.equals(new byte[] {1,2}, (byte[])tabularData.get(new Object[] {"one"}).get("value")));
    Assert.assertTrue(Arrays.equals(new byte[] {3,4}, (byte[])tabularData.get(new Object[] {"two"}).get("value")));

    //Allow plain map as well? Yeah why not!
    Map<String, byte[]> map = new HashMap<String, byte[]>();
    map.put("one", new byte[] {1,2});
    map.put("two", new byte[] {3,4});
    Assert.assertEquals(node, converter.toModelNode(map));
}
ExpressionTypeConverterUnitTestCase.java 文件源码 项目:wildfly-core 阅读 21 收藏 0 点赞 0 评论 0
@Test
public void testSimpleTypeExpressionList() throws Exception {
    ModelNode description = createDescription(ModelType.LIST, ModelType.INT);
    description.get(EXPRESSIONS_ALLOWED).set(true);
    TypeConverter converter = getConverter(description);
    assertCast(ArrayType.class, converter.getOpenType());

    ModelNode node = new ModelNode();
    node.add().set(new ValueExpression("${this.should.not.exist.!!!!!:1}"));
    node.add().set(new ValueExpression("${this.should.not.exist.!!!!!:2}"));

    String[] data = assertCast(String[].class, converter.fromModelNode(node));
    Assert.assertEquals("${this.should.not.exist.!!!!!:1}", data[0]);
    Assert.assertEquals("${this.should.not.exist.!!!!!:2}", data[1]);

    ModelNode newNode = converter.toModelNode(data);
    Assert.assertEquals(node, newNode);
}
LegacyTypeConverterUnitTestCase.java 文件源码 项目:wildfly-core 阅读 17 收藏 0 点赞 0 评论 0
@Test
public void testByteArrayObject() throws Exception {
    ModelNode description = createDescription(ModelType.OBJECT, ModelType.BYTES);
    TypeConverter converter = getConverter(description);

    assertMapType(assertCast(TabularType.class, converter.getOpenType()), SimpleType.STRING, ArrayType.getPrimitiveArrayType(byte[].class));

    ModelNode node = new ModelNode();
    node.get("one").set(new byte[] {1,2});
    node.get("two").set(new byte[] {3,4});

    TabularData tabularData = assertCast(TabularData.class, converter.fromModelNode(node));
    Assert.assertEquals(2, tabularData.size());
    Assert.assertTrue(Arrays.equals(new byte[] {1,2}, (byte[])tabularData.get(new Object[] {"one"}).get("value")));
    Assert.assertTrue(Arrays.equals(new byte[] {3,4}, (byte[])tabularData.get(new Object[] {"two"}).get("value")));

    //Allow plain map as well? Yeah why not!
    Map<String, byte[]> map = new HashMap<String, byte[]>();
    map.put("one", new byte[] {1,2});
    map.put("two", new byte[] {3,4});
    Assert.assertEquals(node, converter.toModelNode(map));
}
LegacyTypeConverterUnitTestCase.java 文件源码 项目:wildfly-core 阅读 22 收藏 0 点赞 0 评论 0
@Test
public void testSimpleTypeExpressionList() throws Exception {
    ModelNode description = createDescription(ModelType.LIST, ModelType.INT);
    description.get(EXPRESSIONS_ALLOWED).set(true);
    TypeConverter converter = getConverter(description);
    ArrayType<?> arrayType = assertCast(ArrayType.class, converter.getOpenType());
    Assert.assertEquals(SimpleType.INTEGER, arrayType.getElementOpenType());

    ModelNode node = new ModelNode();
    node.add().set(new ValueExpression("${this.should.not.exist.!!!!!:1}"));
    node.add().set(new ValueExpression("${this.should.not.exist.!!!!!:2}"));

    Integer[] data = assertCast(Integer[].class, converter.fromModelNode(node));
    Assert.assertEquals(Integer.valueOf(1), data[0]);
    Assert.assertEquals(Integer.valueOf(2), data[1]);
}
OpenTypeGenerator.java 文件源码 项目:fabric8poc 阅读 111 收藏 0 点赞 0 评论 0
public static Object[] getItemValues(Object bean) throws OpenDataException {
    Class<?> beanClass = bean.getClass();
    List<Object> items = new ArrayList<>();
    for (Method method : getGetters(beanClass)) {
        Object value;
        try {
            value = method.invoke(bean, (Object[]) null);
        } catch (Exception ex) {
            OpenDataException ode = new OpenDataException("Cannot obtain vaue from: " + method);
            ode.initCause(ex);
            throw ode;
        }
        Class<?> valueType = value.getClass();
        OpenType<?> openType = getOpenType(valueType);
        if (openType == SimpleType.STRING) {
            items.add(value);
        } else if (openType instanceof ArrayType) {
            items.add(value);
        } else if (openType instanceof CompositeType) {
            items.add(toCompositeData(value));
        } else {
            throw new OpenDataException("Unsupported open type for: " + openType);
        }
    }
    return items.toArray(new Object[items.size()]);
}
AMQQueueMBean.java 文件源码 项目:andes 阅读 17 收藏 0 点赞 0 评论 0
/**
 * initialises the openmbean data types
 */
private static void init() throws OpenDataException
{
    _msgContentAttributeTypes[0] = SimpleType.LONG; // For message id
    _msgContentAttributeTypes[1] = SimpleType.STRING; // For MimeType
    _msgContentAttributeTypes[2] = SimpleType.STRING; // For Encoding
    _msgContentAttributeTypes[3] = new ArrayType(1, SimpleType.BYTE); // For message content
    _msgContentType = new CompositeType("Message Content", "AMQ Message Content",
                VIEW_MSG_CONTENT_COMPOSITE_ITEM_NAMES_DESC.toArray(new String[VIEW_MSG_CONTENT_COMPOSITE_ITEM_NAMES_DESC.size()]),
                VIEW_MSG_CONTENT_COMPOSITE_ITEM_NAMES_DESC.toArray(new String[VIEW_MSG_CONTENT_COMPOSITE_ITEM_NAMES_DESC.size()]),
                _msgContentAttributeTypes);

    _msgAttributeTypes[0] = SimpleType.LONG; // For message id
    _msgAttributeTypes[1] = new ArrayType(1, SimpleType.STRING); // For header attributes
    _msgAttributeTypes[2] = SimpleType.LONG; // For size
    _msgAttributeTypes[3] = SimpleType.BOOLEAN; // For redelivered
    _msgAttributeTypes[4] = SimpleType.LONG; // For queue position

    _messageDataType = new CompositeType("Message", "AMQ Message", 
            VIEW_MSGS_COMPOSITE_ITEM_NAMES_DESC.toArray(new String[VIEW_MSGS_COMPOSITE_ITEM_NAMES_DESC.size()]),
            VIEW_MSGS_COMPOSITE_ITEM_NAMES_DESC.toArray(new String[VIEW_MSGS_COMPOSITE_ITEM_NAMES_DESC.size()]), _msgAttributeTypes);
    _messagelistDataType = new TabularType("Messages", "List of messages", _messageDataType,
                                            VIEW_MSGS_TABULAR_UNIQUE_INDEX.toArray(new String[VIEW_MSGS_TABULAR_UNIQUE_INDEX.size()]));
}
DefaultMXBeanMappingFactory.java 文件源码 项目:openjdk-jdk7u-jdk 阅读 22 收藏 0 点赞 0 评论 0
CollectionMapping(Type targetType,
                  ArrayType<?> openArrayType,
                  Class<?> openArrayClass,
                  MXBeanMapping elementMapping) {
    super(targetType, openArrayType);
    this.elementMapping = elementMapping;

    /* Determine the concrete class to be used when converting
       back to this Java type.  We convert all Lists to ArrayList
       and all Sets to TreeSet.  (TreeSet because it is a SortedSet,
       so works for both Set and SortedSet.)  */
    Type raw = ((ParameterizedType) targetType).getRawType();
    Class<?> c = (Class<?>) raw;
    final Class<?> collC;
    if (c == List.class)
        collC = ArrayList.class;
    else if (c == Set.class)
        collC = HashSet.class;
    else if (c == SortedSet.class)
        collC = TreeSet.class;
    else { // can't happen
        assert(false);
        collC = null;
    }
    collectionClass = Util.cast(collC);
}


问题


面经


文章

微信
公众号

扫码关注公众号