View Javadoc
1   // NAME
2   //      $RCSfile: OneSetPdu.java,v $
3   // DESCRIPTION
4   //      [given below in javadoc format]
5   // DELTA
6   //      $Revision: 3.14 $
7   // CREATED
8   //      $Date: 2006/01/17 17:49:53 $
9   // COPYRIGHT
10  //      Westhawk Ltd
11  // TO DO
12  //
13  
14  
15  /*
16   * Copyright (C) 1996 - 1998 by Westhawk Ltd (www.westhawk.nl)
17   * Copyright (C) 1998 - 2006 by Westhawk Ltd 
18   * <a href="www.westhawk.co.uk">www.westhawk.co.uk</a>
19   *
20   * Permission to use, copy, modify, and distribute this software
21   * for any purpose and without fee is hereby granted, provided
22   * that the above copyright notices appear in all copies and that
23   * both the copyright notice and this permission notice appear in
24   * supporting documentation.
25   * This software is provided "as is" without express or implied
26   * warranty.
27   * author <a href="mailto:snmp@westhawk.co.uk">Tim Panton</a>
28   */
29   
30  package uk.co.westhawk.snmp.pdu;
31  
32  /*-
33   * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲
34   * SNMP Java Client
35   * ჻჻჻჻჻჻
36   * Copyright 2023 MetricsHub, Westhawk
37   * ჻჻჻჻჻჻
38   * This program is free software: you can redistribute it and/or modify
39   * it under the terms of the GNU Lesser General Public License as
40   * published by the Free Software Foundation, either version 3 of the
41   * License, or (at your option) any later version.
42   *
43   * This program is distributed in the hope that it will be useful,
44   * but WITHOUT ANY WARRANTY; without even the implied warranty of
45   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
46   * GNU General Lesser Public License for more details.
47   *
48   * You should have received a copy of the GNU General Lesser Public
49   * License along with this program.  If not, see
50   * <http://www.gnu.org/licenses/lgpl-3.0.html>.
51   * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱
52   */
53  import uk.co.westhawk.snmp.stack.*;
54  import java.util.*;
55  
56  /**
57   * <p>
58   * The OneSetPdu class will set the value of one (1) object (oid), based 
59   * on the Set request.
60   * </p>
61   *
62   * <p>
63   * Unless an exception occurred the Object to the update() method of the
64   * Observer will be a varbind, so any AsnObject type can be returned.
65   * In the case of an exception, that exception will be passed.
66   * </p>
67   *
68   * <p>
69   * For SNMPv3: The receiver of a request PDU acts as the authoritative engine.
70   * </p>
71   *
72   * @deprecated  As of 4_14, just use {@link SetPdu} 
73   * @see varbind
74   * @see SetPdu_vec
75   *
76   * @author <a href="mailto:snmp@westhawk.co.uk">Birgit Arkesteijn</a>
77   * @version $Revision: 3.14 $ $Date: 2006/01/17 17:49:53 $
78   */
79  public class OneSetPdu extends SetPdu {
80      private static final String version_id = "@(#)$Id: OneSetPdu.java,v 3.14 2006/01/17 17:49:53 birgit Exp $ Copyright Westhawk Ltd";
81  
82      varbind var;
83  
84      /**
85       * Constructor.
86       *
87       * @param con The context of the request
88       */
89      public OneSetPdu(SnmpContextBasisFace con) {
90          super(con);
91      }
92  
93      /**
94       * Constructor that will send the request immediately. No Observer
95       * is set.
96       *
97       * @param con the SnmpContextBasisFace
98       * @param oid the oid
99       * @param val The value
100      */
101     public OneSetPdu(SnmpContextBasisFace con, String oid, AsnObject val)
102             throws PduException, java.io.IOException {
103         this(con, oid, val, null);
104     }
105 
106     /**
107      * Constructor that will send the request immediately.
108      *
109      * @param con the SnmpContextBasisFace
110      * @param oid the oid
111      * @param val The value
112      * @param o   the Observer that will be notified when the answer is received
113      */
114     public OneSetPdu(SnmpContextBasisFace con, String oid, AsnObject val, Observer o)
115             throws PduException, java.io.IOException {
116         super(con);
117         if (o != null) {
118             addObserver(o);
119         }
120         addOid(oid, val);
121         send();
122     }
123 
124     /**
125      * The value of the request is set. This will be called by
126      * Pdu.fillin(). This is the value of the OID after the Set request
127      * was done. If the SNMP server allowed the set, this will be the
128      * same value as was set in SetPdu.addOid().
129      *
130      * @param n     the index of the value
131      * @param a_var the value
132      * @see Pdu#new_value
133      * @see SetPdu#addOid(String, AsnObject)
134      */
135     protected void new_value(int n, varbind a_var) {
136         if (n == 0) {
137             var = a_var;
138         }
139     }
140 
141     /**
142      * This method notifies all observers.
143      * This will be called by Pdu.fillin().
144      * 
145      * <p>
146      * Unless an exception occurred the Object to the update() method of the
147      * Observer will be a varbind, so any AsnObject type can be returned.
148      * In the case of an exception, that exception will be passed.
149      * </p>
150      */
151     protected void tell_them() {
152         notifyObservers(var);
153     }
154 
155 }