1 20 21 22 package org.snmp4j.util; 23 24 import org.snmp4j.*; 25 import org.snmp4j.mp.SnmpConstants; 26 27 38 public class DefaultPDUFactory implements PDUFactory { 39 40 private int pduType = PDU.GET; 41 42 45 public DefaultPDUFactory() { 46 } 47 48 53 public DefaultPDUFactory(int pduType) { 54 setPduType(pduType); 55 } 56 57 public void setPduType(int pduType) { 58 this.pduType = pduType; 59 } 60 61 public int getPduType() { 62 return pduType; 63 } 64 65 72 public PDU createPDU(Target target) { 73 return createPDU(target, pduType); 74 } 75 76 86 public static PDU createPDU(Target target, int pduType) { 87 PDU request = createPDU(target.getVersion()); 88 request.setType(pduType); 89 return request; 90 } 91 92 100 public static PDU createPDU(int targetVersion) { 101 PDU request; 102 switch (targetVersion) { 103 case SnmpConstants.version3: { 104 request = new ScopedPDU(); 105 break; 106 } 107 case SnmpConstants.version1: { 108 request = new PDUv1(); 109 break; 110 } 111 default: 112 request = new PDU(); 113 } 114 return request; 115 } 116 } 117 | Popular Tags |