01: /*_############################################################################
02: _##
03: _## SNMP4J-AgentJMX - CombinedBitsType.java
04: _##
05: _## Copyright (C) 2006-2007 Frank Fock (SNMP4J.org)
06: _##
07: _## This program is free software; you can redistribute it and/or modify
08: _## it under the terms of the GNU General Public License version 2 as
09: _## published by the Free Software Foundation.
10: _##
11: _## This program is distributed in the hope that it will be useful,
12: _## but WITHOUT ANY WARRANTY; without even the implied warranty of
13: _## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14: _## GNU General Public License for more details.
15: _##
16: _## You should have received a copy of the GNU General Public License
17: _## along with this program; if not, write to the Free Software
18: _## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19: _## MA 02110-1301 USA
20: _##
21: _##########################################################################*/
22: package org.snmp4j.agent.mo.jmx.types;
23:
24: import javax.management.openmbean.CompositeDataSupport;
25: import javax.management.*;
26:
27: public class CombinedBitsType extends TypedAttribute {
28:
29: private TypedAttribute[] proxyAttribute;
30:
31: public CombinedBitsType(TypedAttribute[] proxyAttribute) {
32: super (proxyAttribute[0].getName(), proxyAttribute[0].getType());
33: this .proxyAttribute = proxyAttribute;
34: }
35:
36: public Object transformFromNative(Object nativeValue,
37: ObjectName objectName) {
38: byte[] bits = null;
39: for (TypedAttribute a : proxyAttribute) {
40: Object n = ((CompositeDataSupport) nativeValue).get(a
41: .getName());
42: n = a.transformFromNative(n, null);
43: byte[] bytes = (byte[]) n;
44: if (bits == null) {
45: bits = bytes;
46: } else if (bits.length < bytes.length) {
47: for (int i = 0; i < bits.length; i++) {
48: bytes[i] |= bits[i];
49: }
50: bits = bytes;
51: } else {
52: for (int i = 0; i < bytes.length; i++) {
53: bits[i] |= bytes[i];
54: }
55: }
56: }
57: return bits;
58: }
59:
60: public Object transformToNative(Object transformedValue,
61: Object oldNativeValue, ObjectName objectName) {
62: throw new UnsupportedOperationException();
63: }
64:
65: }
|