diff options
author | Sven Gothel <[email protected]> | 2011-09-30 21:31:11 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2011-09-30 21:31:11 +0200 |
commit | 541e96ace7ed3f4b863a7374a5ea72895d9362be (patch) | |
tree | b1b5df5e2b29aa0b431e8fb0e467aa7b8a762b21 /src/jogl/classes/javax/media/opengl | |
parent | 448ad05ea1192a1c3ca8812bf8d3142b2df6c30b (diff) |
GLPipelineFactory: Generics && Using enhanced GlueGen's ReflectionUtil.getConstructor(..)
Diffstat (limited to 'src/jogl/classes/javax/media/opengl')
-rw-r--r-- | src/jogl/classes/javax/media/opengl/GLPipelineFactory.java | 29 |
1 files changed, 13 insertions, 16 deletions
diff --git a/src/jogl/classes/javax/media/opengl/GLPipelineFactory.java b/src/jogl/classes/javax/media/opengl/GLPipelineFactory.java index 926651c1d..7a12e52c9 100644 --- a/src/jogl/classes/javax/media/opengl/GLPipelineFactory.java +++ b/src/jogl/classes/javax/media/opengl/GLPipelineFactory.java @@ -39,6 +39,8 @@ package javax.media.opengl; import java.lang.reflect.*; import java.util.StringTokenizer; +import com.jogamp.common.util.ReflectionUtil; + import jogamp.opengl.*; /** @@ -70,10 +72,10 @@ public class GLPipelineFactory { * @param downstream is always the 1st argument for the upstream constructor * @param additionalArgs additional arguments for the upstream constructor */ - public static final GL create(String pipelineClazzBaseName, Class reqInterface, GL downstream, Object[] additionalArgs) { - Class downstreamClazz = downstream.getClass(); - Class upstreamClazz = null; - Class interfaceClazz = null; + public static final GL create(String pipelineClazzBaseName, Class<?> reqInterface, GL downstream, Object[] additionalArgs) { + Class<?> downstreamClazz = downstream.getClass(); + Class<?> upstreamClazz = null; + Class<?> interfaceClazz = null; if(DEBUG) { System.out.println("GLPipelineFactory: Start "+downstreamClazz.getName()+", req. Interface: "+reqInterface+" -> "+pipelineClazzBaseName); @@ -83,7 +85,7 @@ public class GLPipelineFactory { do { // For all interfaces: right -> left == child -> parent // It is important that this matches with the gluegen cfg file's 'Implements' clause ! - Class[] clazzes = downstreamClazz.getInterfaces(); + Class<?>[] clazzes = downstreamClazz.getInterfaces(); for(int i=clazzes.length-1; null==upstreamClazz && i>=0; i--) { if(DEBUG) { System.out.println("GLPipelineFactory: Try "+downstreamClazz.getName()+" Interface["+i+"]: "+clazzes[i].getName()); @@ -124,7 +126,7 @@ public class GLPipelineFactory { System.out.println("GLPipelineFactory: Got : "+ upstreamClazz.getName()+", base interface: "+interfaceClazz.getName()); } - Class[] cstrArgTypes = new Class[ 1 + ( ( null==additionalArgs ) ? 0 : additionalArgs.length ) ] ; + Class<?>[] cstrArgTypes = new Class<?>[ 1 + ( ( null==additionalArgs ) ? 0 : additionalArgs.length ) ] ; { int i = 0; cstrArgTypes[i++] = interfaceClazz; @@ -132,13 +134,8 @@ public class GLPipelineFactory { cstrArgTypes[i++] = additionalArgs[j].getClass(); } } - Constructor cstr = null; - try { - cstr = upstreamClazz.getDeclaredConstructor( cstrArgTypes ); - } catch(NoSuchMethodException nsme) { - throw new GLException("Couldn't find pipeline constructor: " + upstreamClazz.getName() + - " ( "+getArgsClassNameList(downstreamClazz, additionalArgs) +" )"); - } + // throws exception if cstr not found! + Constructor<?> cstr = ReflectionUtil.getConstructor(upstreamClazz, cstrArgTypes); Object instance = null; try { Object[] cstrArgs = new Object[ 1 + ( ( null==additionalArgs ) ? 0 : additionalArgs.length ) ] ; @@ -161,7 +158,7 @@ public class GLPipelineFactory { return (GL) instance; } - private static final String getArgsClassNameList(Class arg0, Object[] args) { + private static final String getArgsClassNameList(Class<?> arg0, Object[] args) { StringBuffer sb = new StringBuffer(); sb.append(arg0.getName()); if(args!=null) { @@ -173,7 +170,7 @@ public class GLPipelineFactory { return sb.toString(); } - private static final Class getUpstreamClazz(Class downstreamClazz, String pipelineClazzBaseName) { + private static final Class<?> getUpstreamClazz(Class<?> downstreamClazz, String pipelineClazzBaseName) { String downstreamClazzName = downstreamClazz.getName(); StringTokenizer st = new StringTokenizer(downstreamClazzName, "."); @@ -183,7 +180,7 @@ public class GLPipelineFactory { } String upstreamClazzName = pipelineClazzBaseName+downstreamClazzBaseName; - Class upstreamClazz = null; + Class<?> upstreamClazz = null; try { upstreamClazz = Class.forName(upstreamClazzName, true, GLPipelineFactory.class.getClassLoader()); } catch (Throwable e) { e.printStackTrace(); } |