-package org.simantics.browsing.ui.model.tests;\r
-\r
-import org.eclipse.core.runtime.Platform;\r
-import org.osgi.framework.Bundle;\r
-import org.simantics.databoard.Bindings;\r
-import org.simantics.db.ReadGraph;\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.viewpoint.ontology.ViewpointResource;\r
-\r
-/**\r
- * A visual contribution rule test that checks whether the input content is an\r
- * instance of a Java class. The class is specified by identifying the source\r
- * bundle and the class name.\r
- * \r
- * @author Tuukka Lehtonen\r
- */\r
-public class InstanceOfTest implements Test {\r
-\r
- String bundleName;\r
- String className;\r
- Class<?> clazz;\r
- boolean failed;\r
-\r
- public InstanceOfTest(String bundle, String className) {\r
- this.bundleName = bundle;\r
- this.className = className;\r
- }\r
-\r
- public InstanceOfTest(ReadGraph graph, Resource test) throws DatabaseException {\r
- ViewpointResource VP = ViewpointResource.getInstance(graph);\r
- this.bundleName = graph.getRelatedValue(test, VP.InstanceOfTest_bundleName, Bindings.STRING);\r
- this.className = graph.getRelatedValue(test, VP.InstanceOfTest_className, Bindings.STRING);\r
- }\r
-\r
- private Class<?> resolveClass() {\r
- if (failed)\r
- return null;\r
- if (clazz != null)\r
- return clazz;\r
- Bundle b = Platform.getBundle(bundleName);\r
- if (b == null) {\r
- System.err.println(getClass() + " could not resolve class " + className + ", bundle " + bundleName + " not found in platform");\r
- failed = true;\r
- return null;\r
- }\r
- try {\r
- this.clazz = b.loadClass(className);\r
- return clazz;\r
- } catch (ClassNotFoundException e) {\r
- System.err.println(getClass() + " could not resolve class " + className + ", from bundle " + bundleName);\r
- failed = true;\r
- return null;\r
- }\r
- }\r
-\r
- @Override\r
- public boolean isCompatible(Class<?> contentType) {\r
- Class<?> clazz = resolveClass();\r
- return clazz != null && clazz.equals(contentType);\r
- }\r
-\r
- @Override\r
- public boolean test(ReadGraph graph, Object content)\r
- throws DatabaseException {\r
- Class<?> clazz = resolveClass();\r
- return clazz != null && clazz.isInstance(content);\r
- }\r
-\r
-}\r
+package org.simantics.browsing.ui.model.tests;
+
+import org.eclipse.core.runtime.Platform;
+import org.osgi.framework.Bundle;
+import org.simantics.databoard.Bindings;
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.viewpoint.ontology.ViewpointResource;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * A visual contribution rule test that checks whether the input content is an
+ * instance of a Java class. The class is specified by identifying the source
+ * bundle and the class name.
+ *
+ * @author Tuukka Lehtonen
+ */
+public class InstanceOfTest implements Test {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(InstanceOfTest.class);
+ String bundleName;
+ String className;
+ Class<?> clazz;
+ boolean failed;
+
+ public InstanceOfTest(String bundle, String className) {
+ this.bundleName = bundle;
+ this.className = className;
+ }
+
+ public InstanceOfTest(ReadGraph graph, Resource test) throws DatabaseException {
+ ViewpointResource VP = ViewpointResource.getInstance(graph);
+ this.bundleName = graph.getRelatedValue(test, VP.InstanceOfTest_bundleName, Bindings.STRING);
+ this.className = graph.getRelatedValue(test, VP.InstanceOfTest_className, Bindings.STRING);
+ }
+
+ private Class<?> resolveClass() {
+ if (failed)
+ return null;
+ if (clazz != null)
+ return clazz;
+ Bundle b = Platform.getBundle(bundleName);
+ if (b == null) {
+ LOGGER.error(getClass() + " could not resolve class " + className + ", bundle " + bundleName + " not found in platform");
+ failed = true;
+ return null;
+ }
+ try {
+ this.clazz = b.loadClass(className);
+ return clazz;
+ } catch (ClassNotFoundException e) {
+ LOGGER.error(getClass() + " could not resolve class " + className + ", from bundle " + bundleName, e);
+ failed = true;
+ return null;
+ }
+ }
+
+ @Override
+ public boolean isCompatible(Class<?> contentType) {
+ Class<?> clazz = resolveClass();
+ return clazz != null && clazz.equals(contentType);
+ }
+
+ @Override
+ public boolean test(ReadGraph graph, Object content)
+ throws DatabaseException {
+ Class<?> clazz = resolveClass();
+ return clazz != null && clazz.isInstance(content);
+ }
+
+}