@Documented @Retention(value=RUNTIME) @Target(value=METHOD) public @interface DescriptorKey
描述注释元素如何与Descriptor中的字段相关的元注释 。 这可以是MBean的描述符,也可以是MBean中的属性,操作或构造函数,也可以是操作或构造函数的参数。
考虑这个注释,例如:
@Documented
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface Units {
@DescriptorKey("units")
String value();
}
而这个使用注释:
public interface CacheControlMBean {
@Units("bytes")
public long getCacheSize();
}
当标准MBean由CacheControlMBean时,通常的规则意味着它将具有一个名为CacheSize的属性类型为long 。 的@Units注释,考虑到上述定义,将确保MBeanAttributeInfo该属性将具有Descriptor ,其具有所谓的场units与对应值bytes 。
类似地,如果注释如下所示:
@Documented
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface Units {
@DescriptorKey("units")
String value();
@DescriptorKey("descriptionResourceKey")
String resourceKey() default "";
@DescriptorKey("descriptionResourceBundleBaseName")
String resourceBundleBaseName() default "";
}
它是这样使用的:
public interface CacheControlMBean {
@Units("bytes", resourceKey="bytes.key", resourceBundleBaseName="com.example.foo.MBeanResources")
public long getCacheSize();
}
那么结果Descriptor将包含以下字段:
诸如@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 typeString, 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.