⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 snmpmiboid.java

📁 Mobile 应用程序使用 Java Micro Edition (Java ME) 平台
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
     */    public void registerNode(String oidString ,SnmpMibNode node) 	throws IllegalAccessException {        SnmpOid oid= new SnmpOid(oidString);        registerNode(oid.longValue(), 0, node);    }        // PROTECTED METHODS    //------------------        /**     * Registers a specific node in the tree.     */    void registerNode(long[] oid, int cursor ,SnmpMibNode node) 	throws IllegalAccessException {                if (cursor >= oid.length)            throw new IllegalAccessException();            // Check if the node is already defined         //        long var= oid[cursor];        //System.out.println("entering registration for val=" 	// + String.valueOf(var) + " position= " + cursor);        int pos = retrieveIndex(var);        if (pos  == nbChildren) {            nbChildren++;            varList= new int[nbChildren];            varList[0]= (int) var;            pos =0;            if ( (cursor + 1) == oid.length) {                // That 's the end of the trip. 		// Do not forward the registration                 //System.out.println("End of trip for val=" 		//      + String.valueOf(var) + " position= " + cursor);                children.insertElementAt(node,pos);                return;            }            //System.out.println("Create node for val=" 	    //       + String.valueOf(var) + " position= " + cursor);            SnmpMibOid child= new SnmpMibOid();            children.insertElementAt(child, pos);            child.registerNode(oid, cursor + 1, node);            return;        }        if (pos == -1) {            // The node is not yet registered            //            int[] tmp= new int[nbChildren + 1];            tmp[nbChildren]= (int) var;            System.arraycopy(varList, 0, tmp, 0, nbChildren);            varList= tmp;            nbChildren++;            SnmpMibNode.sort(varList);            int newPos = retrieveIndex(var);            varList[newPos]= (int) var;            if ( (cursor + 1) == oid.length) {                // That 's the end of the trip.		// Do not forward the registration                                 //System.out.println("End of trip for val=" 		//     + String.valueOf(var) + " position= " + cursor);                children.insertElementAt(node, newPos);                return;            }            SnmpMibOid child= new SnmpMibOid();            // System.out.println("Create node for val=" + 	    //     String.valueOf(var) + " position= " + cursor);            children.insertElementAt(child, newPos);            child.registerNode(oid, cursor + 1, node);            return;        }         else {            // The node is already registered            //            SnmpMibNode child= (SnmpMibNode) children.elementAt(pos);            if ( (cursor + 1) == oid.length ) {                //System.out.println("Node already registered val=" + 		//          String.valueOf(var) + " position= " + cursor);		if (child == node) return;		if (child != null && node != null) {		    // Now we're going to patch the tree the following way:		    //   if a subgroup has been registered before its father,		    //   we're going to replace the father OID node with 		    //   the actual group-node and export the children from 		    //   the temporary OID node to the actual group node.		    //		    if (node instanceof SnmpMibGroup) {			// `node' is a group => replace `child' with `node'			// export the child's subtree to `node'.			//			((SnmpMibOid)child).exportChildren((SnmpMibOid)node);			children.setElementAt(node,pos);			return;		    } else if ((node instanceof SnmpMibOid) &&			     (child instanceof SnmpMibGroup)) {			// `node' is a temporary node, and `child' is a 			//  group => keep child and export the node's 			//  subtree to `child'.			//			((SnmpMibOid)node).exportChildren((SnmpMibOid)child);			return;		    } else if (node instanceof SnmpMibOid) {			// `node' and `child' are both temporary OID nodes			// => replace `child' with `node' and export child's			// subtree to `node'.			//			((SnmpMibOid)child).exportChildren((SnmpMibOid)node);			children.setElementAt(node,pos);			return;		    }		}		children.setElementAt(node,pos);                return;            } else {		if (child == null)		    throw new IllegalAccessException();                ((SnmpMibOid)child).registerNode(oid, cursor + 1, node);            }        }    }        /**     * Export this node's children to a brother node that will replace     * this node in the OID tree.     * This method is a patch that fixes the problem of registering     * a subnode before its father node.     *     **/    void exportChildren(SnmpMibOid brother) 	throws IllegalAccessException {		if (brother == null) return;	final long[] oid = new long[1];	for (int i=0; i<nbChildren; i++) {	    final SnmpMibNode child = (SnmpMibNode)children.elementAt(i);	    if (child == null) continue;	    oid[0] = varList[i];	    brother.registerNode(oid,0,child);	}    }    // PRIVATE METHODS    //----------------      SnmpMibNode getChild(long id) throws SnmpStatusException {                // first we need to retrieve the identifier in the list of children         //        final int pos= getInsertAt(id);        if (pos >= nbChildren)            throw noSuchObjectException;            if (varList[pos] != (int) id)             throw noSuchObjectException;        // Access the node        //	SnmpMibNode child = null;        try {            child = (SnmpMibNode) children.elementAtNonSync(pos);        } catch(ArrayIndexOutOfBoundsException e) {            throw noSuchObjectException;        }	if (child == null)             throw noSuchInstanceException;	return child;    }      private int retrieveIndex(long val) {        int low= 0;        int cursor= (int) val;	if (varList == null || varList.length < 1) 	    return nbChildren;        int max= varList.length -1 ;        int curr= low + (max-low)/2;        int elmt= 0;        while (low <= max) {            elmt= varList[curr];            if (cursor == elmt) {                // We need to get the next index ...                //                return curr;            }              if (elmt < cursor) {                low= curr +1;            } else {                max= curr -1;            }              curr= low + (max-low)/2;        }        return -1;    }      private int getInsertAt(long val) {                int low= 0;        final int index= (int) val;	if (varList == null)             return -1;        int max= varList.length -1 ;        int elmt=0;	//final int[] v = varList;        //if (index > a[max])        //return max +1;              int curr= low + (max-low)/2;            while (low <= max) {            elmt= varList[curr];            // never know ...we might find something ...            //             if (index == elmt)                return curr;            if (elmt < index) {                low= curr +1;            } else {                max= curr -1;            }              curr= low + (max-low)/2;        }        return curr;    }        // PRIVATE VARIABLES    //------------------    /**     * Contains the list of sub nodes.     */    private NonSyncVector children=  new NonSyncVector(1);        /**     * The number of sub nodes.     */    private int nbChildren= 0;            // All the methods of the Vector class are synchronized.    // Synchronization is a very expensive operation. In our case it is     // not always required...    //    class NonSyncVector extends Vector {	        public NonSyncVector(int size) {            super(size);        }	        final void addNonSyncElement(Object obj) {            ensureCapacity(elementCount + 1);            elementData[elementCount++] = obj;        }	        final Object elementAtNonSync(int index) {            return elementData[index];        }	    }} 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -