modules/graphics/src/main/java/com/sun/glass/ui/monocle/NativePlatformFactory.java

Print this page

        

@@ -23,57 +23,82 @@
  * questions.
  */
 
 package com.sun.glass.ui.monocle;
 
+import com.sun.glass.ui.monocle.linux.LinuxSystem;
+
 import java.security.AccessController;
 import java.security.PrivilegedAction;
 import java.util.Locale;
 
 public abstract class NativePlatformFactory {
+    private static String platformName="";
+    private static String factoryClassName="";
+    private static long nativeDisplayType = -1L;
 
     protected abstract boolean matches();
 
     protected abstract NativePlatform createNativePlatform();
 
     private static NativePlatform platform;
-    public static synchronized NativePlatform getNativePlatform() {
-        if (platform == null) {
-            String platformFactoryProperty =
-                    AccessController.doPrivileged(new PrivilegedAction<String>() {
+    private static boolean initialized = false;
+
+    private static void determineNativePlatform(){
+        String platformFactoryProperty = AccessController.doPrivileged(new PrivilegedAction<String>() {
                 @Override
                 public String run() {
-                    return System.getProperty("monocle.platform",
-                                              "MX6,OMAP,Linux,Headless");
+                    return System.getProperty("monocle.platform", "MX6,OMAP,Linux,Headless");
                 }
-            });
+        } );
+
             String[] platformFactories = platformFactoryProperty.split(",");
             for (int i = 0; i < platformFactories.length; i++) {
                 String factoryName = platformFactories[i].trim();
-                String factoryClassName;
                 if (factoryName.contains(".")) {
                     factoryClassName = factoryName;
+                platformName = factoryClassName.substring(factoryClassName.lastIndexOf(".", 0));
                 } else {
-                    factoryClassName = "com.sun.glass.ui.monocle."
-                        + factoryName.toLowerCase(Locale.ROOT)
-                        + "." + factoryName + "PlatformFactory";
+                platformName = factoryName.toLowerCase(Locale.ROOT);
+                factoryClassName = "com.sun.glass.ui.monocle." + platformName + "." + factoryName + "PlatformFactory";
+            }
+            try {
+                NativePlatformFactory npf = (NativePlatformFactory) Class.forName(factoryClassName).newInstance();
+                if (npf.matches()) {
+                    initialized = true;
+                    return;
+                }
+            } catch (Exception e) {
+                e.printStackTrace();
                 }
+        }
+        initialized = true;
+    }
+
+    public static synchronized String getNativePlatformName() {
+        if (!initialized) {
+            determineNativePlatform();
+        }
+        return platformName;
+    }
+
+    public static synchronized NativePlatform getNativePlatform() {
+        if (!initialized) {
+            determineNativePlatform();
+        }
+        if (platform == null) {
                 try {
-                    NativePlatformFactory npf = (NativePlatformFactory)
-                            Class.forName(factoryClassName)
-                            .newInstance();
+                NativePlatformFactory npf = (NativePlatformFactory) Class.forName(factoryClassName).newInstance();
                     if (npf.matches()) {
                         platform = npf.createNativePlatform();
                         return platform;
                     }
                 } catch (Exception e) {
                     e.printStackTrace();
                 }
-            }
-            throw new UnsupportedOperationException(
-                    "Cannot load a native platform from: '"
-                    + platformFactoryProperty + "'");
+
+            throw new UnsupportedOperationException("Cannot load a native platform: '" + platformName + "'");
         }
         return platform;
     }
 
 }