1 11 13 package com.sun.jmx.snmp ; 14 15 16 import java.io.Serializable ; 17 import java.io.UnsupportedEncodingException ; 18 19 import com.sun.jmx.snmp.SnmpDefinitions; 20 import com.sun.jmx.snmp.SnmpStatusException; 21 22 23 41 42 43 public class SnmpParameters extends SnmpParams implements Cloneable , Serializable { 44 45 50 public SnmpParameters() { 51 _readCommunity = defaultRdCommunity ; 52 _informCommunity = defaultRdCommunity ; 53 } 54 55 63 public SnmpParameters(String rdc, String wrc) { 64 _readCommunity = rdc ; 65 _writeCommunity = wrc ; 66 _informCommunity = defaultRdCommunity ; 67 } 68 69 77 public SnmpParameters(String rdc, String wrc, String inform) { 78 _readCommunity = rdc ; 79 _writeCommunity = wrc ; 80 _informCommunity = inform ; 81 } 82 83 87 public String getRdCommunity() { 88 return _readCommunity ; 89 } 90 91 95 public synchronized void setRdCommunity(String read) { 96 if (read == null) 97 _readCommunity = defaultRdCommunity ; 98 else 99 _readCommunity = read ; 100 } 101 102 106 public String getWrCommunity() { 107 return _writeCommunity ; 108 } 109 110 114 public void setWrCommunity(String write) { 115 _writeCommunity = write; 116 } 117 118 122 public String getInformCommunity() { 123 return _informCommunity ; 124 } 125 126 130 public void setInformCommunity(String inform) { 131 if (inform == null) 132 _informCommunity = defaultRdCommunity ; 133 else 134 _informCommunity = inform ; 135 } 136 137 141 public boolean allowSnmpSets() { 142 return _writeCommunity != null ; 143 } 144 145 152 public synchronized boolean equals(Object obj) { 153 if (!( obj instanceof SnmpParameters)) 154 return false; 155 156 if (this == obj) 157 return true ; 158 SnmpParameters param = (SnmpParameters) obj ; 159 if (_protocolVersion == param._protocolVersion) 160 if (_readCommunity.equals(param._readCommunity)) 161 return true ; 162 return false ; 163 } 164 165 169 public synchronized Object clone() { 170 SnmpParameters par = null ; 171 try { 172 par = (SnmpParameters) super.clone() ; 173 par._readCommunity = _readCommunity ; 175 par._writeCommunity = _writeCommunity ; 176 par._informCommunity = _informCommunity ; 177 } catch (CloneNotSupportedException e) { 178 throw new InternalError () ; } 180 return par ; 181 } 182 183 186 public byte[] encodeAuthentication(int snmpCmd) 187 throws SnmpStatusException { 188 try { 192 if (snmpCmd == pduSetRequestPdu) 193 return _writeCommunity.getBytes("8859_1"); 194 else if (snmpCmd == pduInformRequestPdu) 195 return _informCommunity.getBytes("8859_1") ; 196 else 197 return _readCommunity.getBytes("8859_1") ; 198 }catch(UnsupportedEncodingException e) { 199 throw new SnmpStatusException(e.getMessage()); 200 } 201 } 202 203 207 final static String defaultRdCommunity = "public" ; 208 209 214 private int _protocolVersion = snmpVersionOne ; 215 219 private String _readCommunity ; 220 224 private String _writeCommunity ; 225 229 private String _informCommunity ; 230 232 } 234 | Popular Tags |