(String) ArgumentParser.getValue(settings, oVersion, 0);
OctetString community =
createOctetString((String)
ArgumentParser.getValue(settings, oCommunity, 0),
"public");
Target t;
if ("1".equals(version)) {
t = new CommunityTarget();
t.setVersion(SnmpConstants.version1);
((CommunityTarget)t).setCommunity(community);
}
else if ("2c".equals(version)) {
t = new CommunityTarget();
t.setVersion(SnmpConstants.version2c);
((CommunityTarget)t).setCommunity(community);
}
else {
UserTarget ut = new UserTarget();
t = ut;
String ae = (String)
ArgumentParser.getValue(settings, oAuthoritativeEngineID, 0);
if (ae != null) {
ut.setAuthoritativeEngineID(createOctetString(ae, null).getValue());
}
ut.setSecurityModel(USM.SECURITY_MODEL_USM);
String sn = (String)
ArgumentParser.getValue(settings, oSecurityName, 0);
if (sn != null) {
ut.setSecurityName(createOctetString(sn, null));
}
Integer secLevel =
(Integer) ArgumentParser.getValue(settings, oSecLevel, 0);
if (secLevel == null) {
if (settings.containsKey(oPrivPassphrase)) {
ut.setSecurityLevel(SecurityLevel.AUTH_PRIV);
}
else if (settings.containsKey(oAuthPassphrase)) {
ut.setSecurityLevel(SecurityLevel.AUTH_NOPRIV);
}
else {
ut.setSecurityLevel(SecurityLevel.NOAUTH_NOPRIV);
}
}
else {
ut.setSecurityLevel(secLevel.intValue());
}
}
int retries = 0;
Number r = (Number) ArgumentParser.getValue(settings, oRetries, 0);
if (r != null) {
retries = r.intValue();
}
t.setRetries(retries);
long timeout = 5000;
Number to = (Number) ArgumentParser.getValue(settings, oTimeout, 0);
if (to != null) {
timeout = to.longValue();
}
t.setTimeout(timeout);
String addr = (String) ArgumentParser.getValue(settings, oAddress, 0);
if (addr != null) {
if (addr.indexOf('/') <= 0) {
addr += "/161";
}
t.setAddress(GenericAddress.parse(addr));
}
return t;
}