public interface CompositeDataView
一个java类可以实现此接口以显示它是如何被转换成一个CompositeData
MXBean框架。
一个典型的方法来使用这个类添加额外的项目,此外,通过框架提供的CompositeType
MXBean宣布的CompositeData
。要做到这一点,你必须创建一个CompositeType
具有所有相同的项目,再加上你的额外项目。
例如,假设你有一个类Measure
由字符串称为units
和value
是long
或double
。它可能看起来像这样:
公共类的计量器具compositedataview {私有字符串单位;私有数值;/ /长或双公共措施(字符串单位,数字值)this.units =单位;this.value =价值;}公共静态测量(复合数据CD){返回新的措施((字符串))。获取(“单位”),(数字)光盘。获取(“值”);}公共字符串getunits() {返回单位;}/ /不能称之为getvalue(),因为号码是不正确的类型/ /在一个MXBean,所以隐含的“价值”属性将被拒绝。公众号_getvalue() {返回值;}公共tocompositedata复合数据(compositetype CT){尝试{List<String> itemNames = new ArrayList<String>(ct.keySet());
List<String> itemDescriptions = new ArrayList<String>();
List<OpenType<?>> itemTypes = new ArrayList<OpenType<?>>();
对(串项:itemnames){itemdescriptions。添加(CT。getDescription(项));itemtypes。添加(CT。GetType(项));}itemnames添加(“价值”);itemdescriptions。添加(“长或双重价值的措施”);itemtypes。添加((价值是长)?SimpleType.LONG:SimpleType双);compositetype XCT =新的compositetype gettypename()(CT,getdescription() CT,itemnames。toArray(新弦[ 0 ]),itemdescriptions。toArray(新弦[ 0 ]),itemtypes。toArray(新OpenType <?> [ 0 ]);复合数据光盘=新的compositedatasupport(XCT,新字符串[ ] {“单位”,“值”},新的对象[ ] {单位,值};断言CT。英赛孚(CD);/ /检查我们所做的是正确的回CD;}捕获(异常E)抛出RuntimeException(E);}}}
的CompositeType
将这种类型的属性或操作中出现的Descriptor
的openType
领域将只显示units
项目,但所产生的实际CompositeData
既有units
和value
。
MXBean
Modifier and Type | Method and Description |
---|---|
CompositeData |
toCompositeData(CompositeType ct)
返回一个对应于该对象的值
CompositeData 。
|
CompositeData toCompositeData(CompositeType ct)
返回一个对应于该对象的值CompositeData
。返回值通常应该是CompositeDataSupport
实例,或一个类,通过writeReplace
序列化方法CompositeDataSupport
。否则,接收对象的远程客户端可能无法重建它。
ct
-返回值的预期
CompositeType
。如果返回值是
cd
,然后
cd.getCompositeType().equals(ct)
应该是真的。这通常是因为
cd
是一个
ct
为
CompositeType
构建
CompositeDataSupport
。
CompositeData
。
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.