1 /* 2 * Copyright (c) 2015, 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. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 import java.beans.ConstructorProperties; 25 import javax.management.ConstructorParameters; 26 import javax.management.MBeanServer; 27 import javax.management.MBeanServerFactory; 28 import javax.management.ObjectName; 29 30 /* 31 * @test 32 * @bug 7199353 33 * @summary Asserts that 'java.beans.ConstructorProperties' annotation is still 34 * recognized and properly handled for custom types mapped to open types. 35 * Also, makes sure that if the same constructor is annotated by both 36 * j.b.ConstructorProperties and j.m.ConstructorProperties annotations 37 * only j.m.ConstructorProperties annotation is considered. 38 * @author Jaroslav Bachorik 39 * @modules java.management 40 * java.desktop 41 * @run main LegacyConstructorPropertiesTest 42 */ 43 44 public class LegacyConstructorPropertiesTest { 45 public static class CustomType { 46 private String name; 47 private int value; 48 @ConstructorProperties({"name", "value"}) 49 public CustomType(String name, int value) { 50 this.name = name; 51 this.value = value; 52 } 53 54 // if @java.beans.ConstructorProperties would be used 55 // the introspector would choke on this 56 @ConstructorProperties("noname") 57 @ConstructorParameters("name") 58 public CustomType(String name) { 59 this.name = name; 60 this.value = -1; 61 } 62 63 public String getName() { 64 return name; 65 } 66 67 public void setName(String name) { 68 this.name = name; 69 } 70 71 public int getValue() { 72 return value; 73 } 74 75 public void setValue(int value) { 76 this.value = value; 77 } 78 } 79 80 public static interface CustomMXBean { 81 public CustomType getProp(); 82 public void setProp(CustomType prop); 83 } 84 85 public static final class Custom implements CustomMXBean { 86 private CustomType prop; 87 88 @Override 89 public CustomType getProp() { 90 return prop; 91 } 92 93 @Override 94 public void setProp(CustomType prop) { 95 this.prop = prop; 96 } 97 } 98 99 public static void main(String[] args) throws Exception { 100 MBeanServer mbs = MBeanServerFactory.createMBeanServer(); 101 CustomMXBean mbean = new Custom(); 102 103 mbs.registerMBean(mbean, ObjectName.getInstance("test:type=Custom")); 104 } 105 }