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