1 /* 2 * Copyright (c) 1998, 2007, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 27 package com.sun.jmx.snmp; 28 29 30 31 32 /** 33 * Defines the interface of the object in charge of encoding and decoding SNMP packets. 34 * <P> 35 * You will not usually need to use this interface, except if you 36 * decide to replace the default implementation <CODE>SnmpPduFactoryBER</CODE>. 37 * <P> 38 * An <CODE>SnmpPduFactory</CODE> object is attached to an 39 * {@link com.sun.jmx.snmp.daemon.SnmpAdaptorServer SNMP protocol adaptor} 40 * or an {@link com.sun.jmx.snmp.SnmpPeer SnmpPeer}. 41 * It is used each time an SNMP packet needs to be encoded or decoded. 42 * <BR>{@link com.sun.jmx.snmp.SnmpPduFactoryBER SnmpPduFactoryBER} is the default 43 * implementation. 44 * It simply applies the standard ASN.1 encoding and decoding 45 * on the bytes of the SNMP packet. 46 * <P> 47 * It's possible to implement your own <CODE>SnmpPduFactory</CODE> 48 * object and to add authentication and/or encryption to the 49 * default encoding/decoding process. 50 * 51 * <p><b>This API is a Sun Microsystems internal API and is subject 52 * to change without notice.</b></p> 53 * @see SnmpPduFactory 54 * @see SnmpPduPacket 55 * @see SnmpMessage 56 * 57 */ 58 59 public interface SnmpPduFactory { 60 61 /** 62 * Decodes the specified <CODE>SnmpMsg</CODE> and returns the 63 * resulting <CODE>SnmpPdu</CODE>. If this method returns 64 * <CODE>null</CODE>, the message will be considered unsafe 65 * and will be dropped. 66 * 67 * @param msg The <CODE>SnmpMsg</CODE> to be decoded. 68 * @return Null or a fully initialized <CODE>SnmpPdu</CODE>. 69 * @exception SnmpStatusException If the encoding is invalid. 70 * 71 * @since 1.5 72 */ 73 public SnmpPdu decodeSnmpPdu(SnmpMsg msg) throws SnmpStatusException ; 74 75 /** 76 * Encodes the specified <CODE>SnmpPdu</CODE> and 77 * returns the resulting <CODE>SnmpMsg</CODE>. If this 78 * method returns null, the specified <CODE>SnmpPdu</CODE> 79 * will be dropped and the current SNMP request will be 80 * aborted. 81 * 82 * @param p The <CODE>SnmpPdu</CODE> to be encoded. 83 * @param maxDataLength The size limit of the resulting encoding. 84 * @return Null or a fully encoded <CODE>SnmpMsg</CODE>. 85 * @exception SnmpStatusException If <CODE>pdu</CODE> contains 86 * illegal values and cannot be encoded. 87 * @exception SnmpTooBigException If the resulting encoding does not 88 * fit into <CODE>maxPktSize</CODE> bytes. 89 * 90 * @since 1.5 91 */ 92 public SnmpMsg encodeSnmpPdu(SnmpPdu p, int maxDataLength) 93 throws SnmpStatusException, SnmpTooBigException ; 94 }