1. /*
  2. * @(#)file SnmpPduFactory.java
  3. * @(#)author Sun Microsystems, Inc.
  4. * @(#)version 4.23
  5. * @(#)date 04/09/15
  6. *
  7. * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
  8. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  9. *
  10. */
  11. package com.sun.jmx.snmp;
  12. /**
  13. * Defines the interface of the object in charge of encoding and decoding SNMP packets.
  14. * <P>
  15. * You will not usually need to use this interface, except if you
  16. * decide to replace the default implementation <CODE>SnmpPduFactoryBER</CODE>.
  17. * <P>
  18. * An <CODE>SnmpPduFactory</CODE> object is attached to an
  19. * {@link com.sun.jmx.snmp.daemon.SnmpAdaptorServer SNMP protocol adaptor}
  20. * or an {@link com.sun.jmx.snmp.SnmpPeer SnmpPeer}.
  21. * It is used each time an SNMP packet needs to be encoded or decoded.
  22. * <BR>{@link com.sun.jmx.snmp.SnmpPduFactoryBER SnmpPduFactoryBER} is the default
  23. * implementation.
  24. * It simply applies the standard ASN.1 encoding and decoding
  25. * on the bytes of the SNMP packet.
  26. * <P>
  27. * It's possible to implement your own <CODE>SnmpPduFactory</CODE>
  28. * object and to add authentication and/or encryption to the
  29. * default encoding/decoding process.
  30. *
  31. * <p><b>This API is a Sun Microsystems internal API and is subject
  32. * to change without notice.</b></p>
  33. * @see SnmpPduFactory
  34. * @see SnmpPduPacket
  35. * @see SnmpMessage
  36. *
  37. * @version 1.8 08/13/98
  38. * @author Sun Microsystems, Inc
  39. */
  40. public interface SnmpPduFactory {
  41. /**
  42. * Decodes the specified <CODE>SnmpMsg</CODE> and returns the
  43. * resulting <CODE>SnmpPdu</CODE>. If this method returns
  44. * <CODE>null</CODE>, the message will be considered unsafe
  45. * and will be dropped.
  46. *
  47. * @param msg The <CODE>SnmpMsg</CODE> to be decoded.
  48. * @return Null or a fully initialized <CODE>SnmpPdu</CODE>.
  49. * @exception SnmpStatusException If the encoding is invalid.
  50. *
  51. * @since 1.5
  52. */
  53. public SnmpPdu decodeSnmpPdu(SnmpMsg msg) throws SnmpStatusException ;
  54. /**
  55. * Encodes the specified <CODE>SnmpPdu</CODE> and
  56. * returns the resulting <CODE>SnmpMsg</CODE>. If this
  57. * method returns null, the specified <CODE>SnmpPdu</CODE>
  58. * will be dropped and the current SNMP request will be
  59. * aborted.
  60. *
  61. * @param p The <CODE>SnmpPdu</CODE> to be encoded.
  62. * @param maxDataLength The size limit of the resulting encoding.
  63. * @return Null or a fully encoded <CODE>SnmpMsg</CODE>.
  64. * @exception SnmpStatusException If <CODE>pdu</CODE> contains
  65. * illegal values and cannot be encoded.
  66. * @exception SnmpTooBigException If the resulting encoding does not
  67. * fit into <CODE>maxPktSize</CODE> bytes.
  68. *
  69. * @since 1.5
  70. */
  71. public SnmpMsg encodeSnmpPdu(SnmpPdu p, int maxDataLength)
  72. throws SnmpStatusException, SnmpTooBigException ;
  73. }