View Javadoc

1   package net.sf.snmpadaptor4j.core.mapping;
2   
3   import net.sf.snmpadaptor4j.object.SnmpDataType;
4   import net.sf.snmpadaptor4j.object.SnmpOid;
5   
6   /**
7    * Object containing the mapping to build the <code>dataMap</code> field of {@link net.sf.snmpadaptor4j.object.SnmpTrap SnmpTrap} from a <code>userData</code> field
8    * of JMX notification and as <b>simple object</b>.
9    * @author <a href="http://fr.linkedin.com/in/jpminetti/">Jean-Philippe MINETTI</a>
10   */
11  public final class SimpleDataMapTrapMapping
12  		extends DataMapTrapMapping {
13  
14  	/**
15  	 * Serial number.
16  	 */
17  	private static final long serialVersionUID = 2806381975871178286L;
18  
19  	/**
20  	 * SNMP data type of <code>userData</code> field of JMX notification.
21  	 */
22  	private final SnmpDataType userDataType;
23  
24  	/**
25  	 * OID of <code>userData</code> field of JMX notification.
26  	 */
27  	private final SnmpOid userDataOid;
28  
29  	/**
30  	 * Hidden constructor.
31  	 * @param sequenceNumberOid OID of <code>sequenceNumber</code> field of JMX notification. Is NULL if the <code>sequenceNumber</code> should not be present in
32  	 *            <code>dataMap</code> field of {@link net.sf.snmpadaptor4j.object.SnmpTrap SnmpTrap}.
33  	 * @param messageOid OID of <code>message</code> field of JMX notification. Is NULL if the <code>message</code> should not be present in <code>dataMap</code>
34  	 *            field of {@link net.sf.snmpadaptor4j.object.SnmpTrap SnmpTrap}.
35  	 * @param hasSystemInfo <code>TRUE</code> for put all system information attributes in the <code>dataMap</code> field of
36  	 *            {@link net.sf.snmpadaptor4j.object.SnmpTrap SnmpTrap}.
37  	 * @param userDataType SNMP data type of <code>userData</code> field of JMX notification (must not be <code>NULL</code>).
38  	 * @param userDataOid OID of <code>userData</code> field of JMX notification (must not be <code>NULL</code>).
39  	 * @see XmlMappingParser#newSnmpTrapMappingMap(String)
40  	 */
41  	SimpleDataMapTrapMapping (final SnmpOid sequenceNumberOid, final SnmpOid messageOid, final boolean hasSystemInfo, final SnmpDataType userDataType,
42  			final SnmpOid userDataOid) {
43  		super(sequenceNumberOid, messageOid, hasSystemInfo);
44  		this.userDataType = userDataType;
45  		this.userDataOid = userDataOid;
46  	}
47  
48  	/**
49  	 * Returns the SNMP data type of <code>userData</code> field of JMX notification.
50  	 * @return SNMP data type of <code>userData</code> field of JMX notification (never <code>NULL</code>).
51  	 */
52  	public SnmpDataType getUserDataType () {
53  		return this.userDataType;
54  	}
55  
56  	/**
57  	 * Returns the OID of <code>userData</code> field of JMX notification.
58  	 * @return OID of <code>userData</code> field of JMX notification (never <code>NULL</code>).
59  	 */
60  	public SnmpOid getUserDataOid () {
61  		return this.userDataOid;
62  	}
63  
64  	/*
65  	 * {@inheritDoc}
66  	 * @see net.sf.snmpadaptor4j.core.mapping.DataMapTrapMapping#hashCode()
67  	 */
68  	@Override
69  	public int hashCode () {
70  		final int prime = 31;
71  		int result = super.hashCode();
72  		result = prime * result + ((this.userDataOid == null) ? 0 : this.userDataOid.hashCode());
73  		result = prime * result + ((this.userDataType == null) ? 0 : this.userDataType.hashCode());
74  		return result;
75  	}
76  
77  	/*
78  	 * {@inheritDoc}
79  	 * @see net.sf.snmpadaptor4j.core.mapping.DataMapTrapMapping#equals(java.lang.Object)
80  	 */
81  	@Override
82  	public boolean equals (final Object obj) {
83  		boolean result = false;
84  		if (obj == this) {
85  			result = true;
86  		}
87  		else {
88  			result = super.equals(obj);
89  			if (result) {
90  				final SimpleDataMapTrapMapping other = (SimpleDataMapTrapMapping) obj;
91  				result = (this.userDataType == other.userDataType);
92  				if (result) {
93  					result = (this.userDataOid != null ? this.userDataOid.equals(other.userDataOid) : other.userDataOid == null);
94  				}
95  			}
96  		}
97  		return result;
98  	}
99  
100 	/*
101 	 * {@inheritDoc}
102 	 * @see java.lang.Object#toString()
103 	 */
104 	@Override
105 	public String toString () {
106 		return "SimpleDataMapTrapMapping[sequenceNumberOid=" + getSequenceNumberOid() + "; messageOid=" + getMessageOid() + "; hasSystemInfo=" + isHasSystemInfo()
107 				+ "; userDataType=" + this.userDataType + "; userDataOid=" + this.userDataOid + "]";
108 	}
109 
110 }