From dfc10a8ff29e43d49b7fe880bb58052d5c7262e2 Mon Sep 17 00:00:00 2001 From: Harvey Harrison Date: Thu, 3 May 2012 14:59:44 -0700 Subject: j3dcore: simplify Pipeline singleton creation Signed-off-by: Harvey Harrison --- src/classes/share/javax/media/j3d/Pipeline.java | 56 +++++++++++-------------- 1 file changed, 25 insertions(+), 31 deletions(-) (limited to 'src/classes/share') diff --git a/src/classes/share/javax/media/j3d/Pipeline.java b/src/classes/share/javax/media/j3d/Pipeline.java index 1cf87c2..264d616 100644 --- a/src/classes/share/javax/media/j3d/Pipeline.java +++ b/src/classes/share/javax/media/j3d/Pipeline.java @@ -48,9 +48,6 @@ abstract class Pipeline { NOOP, } - private static final String CLASSNAME_JOGL = "javax.media.j3d.JoglPipeline"; - private static final String CLASSNAME_NOOP = "javax.media.j3d.NoopPipeline"; - // Singleton pipeline instance private static Pipeline pipeline; @@ -64,40 +61,37 @@ abstract class Pipeline { protected Pipeline() { } +private static class PipelineCreator +implements java.security.PrivilegedAction { +private final Type pipeType; + +PipelineCreator(Type type) { + pipeType = type; +} + +public Pipeline run() { + try { + switch (pipeType) { + case JOGL: + return (Pipeline)Class.forName("javax.media.j3d.JoglPipeline").newInstance(); + case NOOP: + return (Pipeline)Class.forName("javax.media.j3d.NoopPipeline").newInstance(); + } + } catch (Exception e) { + throw new RuntimeException(e); + } + return null; +} +} + /** * Initialize the Pipeline. Called exactly once by * MasterControl.loadLibraries() to create the singleton * Pipeline object. */ static void createPipeline(Type pipelineType) { - String className = null; - switch (pipelineType) { - case JOGL: - className = CLASSNAME_JOGL; - break; - case NOOP: - className = CLASSNAME_NOOP; - break; - default: - // Should not get here - throw new AssertionError("missing case statement"); - } - - final String pipelineClassName = className; - pipeline = (Pipeline) - java.security.AccessController.doPrivileged(new - java.security.PrivilegedAction() { - public Object run() { - try { - Class pipelineClass = Class.forName(pipelineClassName); - return pipelineClass.newInstance(); - } catch (Exception e) { - throw new RuntimeException(e); - } - } - }); - - pipeline.initialize(pipelineType); + pipeline = java.security.AccessController.doPrivileged(new PipelineCreator(pipelineType)); + pipeline.initialize(pipelineType); } /** -- cgit v1.2.3