/*_############################################################################
_##
_## SNMP4J-AgentJMX - CombinedBitsType.java
_##
_## Copyright (C) 2006-2007 Frank Fock (SNMP4J.org)
_##
_## This program is free software; you can redistribute it and/or modify
_## it under the terms of the GNU General Public License version 2 as
_## published by the Free Software Foundation.
_##
_## This program is distributed in the hope that it will be useful,
_## but WITHOUT ANY WARRANTY; without even the implied warranty of
_## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
_## GNU General Public License for more details.
_##
_## You should have received a copy of the GNU General Public License
_## along with this program; if not, write to the Free Software
_## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
_## MA 02110-1301 USA
_##
_##########################################################################*/
package org.snmp4j.agent.mo.jmx.types;
import javax.management.openmbean.CompositeDataSupport;
import javax.management.*;
public class CombinedBitsType extends TypedAttribute {
private TypedAttribute[] proxyAttribute;
public CombinedBitsType(TypedAttribute[] proxyAttribute) {
super(proxyAttribute[0].getName(), proxyAttribute[0].getType());
this.proxyAttribute = proxyAttribute;
}
public Object transformFromNative(Object nativeValue, ObjectName objectName) {
byte[] bits = null;
for (TypedAttribute a : proxyAttribute) {
Object n = ((CompositeDataSupport)nativeValue).get(a.getName());
n = a.transformFromNative(n, null);
byte[] bytes = (byte[])n;
if (bits == null) {
bits = bytes;
}
else if (bits.length < bytes.length) {
for (int i=0; i<bits.length; i++) {
bytes[i] |= bits[i];
}
bits = bytes;
}
else {
for (int i=0; i<bytes.length; i++) {
bits[i] |= bytes[i];
}
}
}
return bits;
}
public Object transformToNative(Object transformedValue,
Object oldNativeValue, ObjectName objectName) {
throw new UnsupportedOperationException();
}
}
|