Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
MBeanAttributeMapping |
|
| 2.8;2,8 |
1 | package net.sf.snmpadaptor4j.core.mapping; | |
2 | ||
3 | import java.io.Serializable; | |
4 | import net.sf.snmpadaptor4j.object.SnmpDataType; | |
5 | import net.sf.snmpadaptor4j.object.SnmpOid; | |
6 | ||
7 | /** | |
8 | * Object containing the mapping for access to a MBean attribute. | |
9 | * @author <a href="http://fr.linkedin.com/in/jpminetti/">Jean-Philippe MINETTI</a> | |
10 | */ | |
11 | public final class MBeanAttributeMapping | |
12 | implements Serializable { | |
13 | ||
14 | /** | |
15 | * Serial number. | |
16 | */ | |
17 | private static final long serialVersionUID = 1031970528675491341L; | |
18 | ||
19 | /** | |
20 | * Object Identifier of MIB node. | |
21 | */ | |
22 | private final SnmpOid oid; | |
23 | ||
24 | /** | |
25 | * Attribute name. | |
26 | */ | |
27 | private final String attributeName; | |
28 | ||
29 | /** | |
30 | * SNMP data type of MIB node. | |
31 | */ | |
32 | private final SnmpDataType snmpDataType; | |
33 | ||
34 | /** | |
35 | * Data type of JMX attribute. | |
36 | */ | |
37 | private final Class<?> jmxDataType; | |
38 | ||
39 | /** | |
40 | * <code>TRUE</code> if the attribute can be read (for SNMP write and read community), <code>FALSE</code> otherwise. | |
41 | */ | |
42 | private final boolean readable; | |
43 | ||
44 | /** | |
45 | * <code>TRUE</code> if the attribute can be write (for SNMP write community), <code>FALSE</code> otherwise. | |
46 | */ | |
47 | private final boolean writable; | |
48 | ||
49 | /** | |
50 | * Hidden constructor. | |
51 | * @param oid Object Identifier of MIB node. | |
52 | * @param attributeName Attribute name. | |
53 | * @param snmpDataType SNMP data type of MIB node. | |
54 | * @param jmxDataType Data type of JMX attribute. | |
55 | * @param readable <code>TRUE</code> if the attribute can be read (for SNMP write and read community), <code>FALSE</code> otherwise. | |
56 | * @param writable <code>TRUE</code> if the attribute can be write (for SNMP write community), <code>FALSE</code> otherwise. | |
57 | * @see XmlMappingParser#newMBeanAttributeMappingList(java.util.Map, ClassLoader, String) | |
58 | */ | |
59 | MBeanAttributeMapping (final SnmpOid oid, final String attributeName, final SnmpDataType snmpDataType, final Class<?> jmxDataType, final boolean readable, | |
60 | final boolean writable) { | |
61 | 331 | super(); |
62 | 331 | this.oid = oid; |
63 | 331 | this.attributeName = attributeName; |
64 | 331 | this.snmpDataType = snmpDataType; |
65 | 331 | this.jmxDataType = jmxDataType; |
66 | 331 | this.readable = readable; |
67 | 331 | this.writable = writable; |
68 | 331 | } |
69 | ||
70 | /** | |
71 | * Returns the Object Identifier of MIB node. | |
72 | * @return Object Identifier of MIB node. | |
73 | */ | |
74 | public SnmpOid getOid () { | |
75 | 75 | return this.oid; |
76 | } | |
77 | ||
78 | /** | |
79 | * Returns the attribute name. | |
80 | * @return Attribute name. | |
81 | */ | |
82 | public String getAttributeName () { | |
83 | 19 | return this.attributeName; |
84 | } | |
85 | ||
86 | /** | |
87 | * Returns the SNMP data type of MIB node. | |
88 | * @return SNMP data type of MIB node. | |
89 | */ | |
90 | public SnmpDataType getSnmpDataType () { | |
91 | 44 | return this.snmpDataType; |
92 | } | |
93 | ||
94 | /** | |
95 | * Returns the data type of JMX attribute. | |
96 | * @return Data type of JMX attribute. | |
97 | */ | |
98 | public Class<?> getJmxDataType () { | |
99 | 41 | return this.jmxDataType; |
100 | } | |
101 | ||
102 | /** | |
103 | * Returns <code>TRUE</code> if the attribute can be read (for SNMP write and read community), <code>FALSE</code> otherwise. | |
104 | * @return <code>TRUE</code> if the attribute can be read (for SNMP write and read community), <code>FALSE</code> otherwise. | |
105 | */ | |
106 | public boolean isReadable () { | |
107 | 2 | return this.readable; |
108 | } | |
109 | ||
110 | /** | |
111 | * Returns <code>TRUE</code> if the attribute can be write (for SNMP write community), <code>FALSE</code> otherwise. | |
112 | * @return <code>TRUE</code> if the attribute can be write (for SNMP write community), <code>FALSE</code> otherwise. | |
113 | */ | |
114 | public boolean isWritable () { | |
115 | 2 | return this.writable; |
116 | } | |
117 | ||
118 | /* | |
119 | * {@inheritDoc} | |
120 | * @see java.lang.Object#hashCode() | |
121 | */ | |
122 | @Override | |
123 | public int hashCode () { | |
124 | final int prime = 31; | |
125 | 56 | int result = 1; |
126 | 56 | result = prime * result + ((this.attributeName == null) ? 0 : this.attributeName.hashCode()); |
127 | 56 | result = prime * result + ((this.jmxDataType == null) ? 0 : this.jmxDataType.hashCode()); |
128 | 56 | result = prime * result + ((this.oid == null) ? 0 : this.oid.hashCode()); |
129 | 56 | result = prime * result + (this.readable ? 1231 : 1237); |
130 | 56 | result = prime * result + ((this.snmpDataType == null) ? 0 : this.snmpDataType.hashCode()); |
131 | 56 | result = prime * result + (this.writable ? 1231 : 1237); |
132 | 56 | return result; |
133 | } | |
134 | ||
135 | /* | |
136 | * {@inheritDoc} | |
137 | * @see java.lang.Object#equals(java.lang.Object) | |
138 | */ | |
139 | @Override | |
140 | public boolean equals (final Object obj) { | |
141 | 86 | boolean result = false; |
142 | 86 | if (obj == this) { |
143 | 1 | result = true; |
144 | } | |
145 | 85 | else if ((obj != null) && (MBeanAttributeMapping.class.equals(obj.getClass()))) { |
146 | 83 | final MBeanAttributeMapping other = (MBeanAttributeMapping) obj; |
147 | 83 | result = (this.oid != null ? this.oid.equals(other.oid) : (other.oid == null)); |
148 | 83 | if (result) { |
149 | 80 | result = (this.attributeName != null ? this.attributeName.equals(other.attributeName) : (other.attributeName == null)); |
150 | } | |
151 | 83 | if (result) { |
152 | 77 | result = (this.snmpDataType != null ? this.snmpDataType.equals(other.snmpDataType) : (other.snmpDataType == null)); |
153 | } | |
154 | 83 | if (result) { |
155 | 74 | result = (this.jmxDataType != null ? this.jmxDataType.equals(other.jmxDataType) : (other.jmxDataType == null)); |
156 | } | |
157 | 83 | if (result) { |
158 | 71 | result = (this.readable == other.readable); |
159 | } | |
160 | 83 | if (result) { |
161 | 70 | result = (this.writable == other.writable); |
162 | } | |
163 | } | |
164 | 86 | return result; |
165 | } | |
166 | ||
167 | /* | |
168 | * {@inheritDoc} | |
169 | * @see java.lang.Object#toString() | |
170 | */ | |
171 | @Override | |
172 | public String toString () { | |
173 | 1 | return "MBeanAttributeMapping[oid=" + this.oid + "; attributeName=" + this.attributeName + "; snmpDataType=" + this.snmpDataType + "; jmxDataType=" |
174 | + this.jmxDataType + "; readable=" + this.readable + "; writable=" + this.writable + "]"; | |
175 | } | |
176 | ||
177 | } |