diff options
author | Harvey Harrison <[email protected]> | 2012-05-03 14:59:44 -0700 |
---|---|---|
committer | Harvey Harrison <[email protected]> | 2012-05-03 15:04:36 -0700 |
commit | dfc10a8ff29e43d49b7fe880bb58052d5c7262e2 (patch) | |
tree | 3ebbfb43652d875523bc8ca8ee4aa56a7a21e509 /src/classes/share | |
parent | 05f860d98f6d11778aeca0685e68993c64290f5f (diff) |
j3dcore: simplify Pipeline singleton creation
Signed-off-by: Harvey Harrison <[email protected]>
Diffstat (limited to 'src/classes/share')
-rw-r--r-- | src/classes/share/javax/media/j3d/Pipeline.java | 56 |
1 files changed, 25 insertions, 31 deletions
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<Pipeline> { +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); } /** |