KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > snmp4j > agent > io > DefaultMOInput


1 /*_############################################################################
2   _##
3   _## SNMP4J-Agent - DefaultMOInput.java
4   _##
5   _## Copyright (C) 2005-2007 Frank Fock (SNMP4J.org)
6   _##
7   _## Licensed under the Apache License, Version 2.0 (the "License");
8   _## you may not use this file except in compliance with the License.
9   _## You may obtain a copy of the License at
10   _##
11   _## http://www.apache.org/licenses/LICENSE-2.0
12   _##
13   _## Unless required by applicable law or agreed to in writing, software
14   _## distributed under the License is distributed on an "AS IS" BASIS,
15   _## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   _## See the License for the specific language governing permissions and
17   _## limitations under the License.
18   _##
19   _##########################################################################*/

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 JavaDoc 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 JavaDoc 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 JavaDoc 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 JavaDoc 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 JavaDoc 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 JavaDoc next = null;
97     try {
98       next = ois.readObject();
99     }
100     catch (ClassNotFoundException JavaDoc 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 JavaDoc ex1) {
109         logger.error("Failed to skip Context: " + ex1.getMessage());
110       }
111     }
112   }
113
114   public void skipManagedObject(MOInfo moInfo) throws IOException {
115     Object JavaDoc next = null;
116     try {
117       next = ois.readObject();
118     }
119     catch (ClassNotFoundException JavaDoc 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 JavaDoc 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