changeset 6409:e164a77392b6

While lambdifying 3DViewer, it was discovered that it no longer finds loaders when launched from the IDE. This fix looks for a well known set of loaders after first trying to load them from an external jar.
author snorthov
date Mon, 03 Mar 2014 17:33:51 -0500
parents 4742b5a6eb9b
children a5bf93565444
files apps/experiments/3DViewer/src/main/java/com/javafx/experiments/importers/Importer3D.java
diffstat 1 files changed, 29 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/apps/experiments/3DViewer/src/main/java/com/javafx/experiments/importers/Importer3D.java	Mon Mar 03 15:38:59 2014 -0500
+++ b/apps/experiments/3DViewer/src/main/java/com/javafx/experiments/importers/Importer3D.java	Mon Mar 03 17:33:51 2014 -0500
@@ -34,12 +34,14 @@
 import java.io.IOException;
 import java.net.URL;
 import java.net.URLClassLoader;
+
 import javafx.animation.Timeline;
 import javafx.fxml.FXMLLoader;
 import javafx.scene.Node;
 import javafx.scene.shape.MeshView;
 import javafx.scene.shape.TriangleMesh;
 import javafx.util.Pair;
+
 import java.util.ServiceLoader;
 
 /**
@@ -107,9 +109,35 @@
                 break;
             }
         }
+
+        // Check well known loaders that might not be in a jar (ie. running from an IDE)
         if ((importer == null) && (!extension.equals("fxml"))){
-            throw new IOException("Unknown 3D file format [" + extension + "]");
+            String [] names = {
+                 "com.javafx.experiments.importers.dae.DaeImporter",
+                 "com.javafx.experiments.importers.max.MaxLoader",
+                 "com.javafx.experiments.importers.maya.MayaImporter",
+                 "com.javafx.experiments.importers.obj.ObjOrPolyObjImporter",
+            };
+            boolean fail = true;
+            for (String name : names) {
+                try {
+                    Class<?> clazz = Class.forName(name);
+                    Object obj = clazz.newInstance();
+                    if (obj instanceof Importer) {
+                        Importer plugin = (Importer) obj;
+                        if (plugin.isSupported(extension)) {
+                            importer = plugin;
+                            fail = false;
+                            break;
+                        }
+                    }
+                } catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) {
+                    // FAIL SILENTLY
+                }
+            }
+            if (fail) throw new IOException("Unknown 3D file format [" + extension + "]");
         }
+        
         if (extension.equals("fxml")) {
             final Object fxmlRoot = FXMLLoader.load(new URL(fileUrl));
             if (fxmlRoot instanceof Node) {