From 7cd1d4c59e8ffc7a4e0d83ad485ab46499e74d35 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Sat, 12 Sep 2009 15:16:59 -0700 Subject: NEWT: Native window parenting (X11: OK); AWTWindow external Frame OK --- .../com/sun/nativewindow/impl/NWReflection.java | 36 ++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/src/nativewindow/classes/com/sun/nativewindow/impl/NWReflection.java b/src/nativewindow/classes/com/sun/nativewindow/impl/NWReflection.java index b13cf43..d86fbdc 100644 --- a/src/nativewindow/classes/com/sun/nativewindow/impl/NWReflection.java +++ b/src/nativewindow/classes/com/sun/nativewindow/impl/NWReflection.java @@ -66,10 +66,23 @@ public final class NWReflection { if (factoryClass == null) { throw new NativeWindowException(clazzName + " not available"); } + return getConstructor(factoryClass, cstrArgTypes); + } catch (Throwable e) { + if (DEBUG) { + e.printStackTrace(); + } + throw new NativeWindowException(e); + } + } + + public static final Constructor getConstructor(Class clazz, Class[] cstrArgTypes) { + Constructor factory = null; + + try { try { - factory = factoryClass.getDeclaredConstructor( cstrArgTypes ); + factory = clazz.getDeclaredConstructor( cstrArgTypes ); } catch(NoSuchMethodException nsme) { - throw new NativeWindowException("Constructor: '" + clazzName + "("+cstrArgTypes+")' not found"); + throw new NativeWindowException("Constructor: '" + clazz + "("+cstrArgTypes+")' not found"); } return factory; } catch (Throwable e) { @@ -84,6 +97,25 @@ public final class NWReflection { return getConstructor(clazzName, new Class[0]); } + public static final Object createInstance(Class clazz, Class[] cstrArgTypes, Object[] cstrArgs) { + Constructor factory = null; + + try { + factory = getConstructor(clazz, cstrArgTypes); + return factory.newInstance( cstrArgs ) ; + } catch (Exception e) { + throw new NativeWindowException(e); + } + } + + public static final Object createInstance(Class clazz, Object[] cstrArgs) { + Class[] cstrArgTypes = new Class[cstrArgs.length]; + for(int i=0; i