KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > snmp4j > agent > agentx > AgentXResponsePDU


1 /*_############################################################################
2   _##
3   _## SNMP4J-AgentX - AgentXResponsePDU.java
4   _##
5   _## Copyright (C) 2005-2007 Frank Fock (SNMP4J.org)
6   _##
7   _## This program is free software; you can redistribute it and/or modify
8   _## it under the terms of the GNU General Public License version 2 as
9   _## published by the Free Software Foundation.
10   _##
11   _## This program is distributed in the hope that it will be useful,
12   _## but WITHOUT ANY WARRANTY; without even the implied warranty of
13   _## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14   _## GNU General Public License for more details.
15   _##
16   _## You should have received a copy of the GNU General Public License
17   _## along with this program; if not, write to the Free Software
18   _## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19   _## MA 02110-1301 USA
20   _##
21   _##########################################################################*/

22
23 package org.snmp4j.agent.agentx;
24
25 import java.io.IOException JavaDoc;
26 import java.nio.ByteBuffer JavaDoc;
27 import java.util.Arrays JavaDoc;
28 import java.util.List JavaDoc;
29
30 import org.snmp4j.smi.VariableBinding;
31 import java.util.ArrayList JavaDoc;
32
33 public class AgentXResponsePDU extends AgentXPDU {
34
35   private int sysUpTime;
36   private short errorStatus;
37   private short errorIndex;
38
39   private List JavaDoc variableBindings = new ArrayList JavaDoc();
40
41   public AgentXResponsePDU(int sysUpTime, short errorStatus, short errorIndex) {
42     super(AGENTX_RESPONSE_PDU);
43     this.sysUpTime = sysUpTime;
44     this.errorIndex = errorIndex;
45     this.errorStatus = errorStatus;
46   }
47
48   public AgentXResponsePDU(AgentXMessageHeader header) {
49     super(header);
50   }
51
52   public void decodePayload(ByteBuffer JavaDoc buf, int length) throws IOException JavaDoc {
53     sysUpTime = buf.getInt();
54     errorStatus = buf.getShort();
55     errorIndex = buf.getShort();
56     variableBindings = Arrays.asList(AgentXProtocol.decodeVariableBindings(buf));
57   }
58
59   protected void encodePayload(ByteBuffer JavaDoc buf) {
60     buf.putInt(sysUpTime);
61     buf.putShort(errorStatus);
62     buf.putShort(errorIndex);
63     AgentXProtocol.encodeVaribleBindings(buf, getVariableBindings());
64   }
65
66   public int getPayloadLength() {
67     return 2 * AgentXProtocol.AGENTX_INT_SIZE +
68         AgentXProtocol.getVariableBindingsLength(getVariableBindings());
69   }
70
71   public int getSysUpTime() {
72     return sysUpTime;
73   }
74
75   public VariableBinding[] getVariableBindings() {
76     VariableBinding[] vbs = (VariableBinding[])
77     variableBindings.toArray(new VariableBinding[variableBindings.size()]);
78     return vbs;
79   }
80
81   public int size() {
82     return variableBindings.size();
83   }
84
85   public short getErrorIndex() {
86     return errorIndex;
87   }
88
89   public short getErrorStatus() {
90     return errorStatus;
91   }
92
93   public void setVariableBindings(VariableBinding[] variableBindings) {
94     this.variableBindings = Arrays.asList(variableBindings);
95   }
96
97   public void setSysUpTime(int sysUpTime) {
98     this.sysUpTime = sysUpTime;
99   }
100
101   public void setErrorStatus(short errorStatus) {
102     this.errorStatus = errorStatus;
103   }
104
105   public void setErrorIndex(short errorIndex) {
106     this.errorIndex = errorIndex;
107   }
108
109   public void setErrorStatus(int errorStatus) {
110     this.errorStatus = (short)errorStatus;
111   }
112
113   public void setErrorIndex(int errorIndex) {
114     this.errorIndex = (short)errorIndex;
115   }
116
117   public void add(VariableBinding vb) {
118     variableBindings.add(vb);
119   }
120
121   public void clear() {
122     variableBindings.clear();
123   }
124
125   protected void beforeEncode() {
126   }
127
128   protected String JavaDoc toStringExtMembers() {
129     return super.toStringExtMembers()+",sysUpTime="+sysUpTime+",errorStatus="+
130         errorStatus+",errorIndex="+errorIndex+",vbs="+variableBindings;
131   }
132 }
133
Popular Tags