1 20 21 22 package org.snmp4j.agent.io; 23 24 import java.io.*; 25 26 import org.snmp4j.log.*; 27 import org.snmp4j.smi.*; 28 29 public class DefaultMOInput implements MOInput { 30 31 private static final LogAdapter logger = 32 LogFactory.getLogger(DefaultMOInput.class); 33 34 private int importMode; 35 private ObjectInputStream ois; 36 37 public DefaultMOInput(ObjectInputStream ois) { 38 this.ois = ois; 39 } 40 41 public int getImportMode() { 42 return importMode; 43 } 44 45 public Context readContext() throws IOException { 46 try { 47 return (Context) ois.readObject(); 48 } 49 catch (ClassNotFoundException ex) { 50 logger.error("Failed to load Context: " + ex.getMessage()); 51 return null; 52 } 53 } 54 55 public IndexedVariables readIndexedVariables() throws IOException { 56 try { 57 return (IndexedVariables) ois.readObject(); 58 } 59 catch (ClassNotFoundException ex) { 60 logger.error("Failed to load IndexedVariables: " + ex.getMessage()); 61 return null; 62 } 63 } 64 65 public MOInfo readManagedObject() throws IOException { 66 try { 67 return (MOInfo) ois.readObject(); 68 } 69 catch (ClassNotFoundException ex) { 70 logger.error("Failed to load MOInfo: " + ex.getMessage()); 71 return null; 72 } 73 } 74 75 public Sequence readSequence() throws IOException { 76 try { 77 return (Sequence) ois.readObject(); 78 } 79 catch (ClassNotFoundException ex) { 80 logger.error("Failed to load Sequence: " + ex.getMessage()); 81 return null; 82 } 83 } 84 85 public Variable readVariable() throws IOException { 86 try { 87 return (Variable) ois.readObject(); 88 } 89 catch (ClassNotFoundException ex) { 90 logger.error("Failed to load Variable: " + ex.getMessage()); 91 return null; 92 } 93 } 94 95 public void skipContext(Context context) throws IOException { 96 Object next = null; 97 try { 98 next = ois.readObject(); 99 } 100 catch (ClassNotFoundException ex) { 101 logger.error("Failed to skip Context: " + ex.getMessage()); 102 next = null; 103 } 104 while ((!(next instanceof Context)) || (!((Context)next).equals(context))) { 105 try { 106 next = ois.readObject(); 107 } 108 catch (ClassNotFoundException ex1) { 109 logger.error("Failed to skip Context: " + ex1.getMessage()); 110 } 111 } 112 } 113 114 public void skipManagedObject(MOInfo moInfo) throws IOException { 115 Object next = null; 116 try { 117 next = ois.readObject(); 118 } 119 catch (ClassNotFoundException ex) { 120 logger.error("Failed to skip Context: " + ex.getMessage()); 121 next = null; 122 } 123 while ((!(next instanceof MOInfo)) || (!((MOInfo)next).equals(moInfo))) { 124 try { 125 next = ois.readObject(); 126 } 127 catch (ClassNotFoundException ex1) { 128 logger.error("Failed to skip Context: " + ex1.getMessage()); 129 } 130 } 131 } 132 133 public void setOverwriteMode(int importMode) { 134 this.importMode = importMode; 135 } 136 } 137 | Popular Tags |