|
JavaTM Platform Standard Ed. 6 |
|||||||||
앞의 클래스 다음의 클래스 | 프레임 있어 프레임 없음 | |||||||||
개요: 상자 | 필드 | 생성자 | 메소드 | 상세: 필드 | 생성자 | 메소드 |
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
|
JavaTM Platform Standard Ed. 6 |
|||||||||
앞의 클래스 다음의 클래스 | 프레임 있어 프레임 없음 | |||||||||
개요: 상자 | 필드 | 생성자 | 메소드 | 상세: 필드 | 생성자 | 메소드 |
Copyright 2006 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms . Documentation Redistribution Policy 도 참조해 주세요.