001: /*
002: * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: *
023: * Free Software Foundation, Inc.
024: * 59 Temple Place, Suite 330
025: * Boston, MA 02111-1307 USA
026: *
027: * @author Nam Nguyen
028: */
029:
030: package com.caucho.server.snmp.types;
031:
032: /*
033: * Represents a complete SNMP message.
034: */
035: public class SnmpMessageValue extends SnmpValue {
036: IntegerValue _version = IntegerValue.ZERO;
037: OctetStringValue _communityString = OctetStringValue.PUBLIC;
038:
039: PduValue _pdu;
040:
041: public SnmpMessageValue(int version, String community, PduValue pdu) {
042: this (new IntegerValue(version),
043: new OctetStringValue(community), pdu);
044: }
045:
046: public SnmpMessageValue(IntegerValue version,
047: OctetStringValue community, PduValue pdu) {
048: _version = version;
049: _communityString = community;
050: _pdu = pdu;
051: }
052:
053: @Override
054: public int getType() {
055: return SnmpValue.SEQUENCE;
056: }
057:
058: @Override
059: public void toAsn1(StringBuilder sb) {
060: StringBuilder innerSb = new StringBuilder();
061:
062: _version.toAsn1(innerSb);
063: _communityString.toAsn1(innerSb);
064: _pdu.toAsn1(innerSb);
065:
066: header(sb, innerSb.length());
067:
068: sb.append(innerSb.toString());
069: }
070:
071: public IntegerValue getVersion() {
072: return _version;
073: }
074:
075: public void setVersion(int version) {
076: _version = new IntegerValue(version);
077: }
078:
079: public void setVersion(IntegerValue version) {
080: _version = version;
081: }
082:
083: public OctetStringValue getCommunityString() {
084: return _communityString;
085: }
086:
087: public void setCommunityString(String communityString) {
088: _communityString = new OctetStringValue(communityString);
089: }
090:
091: public void setCommunityString(OctetStringValue communityString) {
092: _communityString = communityString;
093: }
094:
095: public PduValue getPdu() {
096: return _pdu;
097: }
098:
099: public void setPdu(PduValue pdu) {
100: _pdu = pdu;
101: }
102:
103: public void setError(int error) {
104: _pdu.setError(error);
105: }
106:
107: public void setError(IntegerValue error) {
108: _pdu.setError(error);
109: }
110:
111: public IntegerValue getError() {
112: return _pdu.getError();
113: }
114:
115: public void setErrorIndex(int errorIndex) {
116: _pdu.setErrorIndex(errorIndex);
117: }
118:
119: public void setErrorIndex(IntegerValue errorIndex) {
120: _pdu.setErrorIndex(errorIndex);
121: }
122:
123: public IntegerValue getErrorIndex() {
124: return _pdu.getErrorIndex();
125: }
126:
127: public void setRequestId(int id) {
128: _pdu.setRequestId(id);
129: }
130:
131: public void setRequestId(IntegerValue id) {
132: _pdu.setRequestId(id);
133: }
134:
135: public IntegerValue getRequestId() {
136: return _pdu.getRequestId();
137: }
138:
139: public void addVarBind(VarBindValue obj) {
140: _pdu.addVarBind(obj);
141: }
142:
143: public void addVarBindList(VarBindListValue list) {
144: _pdu.addVarBindList(list);
145: }
146:
147: public VarBindListValue getVarBindList() {
148: return _pdu.getVarBindList();
149: }
150:
151: public String toString() {
152: return "SnmpMessage[" + _version + "," + _communityString + ","
153: + _pdu + "]";
154: }
155: }
|