KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > snmp4j > agent > mo > jmx > types > CombinedBitsType


1 /*_############################################################################
2   _##
3   _## SNMP4J-AgentJMX - CombinedBitsType.java
4   _##
5   _## Copyright (C) 2006-2007 Frank Fock (SNMP4J.org)
6   _##
7   _## This program is free software; you can redistribute it and/or modify
8   _## it under the terms of the GNU General Public License version 2 as
9   _## 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 JavaDoc;
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 JavaDoc transformFromNative(Object JavaDoc nativeValue, ObjectName objectName) {
37     byte[] bits = null;
38     for (TypedAttribute a : proxyAttribute) {
39       Object JavaDoc n = ((CompositeDataSupport JavaDoc)nativeValue).get(a.getName());
40       n = a.transformFromNative(n, null);
41       byte[] bytes = (byte[])n;
42       if (bits == null) {
43         bits = bytes;
44       }
45       else if (bits.length < bytes.length) {
46         for (int i=0; i<bits.length; i++) {
47           bytes[i] |= bits[i];
48         }
49         bits = bytes;
50       }
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 JavaDoc transformToNative(Object JavaDoc transformedValue,
61                                   Object JavaDoc oldNativeValue, ObjectName objectName) {
62     throw new UnsupportedOperationException JavaDoc();
63   }
64
65
66 }
67
Popular Tags