KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > dwipal > DwSnmpMibRecord


1 package com.dwipal;
2
3 import java.io.*;
4
5 public class DwSnmpMibRecord
6     implements Serializable {
7   public static final int VALUE_TYPE_NONE = 0;
8   public static final int VALUE_TYPE_NULL = 1;
9   public static final int VALUE_TYPE_INTEGER32 = 2;
10   public static final int VALUE_TYPE_UNSIGNED_INTEGER32 = 3;
11   public static final int VALUE_TYPE_OCTET_STRING = 4;
12   public static final int VALUE_TYPE_OID = 5;
13   public static final int VALUE_TYPE_TIMETICKS = 6;
14   public static final int VALUE_TYPE_IP_ADDRESS = 7;
15
16   public static int recNormal = 0;
17   public static int recVariable = -1;
18   public static int recTable = 1;
19
20   public String JavaDoc name = "";
21   public String JavaDoc parent = "";
22   public int number = 0;
23   public String JavaDoc description = "";
24   public String JavaDoc access = "";
25   public String JavaDoc status = "";
26   public String JavaDoc syntax = "";
27   public int recordType = recNormal;
28   public int tableEntry = -1;
29   public String JavaDoc index = "";
30
31   /*
32    recordType = recNormal/recVariable/recTable(1,2,3)
33    During parsing, it is always kept -1 ,1 or 0.
34
35    This is used during tree generation...
36    During parsing, recordType is always kept 0 for simplification reason
37    recordType = 1 => it is ITSELF a table (i.e. its syntax is a Sequence)
38         = 2 => it is a entry (elements under "Entry" are actual elements
39         = 3 => it is an element. Index values are appended to it
40         instead of .0
41         = 0 => The entry is not in any table,i.e. it is a normal record :)
42
43    Variable tableEntry is used to store the no. of entries the
44    table contains,i.e. number of values for each element of table.
45    -1 means it has not been initialized yet.
46    */

47
48   DwSnmpMibRecord() {
49     init();
50   }
51
52   public void init() {
53     name = "";
54     parent = "";
55     number = 0;
56     description = "";
57     access = "";
58     status = "";
59     syntax = "";
60     recordType = recNormal;
61     index = "";
62   }
63
64   public String JavaDoc getCompleteString() {
65     String JavaDoc returnVal = new String JavaDoc("");
66     returnVal = returnVal.concat("Name : " + name + "\n");
67     returnVal = returnVal.concat("Parent : " + parent + "\n");
68     returnVal = returnVal.concat("Number : " + number + "\n");
69     returnVal = returnVal.concat("Access : " + access + "\n");
70     returnVal = returnVal.concat("Syntax : " + syntax + "");
71     returnVal = returnVal.concat("Status : " + status + "\n");
72     if (index.equals("") != true) returnVal = returnVal.concat("Index : " + index + "\n");
73     String JavaDoc desc = "";
74     int i = 50;
75     while (i < desc.length()) {
76       desc = desc + description.substring(i - 50, i);
77       desc = desc + "\n";
78       i += 50;
79     }
80
81     desc = desc + description.substring(i - 50);
82     returnVal = returnVal.concat("Description :" + desc + "\n");
83     returnVal = returnVal.concat("Type :" + recordType + "\n");
84
85     return returnVal;
86   }
87
88   public boolean isWritable() {
89     if(access.toUpperCase().indexOf("WRITE")!=-1) {
90       return true;
91     }
92     return false;
93   }
94   public String JavaDoc toString() {
95     return name;
96   }
97
98   /**
99    * checkValidValue
100    *
101    * @param setValue String
102    * @return boolean
103    */

104   public boolean checkValidValue(String JavaDoc setValue) {
105     return true;
106   }
107
108   public int getSyntaxID() {
109     String JavaDoc strType=syntax.trim().toUpperCase();
110     if(strType.indexOf("INTEGER")!=-1)
111       return VALUE_TYPE_INTEGER32;
112     else if(strType.indexOf("COUNTER") !=-1)
113       return VALUE_TYPE_UNSIGNED_INTEGER32;
114     else if(strType.indexOf("STRING") !=-1)
115       return VALUE_TYPE_OCTET_STRING;
116     else if(strType.indexOf("OID")!=-1)
117       return VALUE_TYPE_OID;
118     else if(strType.indexOf("TIMETICK") !=-1)
119       return VALUE_TYPE_TIMETICKS;
120     else if(strType.indexOf("IPADDRESS") !=-1)
121       return VALUE_TYPE_IP_ADDRESS;
122     else if(strType.indexOf("NULL") !=-1)
123       return VALUE_TYPE_NULL;
124
125     // Default: NONE.
126
return VALUE_TYPE_NONE;
127   }
128
129   /**
130    * getSyntaxIDString
131    *
132    * @return String
133    */

134   public String JavaDoc getSyntaxIDString() {
135     switch(getSyntaxID()) {
136       case VALUE_TYPE_INTEGER32:
137         return "Integer";
138       case VALUE_TYPE_UNSIGNED_INTEGER32:
139         return "Unsigned Integer";
140       case VALUE_TYPE_OCTET_STRING:
141         return "Octet String";
142       case VALUE_TYPE_OID:
143         return "OID";
144       case VALUE_TYPE_TIMETICKS:
145         return "Time Ticks";
146       case VALUE_TYPE_IP_ADDRESS:
147         return "IP Address";
148       case VALUE_TYPE_NULL:
149         return "Null";
150     }
151     return "Unknown";
152   }
153 }
154
155
156
157
Popular Tags