@Documented @Retention(value=RUNTIME) @Target(value=METHOD) public @interface DescriptorKey
元注释,介绍了如何注释元素涉及在Descriptor
一场。这可以为MBean描述符,或为一个属性,操作,或构造函数在MBean,或一个操作或构造函数的参数。
考虑这个注释为例:
@记录“目标(定义方法)“保留(retentionpolicy。运行时)公共@接口单元“DescriptorKey(“单位”)字符串value();}
和这个使用的注释:
CacheControlMBean的公共接口{“单位”(“字节”)公共长getcachesize();}
当一个标准MBean是由CacheControlMBean
,通常的规则意味着它将有一个属性叫做型long
CacheSize
。的@Units
标注,鉴于上述定义,将确保该属性的MBeanAttributeInfo
将有一个Descriptor
,有一场称为units
相应价值bytes
。
同样,如果注释看起来像这样:
@记录“目标(定义方法)“保留(retentionpolicy。运行时)公共@接口单元“DescriptorKey(“单位”)字符串value();“DescriptorKey(“descriptionresourcekey”)字符串resourcekey()默认”;“DescriptorKey(“descriptionresourcebundlebasename”)字符串resourcebundlebasename()默认”;}
它是这样使用:
CacheControlMBean的公共接口{“单位”(“字节”,ResourceKey =“字节。钥匙”,resourcebundlebasename =“COM。例子。foo。mbeanresources”)公共长getcachesize();}
然后得到的Descriptor
将包含以下领域:
Name | Value |
---|---|
units | "bytes" |
descriptionResourceKey | "bytes.key" |
descriptionResourceBundleBaseName | "com.example.foo.MBeanResources" |
注释如@Units
可以应用于:
忽略注释的其他用途。
接口注释只在精确的接口,定义了一个标准MBean或MXBean的管理接口进行检查,没有对其母接口。方法注释中出现的最具体的接口方法检查;换句话说,如果一个孩子接口重写从父接口的方法,考虑的是孩子的接口方法中仅@DescriptorKey
注释。
通过在同一程序元素上的不同注释以这种方式提供的描述符字段必须是一致的。也就是说,两个不同的注释,或同一个注释的两个成员,不能为同一描述符字段定义一个不同的值。字段注释getter方法还必须与字段注释相应的setter方法一致。
从这些注释的描述符将任何描述字段的实现提供了合并,如MBean的immutableInfo
场。注释的字段必须与实现所提供的这些字段一致。
注释元素被转换成一个描述符字段可以是任何类型的java语言允许的,除了一个注释、注解的数组。字段的值来自注释元素的值,如下:
Annotation element | Descriptor field |
---|---|
Primitive value (5 , false , etc) |
Wrapped value (Integer.valueOf(5) , Boolean.FALSE , etc) |
Class constant (e.g. Thread.class ) |
Class name from Class.getName() (e.g. "java.lang.Thread" ) |
Enum constant (e.g. ElementType.FIELD ) |
Constant name from Enum.name() (e.g. "FIELD" ) |
Array of class constants or enum constants | String array derived by applying these rules to each element |
Value of any other type ( String , String[] , int[] , etc) |
The same value |
public abstract String value
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2014, Oracle and/or its affiliates. All rights reserved.