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