public interface CompositeDataView
Java クラスは、このインタフェースを実装することにより、MXBean フレームワークを使って CompositeData に変換する方法を示すことができます。
このクラスの一般的な使用方法は、MXBean フレームワークの提供する CompositeTypeで宣言される項目に加えて、補足項目を CompositeData に追加することです。このためには、同一の項目を持ち、かつ補足項目も持つ別の CompositeType を作成する必要があります。
たとえば、units という名前の String と、long と double のいずれかである value とで構成される Measure クラスを考えましょう。これは、次のようになります。
 public class Measure implements CompositeDataView {
     private String units;
     private Number value; // a Long or a Double
     public Measure(String units, Number value) {
         this.units = units;
         this.value = value;
     }
     public static Measure from(CompositeData cd) {
         return new Measure((String) cd.get("units"),
                            (Number) cd.get("value"));
     }
     public String getUnits() {
         return units;
     }
     // Can't be called getValue(), because Number is not a valid type
     // in an MXBean, so the implied "value" property would be rejected.
     public Number _getValue() {
         return value;
     }
     public CompositeData toCompositeData(CompositeType ct) {
         try {
             List<String> itemNames = new ArrayList<String>(ct.keySet());
             List<String> itemDescriptions = new ArrayList<String>();
             List<OpenType<?>> itemTypes = new ArrayList<OpenType<?>>();
             for (String item : itemNames) {
                 itemDescriptions.add(ct.getDescription(item));
                 itemTypes.add(ct.getType(item));
             }
             itemNames.add("value");
             itemDescriptions.add("long or double value of the measure");
             itemTypes.add((value instanceof Long) ? SimpleType.LONG :
                           SimpleType.DOUBLE);
             CompositeType xct =
                 new CompositeType(ct.getTypeName(),
                                   ct.getDescription(),
                                   itemNames.toArray(new String[0]),
                                   itemDescriptions.toArray(new String[0]),
                                   itemTypes.toArray(new OpenType<?>[0]));
             CompositeData cd =
                 new CompositeDataSupport(xct,
                                          new String[] {"units", "value"},
                                          new Object[] {units, value});
             assert ct.isValue(cd);  // check we've done it right
             return cd;
         } catch (Exception e) {
             throw new RuntimeException(e);
         }
     }
 }
 
この属性型またはオペレーション型の Descriptor の openType フィールドに表示される CompositeType には、units 項目だけが示されます。ただし、生成される実際の CompositeData には、units と value の両方が含まれます。
MXBean| 修飾子と型 | メソッドと説明 | 
|---|---|
| CompositeData | toCompositeData(CompositeType ct)このオブジェクト内の値に対応する  CompositeDataを返します。 | 
CompositeData toCompositeData(CompositeType ct)
このオブジェクト内の値に対応する CompositeData を返します。通常、戻り値は CompositeDataSupport のインスタンス、または writeReplace メソッドを介して CompositeDataSupport として直列化を行うクラスになります。それ以外の場合、オブジェクトを受信するリモートクライアントは、再構築を実行できない可能性があります。
ct - 戻り値の予想される CompositeType。戻り値が cd である場合、cd.getCompositeType().equals(ct) は true になる。通常、これは、cd が ct を CompositeType として構築された CompositeDataSupport であるため。CompositeData。 バグまたは機能を送信 
詳細な API リファレンスおよび開発者ドキュメントについては、Java SE のドキュメントを参照してください。そのドキュメントには、概念的な概要、用語の定義、回避方法、有効なコード例などの、開発者を対象にしたより詳細な説明が含まれています。
Copyright © 1993, 2013, Oracle and/or its affiliates. All rights reserved.