if (!Proxy.isProxyClass(proxy.getClass()))
System.out.println("not a proxy class?"); if (Proxy.getInvocationHandler(proxy) == null)
System.out.println("ERROR: Proxy.getInvocationHandler is null");
// Test the proxy spec: These Object functions are supposed to be given to the handler. int unusedHashCode = ((Object)trace).hashCode(); boolean unusedEquals = ((Object)trace).equals(trace);
String unusedString = ((Object)trace).toString();
static Object createProxy(Object proxyMe) { /* declare an object that will handle the method calls */
InvocationHandler handler = new MyInvocationHandler(proxyMe);
/* create the proxy class */ Class<?> proxyClass = Proxy.getProxyClass(Shapes.class.getClassLoader(),
Quads.class, Colors.class, Trace.class);
Main.registerProxyClassName(proxyClass.getCanonicalName());
// Trap Object calls. This is important here to avoid a recursive // invocation of toString() in the print statements below. if (method.getDeclaringClass() == java.lang.Object.class) { //System.out.println("!!! object " + method.getName()); if (method.getName().equals("toString")) { returnsuper.toString();
} elseif (method.getName().equals("hashCode")) { return Integer.valueOf(super.hashCode());
} elseif (method.getName().equals("equals")) { returnBoolean.valueOf(super.equals(args[0]));
} else { thrownew RuntimeException("huh?");
}
}
if (method.getDeclaringClass() == Trace.class) { if (method.getName().equals("getTrace")) {
StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace(); for (int i = 0; i < stackTrace.length; i++) {
StackTraceElement ste = stackTrace[i]; if (ste.getMethodName().equals("getTrace")) {
String outputClassName = Main.replaceProxyClassNamesForOutput(ste.getClassName());
System.out.println(outputClassName + "." + ste.getMethodName() + " " +
ste.getFileName() + ":" + ste.getLineNumber());
}
} returnnull;
}
}
if (method.getDeclaringClass() == Trace.class) { if (method.getName().equals("getTrace")) {
StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace(); for (int i = 0; i < stackTrace.length; i++) {
StackTraceElement ste = stackTrace[i]; if (ste.getMethodName().equals("getTrace")) {
String outputClassName = Main.replaceProxyClassNamesForOutput(ste.getClassName());
System.out.println(outputClassName + "." + ste.getMethodName() + " " +
ste.getFileName() + ":" + ste.getLineNumber());
}
} returnnull;
}
}
if (args == null || args.length == 0) {
System.out.println(" (no args)");
} else { for (int i = 0; i < args.length; i++)
System.out.println(" " + i + ": " + args[i]);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.