1 22 package org.snmp4j.agent.mo.jmx.types; 23 24 import org.snmp4j.smi.OctetString; 25 import javax.management.*; 26 27 public class BooleanBitsType extends TypedAttribute { 28 29 private int offset = 0; 30 31 public BooleanBitsType(String name, int offset) { 32 super(name, byte[].class); 33 this.offset = offset; 34 } 35 36 public int getOffset() { 37 return offset; 38 } 39 40 public Object transformFromNative(Object nativeValue, ObjectName objectName) { 41 StringBuffer buf = 42 new StringBuffer (((Boolean )nativeValue).booleanValue() ? "1" : "0"); 43 for (int i=0; i<offset; i++) { 44 buf.insert(0, "0"); 45 } 46 while (buf.length() % 8 > 0) { 47 buf.append("0"); 48 } 49 return OctetString.fromString(buf.toString(), 2).toByteArray(); 50 } 51 52 public Object transformToNative(Object transformedValue, 53 Object oldNativeValue, ObjectName objectName) { 54 OctetString os = new OctetString((byte[])transformedValue); 55 String s = os.toString(2); 56 if (s.length() <= offset) { 57 return false; 58 } 59 return (s.charAt(offset) == '1'); 60 } 61 62 } 63 | Popular Tags |