FileDocCategorySizeDatePackage
KVMPrintNativeMethodName.javaAPI DocExample1859Mon Nov 26 10:45:18 GMT 2001ora.ch2

KVMPrintNativeMethodName

public class KVMPrintNativeMethodName extends Object

Fields Summary
Constructors Summary
Methods Summary
public static java.lang.StringconvertToJNIName(java.lang.String classname, java.lang.String methodname, java.lang.String typename)

 
	StringBuffer result = new StringBuffer("Java_");
	stringToJNI(result, classname);
	result.append('_");
	stringToJNI(result, methodname);
	if (typename != null) {
	    result.append("__");
	    // Only include the stuff inside the parentheses.
	    stringToJNI(result, typename.substring(1, typename.indexOf(')")));
	} 
	return result.toString();
    
public static voidmain(java.lang.String[] args)

        String className = args[0];
        String methodName = args[1];
        String signature = (args.length > 2 ? args[2] : null);
        
        System.out.println(convertToJNIName(className, methodName, signature));
    
private static voidstringToJNI(java.lang.StringBuffer result, java.lang.String name)

 
	int length = name.length();
	for (int i = 0; i < length; i++) { 
	    char ch = name.charAt(i);
	    if (ch <= 0x7f && Character.isLetterOrDigit(ch)) {
		result.append(ch);
	    } else { 
		result.append('_");
		switch(ch) { 
		   case '/":  break; // the _ is all we need
		   case '_":  result.append('1"); break;
		   case ';":  result.append('2"); break;
		   case '[":  result.append('3"); break;
		   default: { 
		       // Adding 0x100000 to a 16-bit number forces 
		       // toHexString to produce a string of the form "10xxxx".
		       // Discard the initial "1" to get the right result.
		       String t = Integer.toHexString(ch + 0x100000);
		       result.append(t.substring(1));
		   }
		}
	    }
	}