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