JavaTM Platform
Standard Ed. 6

javax.management.openmbean
인터페이스 CompositeDataView



public interface CompositeDataView

Java 클래스는, 이 인터페이스를 구현하는 것으로써, MXBean 시스템를 사용해 CompositeData 로 변환하는 방법을 나타낼 수가 있습니다.

이 클래스의 일반적인 사용 방법은, MXBean 시스템의 제공하는 CompositeType 로 선언되는 항목에 가세해, 추가 항목을 CompositeData 에 추가하는 것입니다. 이 때문에는, 동일한 항목을 가져, 한편 추가 항목도 가지는 다른 CompositeType 를 작성할 필요가 있습니다.

예를 들어,units 라는 이름의 String 와longdouble 의 언젠가인 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);
         }
     }
 }
 

이 속성형 또는 오퍼레이션형 DescriptoropenType 필드에 표시되는 CompositeType 에는,units 항목만이 나타납니다. 다만, 생성되는 실제의 CompositeData 에는,unitsvalue 의 양쪽 모두가 포함됩니다.

도입된 버젼:
1.6
관련 항목:
MXBean

메소드의 개요
 CompositeData toCompositeData (CompositeType  ct)
          이 객체내의 값에 대응하는 CompositeData 를 돌려줍니다.
 

메소드의 상세

toCompositeData

CompositeData  toCompositeData(CompositeType  ct)

이 객체내의 값에 대응하는 CompositeData 를 돌려줍니다. 일반적으로, 반환값은 CompositeDataSupport 의 인스턴스, 또는 writeReplace 메소드를 개입시켜 CompositeDataSupport 로서 직렬화를 실시하는 클래스가 됩니다. 그 이외의 경우, 객체를 수신하는 원격 클라이언트는, 재구축을 실행할 수 없을 가능성이 있습니다.

파라미터:
ct - 반환값의 예상되는 CompositeType. 반환값이 cd 인 경우, cd.getCompositeType(). equals(ct) 는 true 가 된다. 일반적으로, 이것은,cdctCompositeType 로서 구축된 CompositeDataSupport 로 있기 (위해)때문에
반환값:
CompositeData

JavaTM Platform
Standard Ed. 6

버그의 보고와 기능의 요청
한층 더 자세한 API 레퍼런스 및 개발자 문서에 대해서는,Java SE 개발자용 문서를 참조해 주세요. 개발자전용의 상세한 해설, 개념의 개요, 용어의 정의, 버그의 회피책, 및 코드 실례가 포함되어 있습니다.

Copyright 2006 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms . Documentation Redistribution Policy 도 참조해 주세요.