simplenode.java
来自「opennms得相关源码 请大家看看」· Java 代码 · 共 1,164 行 · 第 1/3 页
JAVA
1,164 行
/* String fullOid = (String)oidNames.get(parent); if (printDebug) System.out.println("found fullOid **** =" + fullOid); fullOid = fullOid + "." + textOid; oidNames.put(textOid, fullOid); if (printDebug) System.out.println("added to oidNames: " + fullOid); */ } } // end if foundDeclOID } // end if children != null } // end collectOIDS /** * Walk the abstract syntax tree and collect information about * any OID in a table */ public void collectTableInfo() { //if (printDebug) System.out.println("collectTableInfo node=" + this.toString()); if (this.getVisited() == true) { return; } // auiTable OBJECT-TYPE // SYNTAX SEQUENCE OF AuiEntry ... // Save the name ("auiTable") as the value, and the entry ("AuiEntry") as the key // The entry is the key so that we can search it later by entry when we get the // sequence entry (in collectSequenceInfo) // entryNameAndTableName is the symbol table Hashtable // The tree looks like: // DeclOID default visited=false children=4 // ObjectIdentifier auiTable visited=false children=0 // TableSequenceOf AuiEntry visited=false children=0 // GetAccessIdentifier read-only visited=false children=0 // Parent auiTable visited=false children=0 // PartialOID 1 visited=false children=0 boolean declOidFound = ParseMibTreeConstants.jjtNodeName[this.id].equals( "DeclOID"); // walk through and see if it contains a TableSequenceOf node if (children != null) { // walk through the children and collect information String tableName = null; String entryName = null; for (int i = 0; i < children.length; ++i) { SimpleNode n = (SimpleNode) children[i]; if (n != null) { if (ParseMibTreeConstants.jjtNodeName[n.getId()].equals("Parent")) { tableName = n.identifier_text; } else if (ParseMibTreeConstants.jjtNodeName[n.getId()].equals( "TableSequenceOf")) { // could mark the parent as a table here if we wanted to entryName = n.identifier_text; } } // end if if (n != null) { n.collectTableInfo(); n.setVisited(true); } } // end for // we know we have found a table if entryName != null if (declOidFound && entryName != null) { if (printDebug) { System.out.println("collectTableInfo adding " + entryName + "/" + tableName); } entryNameAndTableName.put(entryName, tableName); } } } // end collectTableInfo /** * Walk the abstract syntax tree and collect SEQUENCE information about * any OID in a table */ public void collectSequenceInfo() { //if (printDebug) System.out.println("collectSequenceInfo node=" + this.toString()); if (this.getVisited() == true) { return; } // Look for a tree starting with "TableOidVars" // 1) the first child is the index of the table // 2) add every entry with the table name entry as the value (from example below "AuiEntry") // TableOidVars AuiEntry visited=false children=5 // IdentifierInSequenceOfVars auiTableIndex visited=false children=0 // IdentifierInSequenceOfVars activeSessions visited=false children=0 // IdentifierInSequenceOfVars inactiveSessions visited=false children=0 // IdentifierInSequenceOfVars openCursors visited=false children=0 // IdentifierInSequenceOfVars accounts visited=false children=0 String entryName = this.getName(); String tableName = (String) entryNameAndTableName.get(entryName); if (children != null) { // walk through the children and collect information String indexName = null; for (int i = 0; i < children.length; ++i) { SimpleNode n = (SimpleNode) children[i]; if (n.getIsOidInTable()) { if (printDebug) { System.out.println("adding OID " + n.getName() + " to table"); // put all the OID vars in a symbol table (hashtable) oidName/tableName } oidVarsTableName.put(n.getName(), tableName); } if (n != null) { n.collectSequenceInfo(); n.setVisited(true); } } // end for } } // end collectSequenceInfo /** * Walk the abstract syntax tree and collect information about * the index of a table. By convention, the index of a table is the * first variable in the MIB SEQUENCE delcaration. */ public void collectTableIndexInfo() { //if (printDebug) System.out.println("collectTableIndexInfo node=" + this.toString()); if (this.getVisited() == true) { return; } // auiTable OBJECT-TYPE // SYNTAX SEQUENCE OF AuiEntry ... // Save the name ("auiTable") as the value, and the entry ("AuiEntry") as the key // The entry is the key so that we can search it later by entry when we get the // sequence entry (in collectSequenceInfo) // entryNameAndTableName is the symbol table Hashtable // The tree looks like: // TableOidVars AuiEntry visited=false children=5 // IdentifierInSequenceOfVars auiTableIndex visited=false children=0 // IdentifierInSequenceOfVars activeSessions visited=false children=0 // IdentifierInSequenceOfVars inactiveSessions visited=false children=0 // IdentifierInSequenceOfVars openCursors visited=false children=0 // IdentifierInSequenceOfVars accounts visited=false children=0 String entryName = this.getName(); String tableName = (String) entryNameAndTableName.get(entryName); if (children != null) { // walk through the children and collect information String indexName = null; for (int i = 0; i < children.length; ++i) { SimpleNode n = (SimpleNode) children[i]; if (i == 0) { // the index is always the first child if (ParseMibTreeConstants.jjtNodeName[n.getId()].equals( "IdentifierInSequenceOfVars")) { indexName = n.identifier_text; } } // end if if (n.getIsOidInTable()) { // this was set during parsing if (printDebug) { System.out.println("adding OID " + n.getName() + " to table"); // put all the OID vars in a symbol table (hashtable) oidName/tableName } oidVarsTableName.put(n.getName(), tableName); } if (n != null) { n.collectTableIndexInfo(); n.setVisited(true); } } // end for // we know we have found a table if indexName |= null if (indexName != null) { if (printDebug) { System.out.println("collectTableIndexInfo indexName=" + indexName); } if (printDebug) { System.out.println("collectTableIndexInfo entryName=" + entryName); } if (printDebug) { System.out.println("collectTableIndexInfo tableName=" + tableName); } tableAndIndex.put(tableName, indexName); } } } // end collectTableIndexInfo /** * Walk the abstract syntax tree and collect information about * any TEXTUAL-CONVENTIONS. The reason for collecting these in * a symbol table is that this relates the underlying type to * the text name and it is the underlying type that would need * to be printed in the xml. */ public void collectTextualConventionsInfo() { //if (printDebug) System.out.println("collectTextualConventionsInfo node=" + this.toString()); if (this.getVisited() == true) { return; } // Look for a tree starting with "TextConvention" or "Assignment" // 0) the node TextConvention has some type name // 1) the first child is the base type, that is referred to by the type name above // TextConvention VasStates visited=false children=1 // GetTypeIdentifier Integer32 visited=false children=0 boolean textConventionFound = ParseMibTreeConstants.jjtNodeName[this.id]. equals("TextConvention") || ParseMibTreeConstants.jjtNodeName[this.id].equals("Assignment"); // walk through and find the index of the table which is the first child String typeName = this.getName(); String baseTypeName = null; // will be in the child if (children != null) { // walk through the children and collect information String indexName = null; for (int i = 0; i < children.length; ++i) { SimpleNode n = (SimpleNode) children[i]; if (textConventionFound) { if (printDebug) { System.out.println("adding OID " + n.getName() + "/" + typeName + " to typeNametable"); // put all the OID vars in a symbol table (hashtable) oidName/tableName } baseTypeName = n.getName(); typeNameTable.put(typeName, baseTypeName); } if (n != null) { n.collectTextualConventionsInfo(); n.setVisited(true); } } // end for } } // end collectTextualConventionInfo /** * Walk the symbol tables and output XML */ public void writeOids() { // write something like: // <mibObj oid=".1.3.6.1.2.1.2.2.1.10" instance="ifIndex" alias="ifInOctets" type="counter"/> StringBuffer sb = new StringBuffer(); OidValues oidValues = null; TreeMap sortedMap = new TreeMap(); if (printDebug) { System.out.println("Sorted OIDS from Vector"); } sb = new StringBuffer(); for (int i = 0; i < orderList.size(); i++) { String name = (String) orderList.elementAt(i); oidValues = (OidValues) oidNames.get(name); if (! (oidValues.getTypeId().equals("DEFAULT") || oidValues.getAccess().equals(OidValues.NOT_ACCESSIBLE))) { String instanceVar = "0"; // TBD get the table instance var String aliasVar = oidValues.getTextOid(); int index = aliasVar.lastIndexOf(".") + 1; String lastOidStr = aliasVar.substring(index); String tableName = (String) oidVarsTableName.get(lastOidStr); String numericOid = oidValues.getNumericOid(); String typeName = oidValues.getTypeId(); String typeFromTable = (String) typeNameTable.get(typeName); if (typeFromTable != null) { typeName = typeFromTable; // this gets the base type } if (tableName != null) { instanceVar = (String) tableAndIndex.get(tableName); } // There is a 19 char rrd limitation. Catenate a string onto the alias. if (lastOidStr.length() > tooLongSize) { lastOidStr = lastOidStr + TOO_LONG; } sb.append("<mibObj oid=\"").append(numericOid).append("\" "); sb.append("instance=\"").append(instanceVar).append("\" "); sb.append("alias=\"").append(lastOidStr).append("\" "); sb.append("type=\"").append(typeName).append("\" />").append("\n"); System.out.print(sb.toString()); sortedMap.put(numericOid, sb.toString()); sb = new StringBuffer(); } else { if (printDebug && oidValues.getTypeId().equals("DEFAULT")) { System.out.println("skipping oid with DEFAULT type, oid=" + oidValues.getTextOid()); } if (printDebug && oidValues.getAccess().equals(OidValues.NOT_ACCESSIBLE)) { System.out.println("skipping oid with no ACCESS, oid=" + oidValues.getAccess()); } } } } // end writeOIDS /** * Dump the oidNames symbol tables - primarily debugging routine */ public void dumpOidNamesSymbolTable() { StringBuffer sb = new StringBuffer(); OidValues oidValues = null; String key = null; String oidName = null; sb.append("Symbol Table oidNames for text OID/OidValues\n"); for (Enumeration e = oidNames.keys(); e.hasMoreElements(); ) { key = (String) e.nextElement(); oidValues = (OidValues) oidNames.get(key); sb.append(key + "/" + oidValues.toString()).append("\n"); } if (printDebug) { System.out.println(sb.toString()); } } /** * Dump the symbol tables - primarily debugging routine */ public void dumpSymbolTables() { StringBuffer sb = new StringBuffer(); OidValues oidValues = null; String key = null; String oidName = null; String entryName = null; String indexName = null; String baseType = null; dumpOidNamesSymbolTable(); sb.append("Symbol Table oidVarsTableName for tableName/OidName\n"); for (Enumeration e = oidVarsTableName.keys(); e.hasMoreElements(); ) { key = (String) e.nextElement(); oidName = (String) oidVarsTableName.get(key); sb.append(key + "/" + oidName).append("\n"); } sb.append("Symbol Table entryNameAndTableName for entryName/tableName\n"); for (Enumeration e = entryNameAndTableName.keys(); e.hasMoreElements(); ) { key = (String) e.nextElement(); entryName = (String) entryNameAndTableName.get(key); sb.append(key + "/" + entryName).append("\n"); } sb.append("Symbol Table tableAndIndex for tableName/indexName\n"); for (Enumeration e = tableAndIndex.keys(); e.hasMoreElements(); ) { key = (String) e.nextElement(); indexName = (String) tableAndIndex.get(key); sb.append(key + "/" + indexName).append("\n"); } sb.append("Symbol Table typeNameTable for type/baseType\n"); for (Enumeration e = typeNameTable.keys(); e.hasMoreElements(); ) { key = (String) e.nextElement(); baseType = (String) typeNameTable.get(key); sb.append(key + "/" + baseType).append("\n"); } if (printDebug) { System.out.println(sb.toString()); } } // end dumpSymbolTables}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?