KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*_############################################################################
2   _##
3   _## SNMP4J-AgentJMX - TypedAttribute.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
23 package org.snmp4j.agent.mo.jmx.types;
24
25 import java.io.*;
26
27 import org.snmp4j.smi.Variable;
28 import javax.management.*;
29
30 /**
31  * A <code>TypedAttribute</code> is the combination of a attribute name
32  * and a <code>Class</code> instance denoting the name and type of a MBean
33  * attribute value. Various transformation methods provide mappings to and from
34  * SNMP values.
35  *
36  * @author Frank Fock
37  * @version 1.0
38  */

39 public class TypedAttribute
40     implements Serializable, SMITransformType, TransformType
41 {
42
43   private String JavaDoc name;
44   private Class JavaDoc type;
45
46   public TypedAttribute(String JavaDoc name, String JavaDoc type) throws ClassNotFoundException JavaDoc {
47     this.name = name;
48     this.type = Class.forName(type);
49   }
50
51   public TypedAttribute(String JavaDoc name, Class JavaDoc type) {
52     this.name = name;
53     this.type = type;
54   }
55
56   public String JavaDoc getName() {
57     return name;
58   }
59
60   public Class JavaDoc getType() {
61     return type;
62   }
63
64   public void transformObject2SMI(Object JavaDoc object, Variable value) {
65     SMIVariant colVariant = new SMIVariant(value);
66     colVariant.setValue(object);
67   }
68
69   public Object JavaDoc transformSMI2Object(Variable value) {
70     SMIVariant smiVariant = new SMIVariant(value);
71     return smiVariant.getValue(type);
72   }
73
74   public Object JavaDoc transformFromNative(Object JavaDoc nativeValue, ObjectName objectName) {
75     return nativeValue;
76   }
77
78   public Object JavaDoc transformToNative(Object JavaDoc transformedValue,
79                                   Object JavaDoc oldNativeValue, ObjectName objectName) {
80     return transformedValue;
81   }
82
83   public boolean isNativeValueAlwaysNeeded() {
84     return false;
85   }
86
87 }
88
Popular Tags