package jni; import java.util.* ; import tools.*; import java.lang.Integer; import java.lang.Byte; import java.util.StringTokenizer; import com.sun.jaw.snmp.common.*; /** * Klasse zur Verwendung von Java-Native Methoden<BR> * Diese Methoden werden an dieser Stelle angegeben, aber noch * nicht implementiert.<BR> Dies geschieht in dem entsprechenden * C++ File (nativeBase.cpp). * @version created 14.12.1998 * @since 0.99 */ public class nativeBase { // get public static native String getStringNative(int[] mibVarOID); public static native int getIntNative(int[] mibVarOID); // get Methods to convert Data in accessible format /** * Get the IpAddress Property of NetworkParms and turn it * into a Byte-array. like this :<BR> * [127.0.0.1] -> 91,49,50,55,46,48,46,48,46,49,93<BR> * @param mibVarOID OID as int-Array * @return Byte-Array */ public static Byte[] getIpAddress(int[] mibVarOID) { String tempString = getStringNative(mibVarOID); SnmpString snmpString = new SnmpString(tempString); return snmpString.toByte(); } /** * Get the SubnetMask Property of NetworkParms and turn it * into a Byte-array. like this :<BR> * [127.0.0.1] -> 91,49,50,55,46,48,46,48,46,49,93<BR> * @param mibVarOID OID as int-Array * @return Byte-Array */ public static Byte[] getSubnetMask(int[] mibVarOID) { String tempString = getStringNative(mibVarOID); SnmpString snmpString = new SnmpString(tempString); return snmpString.toByte(); } /** * Get the Adress Format "[0.0.0.0]" and convert it * into a Byte-array. like this :<BR> * [127.0.0.1] -> 91,49,50,55,46,48,46,48,46,49,93<BR> * @param mibVarOID OID as int-Array * @return Byte-Array */ public static Byte[] getByteArray(int[] mibVarOID) { String tempString = getStringNative(mibVarOID); SnmpString snmpString = new SnmpString(tempString); return snmpString.toByte(); } // getNext public static native int getNextIntNative(int[][] mibVarOID, int oidIndex); public static native String getNextStringNative(int[][] mibVarOID, int oidIndex); public static native String[] getIndexedStringNative(int[][] oids, int IndexRange); public static native int[] getIndexedIntNative(int[][] oids, int IndexRange); // set public static native void setNative(int[] mibVarOID, int value); public static native void setNative(int[] mibVarOID, String value); // set Methods to convert Da\chapter{Realisierung der proprietären Schnittstelle} \label{anhang_b} \section{Java Teilbereich} \begin{verbatim} package jni; import java.util.* ; import tools.*; import java.lang.Integer; import java.lang.Byte; import java.util.StringTokenizer; import com.sun.jaw.snmp.common.*; /** * Klasse zur Verwendung von Java-Native Methoden<BR> * Diese Methoden werden an dieser Stelle angegeben, aber noch * nicht implementiert.<BR> Dies geschieht in dem entsprechenden * C++ File (nativeBase.cpp). * @version created 14.12.1998 * @since 0.99 */ public class nativeBase { // get public static native String getStringNative(int[] mibVarOID); public static native int getIntNative(int[] mibVarOID); // get Methods to convert Data in accessible format /** * Get the IpAddress Property of NetworkParms and turn it * into a Byte-array. like this :<BR> * [127.0.0.1] -> 91,49,50,55,46,48,46,48,46,49,93<BR> * @param mibVarOID OID as int-Array * @return Byte-Array */ public static Byte[] getIpAddress(int[] mibVarOID) { String tempString = getStringNative(mibVarOID); SnmpString snmpString = new SnmpString(tempString); return snmpString.toByte(); } /** * Get the SubnetMask Property of NetworkParms and turn it * into a Byte-array. like this :<BR> * [127.0.0.1] -> 91,49,50,55,46,48,46,48,46,49,93<BR> * @param mibVarOID OID as int-Array * @return Byte-Array */ public static Byte[] getSubnetMask(int[] mibVarOID) { String tempString = getStringNative(mibVarOID); SnmpString snmpString = new SnmpString(tempString); return snmpString.toByte(); } /** * Get the Adress Format "[0.0.0.0]" and convert it * into a Byte-array. like this :<BR> * [127.0.0.1] -> 91,49,50,55,46,48,46,48,46,49,93<BR> * @param mibVarOID OID as int-Array * @return Byte-Array */ public static Byte[] getByteArray(int[] mibVarOID) { String tempString = getStringNative(mibVarOID); SnmpString snmpString = new SnmpString(tempString); return snmpString.toByte(); } // getNext public static native int getNextIntNative(int[][] mibVarOID, int oidIndex); public static native String getNextStringNative(int[][] mibVarOID, int oidIndex); public static native String[] getIndexedStringNative(int[][] oids, int IndexRange); public static native int[] getIndexedIntNative(int[][] oids, int IndexRange); // set public static native void setNative(int[] mibVarOID, int value); public static native void setNative(int[] mibVarOID, String value); // set Methods to convert Data in accessible format /** * Set the IpAddress.<BR> * The new IP-Address shows : [127.0.0.1] * @param mibVarOID OID for MibVariable IpAddress * @param ipAddress new IpAddress as Byte-Array * @return none */ public static void setIpAddress(int[] mibVarOID, Byte[] ByteArray) { try { SnmpString snmpString = new SnmpString(ByteArray); setNative(mibVarOID, snmpString.toString()); } catch (Exception e) { e.printStackTrace(); System.exit(0); } } /** * Set the SubnetMask.<BR> * The new IP-Address shows : [127.0.0.1] * @param mibVarOID OID for MibVariable SubnetMask * @param SubnetMask new SubnetMask as Byte-Array * @return none */ public static void setSubnetMask(int[] mibVarOID, Byte[] ByteArray) { try { SnmpString snmpString = new SnmpString(ByteArray); setNative(mibVarOID, snmpString.toString()); } catch (Exception e) { e.printStackTrace(); System.exit(0); } } public static void setByteArray(int[] mibVarOID, Byte[] ByteArray) { SnmpString snmpString = new SnmpString(ByteArray); setNative(mibVarOID, snmpString.toString()); } // andere Native Methoden public static native void buildCAsnNodeStructure(); public static native void removeNative(int[] mibVarOID); public static void encodeStringToAscii(String str, int[][] intArray, int oidIndex) { int strIndex = 0; char charArray[] = str.toCharArray(); intArray[oidIndex] = new int[str.length()]; for (int i = 0; i < charArray.length; i++) { intArray[oidIndex][i] = (int) charArray[i]; } } static { System.out.print("JNI : Loading nativeBase.dll ... "); System.loadLibrary("c:/jdmk/jni/Debug/nativeBase"); System.out.println("loaded."); System.out.println("JNI : buildCAsnNode ... "); buildCAsnNodeStructure(); System.out.println("executed."); } }