001: package com.dwipal;
002:
003: import java.io.*;
004:
005: public class DwSnmpMibRecord implements Serializable {
006: public static final int VALUE_TYPE_NONE = 0;
007: public static final int VALUE_TYPE_NULL = 1;
008: public static final int VALUE_TYPE_INTEGER32 = 2;
009: public static final int VALUE_TYPE_UNSIGNED_INTEGER32 = 3;
010: public static final int VALUE_TYPE_OCTET_STRING = 4;
011: public static final int VALUE_TYPE_OID = 5;
012: public static final int VALUE_TYPE_TIMETICKS = 6;
013: public static final int VALUE_TYPE_IP_ADDRESS = 7;
014:
015: public static int recNormal = 0;
016: public static int recVariable = -1;
017: public static int recTable = 1;
018:
019: public String name = "";
020: public String parent = "";
021: public int number = 0;
022: public String description = "";
023: public String access = "";
024: public String status = "";
025: public String syntax = "";
026: public int recordType = recNormal;
027: public int tableEntry = -1;
028: public String index = "";
029:
030: /*
031: recordType = recNormal/recVariable/recTable(1,2,3)
032: During parsing, it is always kept -1 ,1 or 0.
033:
034: This is used during tree generation...
035: During parsing, recordType is always kept 0 for simplification reason
036: recordType = 1 => it is ITSELF a table (i.e. its syntax is a Sequence)
037: = 2 => it is a entry (elements under "Entry" are actual elements
038: = 3 => it is an element. Index values are appended to it
039: instead of .0
040: = 0 => The entry is not in any table,i.e. it is a normal record :)
041:
042: Variable tableEntry is used to store the no. of entries the
043: table contains,i.e. number of values for each element of table.
044: -1 means it has not been initialized yet.
045: */
046:
047: DwSnmpMibRecord() {
048: init();
049: }
050:
051: public void init() {
052: name = "";
053: parent = "";
054: number = 0;
055: description = "";
056: access = "";
057: status = "";
058: syntax = "";
059: recordType = recNormal;
060: index = "";
061: }
062:
063: public String getCompleteString() {
064: String returnVal = new String("");
065: returnVal = returnVal.concat("Name : " + name + "\n");
066: returnVal = returnVal.concat("Parent : " + parent + "\n");
067: returnVal = returnVal.concat("Number : " + number + "\n");
068: returnVal = returnVal.concat("Access : " + access + "\n");
069: returnVal = returnVal.concat("Syntax : " + syntax + "");
070: returnVal = returnVal.concat("Status : " + status + "\n");
071: if (index.equals("") != true)
072: returnVal = returnVal.concat("Index : " + index + "\n");
073: String desc = "";
074: int i = 50;
075: while (i < desc.length()) {
076: desc = desc + description.substring(i - 50, i);
077: desc = desc + "\n";
078: i += 50;
079: }
080:
081: desc = desc + description.substring(i - 50);
082: returnVal = returnVal.concat("Description :" + desc + "\n");
083: returnVal = returnVal.concat("Type :" + recordType + "\n");
084:
085: return returnVal;
086: }
087:
088: public boolean isWritable() {
089: if (access.toUpperCase().indexOf("WRITE") != -1) {
090: return true;
091: }
092: return false;
093: }
094:
095: public String toString() {
096: return name;
097: }
098:
099: /**
100: * checkValidValue
101: *
102: * @param setValue String
103: * @return boolean
104: */
105: public boolean checkValidValue(String setValue) {
106: return true;
107: }
108:
109: public int getSyntaxID() {
110: String strType = syntax.trim().toUpperCase();
111: if (strType.indexOf("INTEGER") != -1)
112: return VALUE_TYPE_INTEGER32;
113: else if (strType.indexOf("COUNTER") != -1)
114: return VALUE_TYPE_UNSIGNED_INTEGER32;
115: else if (strType.indexOf("STRING") != -1)
116: return VALUE_TYPE_OCTET_STRING;
117: else if (strType.indexOf("OID") != -1)
118: return VALUE_TYPE_OID;
119: else if (strType.indexOf("TIMETICK") != -1)
120: return VALUE_TYPE_TIMETICKS;
121: else if (strType.indexOf("IPADDRESS") != -1)
122: return VALUE_TYPE_IP_ADDRESS;
123: else if (strType.indexOf("NULL") != -1)
124: return VALUE_TYPE_NULL;
125:
126: // Default: NONE.
127: return VALUE_TYPE_NONE;
128: }
129:
130: /**
131: * getSyntaxIDString
132: *
133: * @return String
134: */
135: public String getSyntaxIDString() {
136: switch (getSyntaxID()) {
137: case VALUE_TYPE_INTEGER32:
138: return "Integer";
139: case VALUE_TYPE_UNSIGNED_INTEGER32:
140: return "Unsigned Integer";
141: case VALUE_TYPE_OCTET_STRING:
142: return "Octet String";
143: case VALUE_TYPE_OID:
144: return "OID";
145: case VALUE_TYPE_TIMETICKS:
146: return "Time Ticks";
147: case VALUE_TYPE_IP_ADDRESS:
148: return "IP Address";
149: case VALUE_TYPE_NULL:
150: return "Null";
151: }
152: return "Unknown";
153: }
154: }
|