diff options
author | Sven Gothel <[email protected]> | 2010-04-19 01:40:20 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2010-04-19 01:40:20 +0200 |
commit | a01cb3d59715a41153380f1977ec75263b762dc6 (patch) | |
tree | 0fc31f9e9b60d23c088ae8049b5c8d456398bc9f /src | |
parent | c7630f35befa1b8dbd365984f08c4efbc04488c1 (diff) |
Importing files from JOGL (preserving history)
git mv src/nativewindow/native/JVM_Tool.c src/native/common/JVM_Tool.c
git mv src/nativewindow/classes/com/jogamp/nativewindow/impl/NativeLibLoaderBase.java src/java/com/jogamp/common/jvm/JNILibLoaderBase.java
git mv src/nativewindow/classes/com/jogamp/nativewindow/impl/jvm/JVMUtil.java src/java/com/jogamp/common/jvm/JVMUtil.java
git mv src/nativewindow/classes/com/jogamp/nativewindow/impl/NWReflection.java src/java/com/jogamp/common/util/ReflectionUtil.java
Adding own JogampRuntimeException and Debug class
Diffstat (limited to 'src')
-rw-r--r-- | src/java/com/jogamp/common/JogampRuntimeException.java | 56 | ||||
-rw-r--r-- | src/java/com/jogamp/common/impl/Debug.java | 134 | ||||
-rw-r--r-- | src/java/com/jogamp/common/jvm/JNILibLoaderBase.java | 23 | ||||
-rw-r--r-- | src/java/com/jogamp/common/jvm/JVMUtil.java | 11 | ||||
-rw-r--r-- | src/java/com/jogamp/common/util/ReflectionUtil.java | 31 | ||||
-rw-r--r-- | src/native/common/JVM_Tool.c | 2 |
6 files changed, 222 insertions, 35 deletions
diff --git a/src/java/com/jogamp/common/JogampRuntimeException.java b/src/java/com/jogamp/common/JogampRuntimeException.java new file mode 100644 index 0000000..d188561 --- /dev/null +++ b/src/java/com/jogamp/common/JogampRuntimeException.java @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2010, Sven Gothel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of JogAmp nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL Sven Gothel BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package com.jogamp.common; + +/** A generic exception for Jogamp errors used throughout the binding + as a substitute for {@link RuntimeException}. */ + +public class JogampRuntimeException extends RuntimeException { + /** Constructs a JogampRuntimeException object. */ + public JogampRuntimeException() { + super(); + } + + /** Constructs a JogampRuntimeException object with the specified detail + message. */ + public JogampRuntimeException(String message) { + super(message); + } + + /** Constructs a JogampRuntimeException object with the specified detail + message and root cause. */ + public JogampRuntimeException(String message, Throwable cause) { + super(message, cause); + } + + /** Constructs a JogampRuntimeException object with the specified root + cause. */ + public JogampRuntimeException(Throwable cause) { + super(cause); + } +} diff --git a/src/java/com/jogamp/common/impl/Debug.java b/src/java/com/jogamp/common/impl/Debug.java new file mode 100644 index 0000000..06a5fea --- /dev/null +++ b/src/java/com/jogamp/common/impl/Debug.java @@ -0,0 +1,134 @@ +/* + * Copyright (c) 2003-2005 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package com.jogamp.common.impl; + +import java.security.*; + +/** Helper routines for logging and debugging. */ + +public class Debug { + // Some common properties + private static boolean verbose; + private static boolean debugAll; + private static AccessControlContext localACC; + + static { + localACC=AccessController.getContext(); + verbose = isPropertyDefined("jogamp.verbose", true); + debugAll = isPropertyDefined("jogamp.debug", true); + } + + static int getIntProperty(final String property, final boolean jnlpAlias) { + return getIntProperty(property, jnlpAlias, localACC); + } + + public static int getIntProperty(final String property, final boolean jnlpAlias, final AccessControlContext acc) { + int i=0; + try { + Integer iv = Integer.valueOf(Debug.getProperty(property, jnlpAlias, acc)); + i = iv.intValue(); + } catch (NumberFormatException nfe) {} + return i; + } + + static boolean getBooleanProperty(final String property, final boolean jnlpAlias) { + return getBooleanProperty(property, jnlpAlias, localACC); + } + + public static boolean getBooleanProperty(final String property, final boolean jnlpAlias, final AccessControlContext acc) { + Boolean b = Boolean.valueOf(Debug.getProperty(property, jnlpAlias, acc)); + return b.booleanValue(); + } + + static boolean isPropertyDefined(final String property, final boolean jnlpAlias) { + return isPropertyDefined(property, jnlpAlias, localACC); + } + + public static boolean isPropertyDefined(final String property, final boolean jnlpAlias, final AccessControlContext acc) { + return (Debug.getProperty(property, jnlpAlias, acc) != null) ? true : false; + } + + static String getProperty(final String property, final boolean jnlpAlias) { + return getProperty(property, jnlpAlias, localACC); + } + + public static String getProperty(final String property, final boolean jnlpAlias, final AccessControlContext acc) { + String s=null; + if(null!=acc && acc.equals(localACC)) { + s = (String) AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + String val=null; + try { + val = System.getProperty(property); + } catch (Exception e) {} + if(null==val && jnlpAlias && !property.startsWith(jnlp_prefix)) { + try { + val = System.getProperty(jnlp_prefix + property); + } catch (Exception e) {} + } + return val; + } + }); + } else { + try { + s = System.getProperty(property); + } catch (Exception e) {} + if(null==s && jnlpAlias && !property.startsWith(jnlp_prefix)) { + try { + s = System.getProperty(jnlp_prefix + property); + } catch (Exception e) {} + } + } + return s; + } + public static final String jnlp_prefix = "jnlp." ; + + public static boolean verbose() { + return verbose; + } + + public static boolean debugAll() { + return debugAll; + } + + public static boolean debug(String subcomponent) { + return debugAll() || isPropertyDefined("jogamp.debug." + subcomponent, true); + } +} diff --git a/src/java/com/jogamp/common/jvm/JNILibLoaderBase.java b/src/java/com/jogamp/common/jvm/JNILibLoaderBase.java index c4f1d7e..b89cc8a 100644 --- a/src/java/com/jogamp/common/jvm/JNILibLoaderBase.java +++ b/src/java/com/jogamp/common/jvm/JNILibLoaderBase.java @@ -37,18 +37,21 @@ * and developed by Kenneth Bradley Russell and Christopher John Kline. */ -package com.jogamp.nativewindow.impl; +package com.jogamp.common.jvm; // FIXME: refactor Java SE dependencies //import java.awt.Toolkit; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.security.AccessController; +import java.security.AccessControlContext; import java.security.PrivilegedAction; import java.util.HashSet; +import com.jogamp.common.impl.Debug; -public class NativeLibLoaderBase { - public static final boolean DEBUG = Debug.debug("NativeLibLoader"); +public class JNILibLoaderBase { + public static final boolean DEBUG = Debug.debug("JNILibLoader"); + private static final AccessControlContext localACC = AccessController.getContext(); public interface LoaderAction { /** @@ -127,16 +130,6 @@ public class NativeLibLoaderBase { } } - public static void loadNativeWindow(final String ossuffix) { - AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { - loadLibrary("nativewindow_"+ossuffix, null, false); - return null; - } - }); - } - - private static final Class customLauncherClass; private static final Method customLoadLibraryMethod; @@ -145,7 +138,7 @@ public class NativeLibLoaderBase { Class launcherClass = null; Method loadLibraryMethod = null; - if ( Debug.getBooleanProperty("sun.jnlp.applet.launcher", false) ) { + if ( Debug.getBooleanProperty("sun.jnlp.applet.launcher", false, localACC) ) { try { launcherClass = Class.forName("org.jdesktop.applet.util.JNLPAppletLauncher"); loadLibraryMethod = launcherClass.getDeclaredMethod("loadLibrary", new Class[] { String.class }); @@ -162,7 +155,7 @@ public class NativeLibLoaderBase { } if(null==launcherClass) { - String launcherClassName = Debug.getProperty("jnlp.launcher.class", false); + String launcherClassName = Debug.getProperty("jnlp.launcher.class", false, localACC); if(null!=launcherClassName) { try { launcherClass = Class.forName(launcherClassName); diff --git a/src/java/com/jogamp/common/jvm/JVMUtil.java b/src/java/com/jogamp/common/jvm/JVMUtil.java index df703aa..833e907 100644 --- a/src/java/com/jogamp/common/jvm/JVMUtil.java +++ b/src/java/com/jogamp/common/jvm/JVMUtil.java @@ -30,10 +30,12 @@ * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. */ -package com.jogamp.nativewindow.impl.jvm; +package com.jogamp.common.jvm; import java.nio.ByteBuffer; -import com.jogamp.nativewindow.impl.*; +import com.jogamp.common.nio.Buffers; +import com.jogamp.common.impl.Debug; +import com.jogamp.gluegen.runtime.NativeLibLoader; /** * Currently this tool works around the Hotspot race condition bugs: @@ -50,9 +52,10 @@ public class JVMUtil { private static final boolean DEBUG = Debug.debug("JVMUtil"); static { - NativeLibLoaderBase.loadNativeWindow("jvm"); + // JNILibLoaderBase.loadLibrary("jvm", null, false); + NativeLibLoader.loadGlueGenRT(); - ByteBuffer buffer = InternalBufferUtil.newByteBuffer(64); + ByteBuffer buffer = Buffers.newDirectByteBuffer(64); if( ! initialize(buffer) ) { throw new RuntimeException("Failed to initialize the JVMUtil "+Thread.currentThread().getName()); } diff --git a/src/java/com/jogamp/common/util/ReflectionUtil.java b/src/java/com/jogamp/common/util/ReflectionUtil.java index 9bac947..f3708aa 100644 --- a/src/java/com/jogamp/common/util/ReflectionUtil.java +++ b/src/java/com/jogamp/common/util/ReflectionUtil.java @@ -34,21 +34,22 @@ * facility. */ -package com.jogamp.nativewindow.impl; +package com.jogamp.common.util; import java.lang.reflect.*; -import javax.media.nativewindow.*; +import com.jogamp.common.JogampRuntimeException; +import com.jogamp.common.impl.Debug; -public final class NWReflection { +public final class ReflectionUtil { - public static final boolean DEBUG = Debug.debug("NWReflection"); + public static final boolean DEBUG = Debug.debug("ReflectionUtil"); /** * Returns true only if the class could be loaded. */ public static final boolean isClassAvailable(String clazzName) { try { - return null != Class.forName(clazzName, false, NWReflection.class.getClassLoader()); + return null != Class.forName(clazzName, false, ReflectionUtil.class.getClassLoader()); } catch (ClassNotFoundException e) { return false; } @@ -67,22 +68,22 @@ public final class NWReflection { } private static Class getClassImpl(String clazzName, boolean initialize) throws ClassNotFoundException { - return Class.forName(clazzName, initialize, NWReflection.class.getClassLoader()); + return Class.forName(clazzName, initialize, ReflectionUtil.class.getClassLoader()); } /** - * @throws NativeWindowException if the constructor can not be delivered. + * @throws JogampRuntimeException if the constructor can not be delivered. */ public static final Constructor getConstructor(String clazzName, Class[] cstrArgTypes) { try { return getConstructor(getClassImpl(clazzName, true), cstrArgTypes); } catch (ClassNotFoundException ex) { - throw new NativeWindowException(clazzName + " not available", ex); + throw new JogampRuntimeException(clazzName + " not available", ex); } } /** - * @throws NativeWindowException if the constructor can not be delivered. + * @throws JogampRuntimeException if the constructor can not be delivered. */ public static final Constructor getConstructor(Class clazz, Class[] cstrArgTypes) { try { @@ -95,7 +96,7 @@ public final class NWReflection { args+= ", "; } } - throw new NativeWindowException("Constructor: '" + clazz + "(" + args + ")' not found", ex); + throw new JogampRuntimeException("Constructor: '" + clazz + "(" + args + ")' not found", ex); } } @@ -104,17 +105,17 @@ public final class NWReflection { } /** - * @throws NativeWindowException if the instance can not be created. + * @throws JogampRuntimeException if the instance can not be created. */ public static final Object createInstance(Class clazz, Class[] cstrArgTypes, Object[] cstrArgs) { try { return getConstructor(clazz, cstrArgTypes).newInstance(cstrArgs); } catch (InstantiationException ex) { - throw new NativeWindowException("can not create instance of class "+clazz, ex); + throw new JogampRuntimeException("can not create instance of class "+clazz, ex); } catch (InvocationTargetException ex) { - throw new NativeWindowException("can not create instance of class "+clazz, ex); + throw new JogampRuntimeException("can not create instance of class "+clazz, ex); } catch (IllegalAccessException ex) { - throw new NativeWindowException("can not create instance of class "+clazz, ex); + throw new JogampRuntimeException("can not create instance of class "+clazz, ex); } } @@ -130,7 +131,7 @@ public final class NWReflection { try { return createInstance(getClassImpl(clazzName, true), cstrArgTypes, cstrArgs); } catch (ClassNotFoundException ex) { - throw new NativeWindowException(clazzName + " not available", ex); + throw new JogampRuntimeException(clazzName + " not available", ex); } } diff --git a/src/native/common/JVM_Tool.c b/src/native/common/JVM_Tool.c index ce82712..cb08b47 100644 --- a/src/native/common/JVM_Tool.c +++ b/src/native/common/JVM_Tool.c @@ -40,7 +40,7 @@ #include <jni.h> JNIEXPORT jboolean JNICALL -Java_com_jogamp_nativewindow_impl_jvm_JVMUtil_initialize(JNIEnv *env, jclass _unused, jobject nioBuffer) { +Java_com_jogamp_common_jvm_JVMUtil_initialize(JNIEnv *env, jclass _unused, jobject nioBuffer) { int res; void * ptr = NULL; if (nioBuffer != NULL) { |