Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/javax/management/DescriptorKey.java
38829 views
/*1* Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 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 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package javax.management;2627import java.lang.annotation.*;2829/**30* <p>Meta-annotation that describes how an annotation element relates31* to a field in a {@link Descriptor}. This can be the Descriptor for32* an MBean, or for an attribute, operation, or constructor in an33* MBean, or for a parameter of an operation or constructor.</p>34*35* <p>Consider this annotation for example:</p>36*37* <pre>38* @Documented39* @Target(ElementType.METHOD)40* @Retention(RetentionPolicy.RUNTIME)41* public @interface Units {42* <b>@DescriptorKey("units")</b>43* String value();44* }45* </pre>46*47* <p>and this use of the annotation:</p>48*49* <pre>50* public interface CacheControlMBean {51* <b>@Units("bytes")</b>52* public long getCacheSize();53* }54* </pre>55*56* <p>When a Standard MBean is made from the {@code CacheControlMBean},57* the usual rules mean that it will have an attribute called58* {@code CacheSize} of type {@code long}. The {@code @Units}59* annotation, given the above definition, will ensure that the60* {@link MBeanAttributeInfo} for this attribute will have a61* {@code Descriptor} that has a field called {@code units} with62* corresponding value {@code bytes}.</p>63*64* <p>Similarly, if the annotation looks like this:</p>65*66* <pre>67* @Documented68* @Target(ElementType.METHOD)69* @Retention(RetentionPolicy.RUNTIME)70* public @interface Units {71* <b>@DescriptorKey("units")</b>72* String value();73*74* <b>@DescriptorKey("descriptionResourceKey")</b>75* String resourceKey() default "";76*77* <b>@DescriptorKey("descriptionResourceBundleBaseName")</b>78* String resourceBundleBaseName() default "";79* }80* </pre>81*82* <p>and it is used like this:</p>83*84* <pre>85* public interface CacheControlMBean {86* <b>@Units("bytes",87* resourceKey="bytes.key",88* resourceBundleBaseName="com.example.foo.MBeanResources")</b>89* public long getCacheSize();90* }91* </pre>92*93* <p>then the resulting {@code Descriptor} will contain the following94* fields:</p>95*96* <table border="2" summary="Descriptor Fields">97* <tr><th>Name</th><th>Value</th></tr>98* <tr><td>units</td><td>"bytes"</td></tr>99* <tr><td>descriptionResourceKey</td><td>"bytes.key"</td></tr>100* <tr><td>descriptionResourceBundleBaseName</td>101* <td>"com.example.foo.MBeanResources"</td></tr>102* </table>103*104* <p>An annotation such as {@code @Units} can be applied to:</p>105*106* <ul>107* <li>a Standard MBean or MXBean interface;108* <li>a method in such an interface;109* <li>a parameter of a method in a Standard MBean or MXBean interface110* when that method is an operation (not a getter or setter for an attribute);111* <li>a public constructor in the class that implements a Standard MBean112* or MXBean;113* <li>a parameter in such a constructor.114* </ul>115*116* <p>Other uses of the annotation are ignored.</p>117*118* <p>Interface annotations are checked only on the exact interface119* that defines the management interface of a Standard MBean or an120* MXBean, not on its parent interfaces. Method annotations are121* checked only in the most specific interface in which the method122* appears; in other words, if a child interface overrides a method123* from a parent interface, only {@code @DescriptorKey} annotations in124* the method in the child interface are considered.125*126* <p>The Descriptor fields contributed in this way by different127* annotations on the same program element must be consistent. That128* is, two different annotations, or two members of the same129* annotation, must not define a different value for the same130* Descriptor field. Fields from annotations on a getter method must131* also be consistent with fields from annotations on the132* corresponding setter method.</p>133*134* <p>The Descriptor resulting from these annotations will be merged135* with any Descriptor fields provided by the implementation, such as136* the <a href="Descriptor.html#immutableInfo">{@code137* immutableInfo}</a> field for an MBean. The fields from the annotations138* must be consistent with these fields provided by the implementation.</p>139*140* <p>An annotation element to be converted into a descriptor field141* can be of any type allowed by the Java language, except an annotation142* or an array of annotations. The value of the field is derived from143* the value of the annotation element as follows:</p>144*145* <table border="2" summary="Descriptor Field Types">146* <tr><th>Annotation element</th><th>Descriptor field</th></tr>147* <tr><td>Primitive value ({@code 5}, {@code false}, etc)</td>148* <td>Wrapped value ({@code Integer.valueOf(5)},149* {@code Boolean.FALSE}, etc)</td></tr>150* <tr><td>Class constant (e.g. {@code Thread.class})</td>151* <td>Class name from {@link Class#getName()}152* (e.g. {@code "java.lang.Thread"})</td></tr>153* <tr><td>Enum constant (e.g. {@link ElementType#FIELD})</td>154* <td>Constant name from {@link Enum#name()}155* (e.g. {@code "FIELD"})</td></tr>156* <tr><td>Array of class constants or enum constants</td>157* <td>String array derived by applying these rules to each158* element</td></tr>159* <tr><td>Value of any other type<br>160* ({@code String}, {@code String[]}, {@code int[]}, etc)</td>161* <td>The same value</td></tr>162* </table>163*164* @since 1.6165*/166@Documented167@Retention(RetentionPolicy.RUNTIME)168@Target(ElementType.METHOD)169public @interface DescriptorKey {170String value();171}172173174