- }\r
-\r
- @SuppressWarnings("unchecked")\r
- public static <T extends Binding> T getBinding(BindingRequest request)\r
- throws BindingConstructionException\r
- {\r
- synchronized(classBindingFactory) {\r
- return (T) classBindingFactory.construct(request);\r
- }\r
- }\r
- \r
- /**\r
- * Get a binding for a Java Class. Use this method to acquire class \r
- * parameters for a generics class. <p>\r
- * \r
- * Example 1: \r
- * \r
- * Binding binding = Bindings.getBinding(Map.class, String.class, Integer.class);\r
- * Map<String, Integer> map = (Map<String, Integer>) binding.createDefault();\r
- * \r
- * Example 2:\r
- * \r
- * Binding d = Bindings.getBinding(List.class, Integer.class);\r
- * List<Integer> list = (List<Integer>) d.createRandom(5);\r
- * \r
- * Example 3:\r
- * \r
- * Binding d = Bindings.getBinding(List.class, List.class, Integer.class);\r
- * List<List<Integer>> list = (List<List<Integer>>) d.createRandom(5);\r
- * \r
- * @see ClassBindingFactory \r
- * @param clazz\r
- * @return binding\r
- * @throws BindingConstructionException\r
- */\r
- @SuppressWarnings("unchecked")\r
- public static <T extends Binding> T getBinding(Class<?> clazz, Class<?>...parameters)\r
- throws BindingConstructionException\r
- {\r
- BindingRequest request = new BindingRequest( clazz, parameters );\r
- synchronized(classBindingFactory) {\r
- return (T) classBindingFactory.construct(request);\r
- }\r
- }\r
-\r
- /**\r
- * Try to get a binding for the actual class of a Java object.\r
- * @param obj A Java object\r
- * @return A binding for the class of the object\r
- * @throws BindingConstructionException if no binding can be constructed\r
- */\r
- public static <T extends Binding> T getInstanceBinding(Object obj)\r
- throws BindingConstructionException\r
- {\r
- return getBinding(obj.getClass());\r
- }\r
- \r
- /**\r
- * Read binding and type from a class. DataType details and parameters\r
- * are read as annotations placed in the class. \r
- * (See org.simantics.databoard.annotations)\r
- * <p>\r
- * As an exception, in the subclasses of {@link Throwable}, the fields of\r
- * Throwable are omited.\r
- * <p>\r
- * This method is used for well-known classes where the caller is 100% sure\r
- * that a binding is construable without exception. <p> \r
- * \r
- * @param clazz\r
- * @return binding\r
- * @throws RuntimeBindingConstructionException\r
- */\r
- @SuppressWarnings("unchecked")\r
- public static <T extends Binding> T getBindingUnchecked(Class<?> clazz)\r
- throws RuntimeBindingConstructionException\r
- {\r
- try {\r
- return (T) getBinding(clazz);\r
- } catch (BindingConstructionException e) {\r
- throw new RuntimeBindingConstructionException(e);\r
- }\r
+ }
+
+ @SuppressWarnings("unchecked")
+ public static <T extends Binding> T getBinding(BindingRequest request)
+ throws BindingConstructionException
+ {
+ synchronized(classBindingFactory) {
+ return (T) classBindingFactory.construct(request);
+ }
+ }
+
+ /**
+ * Get a binding for a Java Class. Use this method to acquire class
+ * parameters for a generics class. <p>
+ *
+ * Example 1:
+ *
+ * Binding binding = Bindings.getBinding(Map.class, String.class, Integer.class);
+ * Map<String, Integer> map = (Map<String, Integer>) binding.createDefault();
+ *
+ * Example 2:
+ *
+ * Binding d = Bindings.getBinding(List.class, Integer.class);
+ * List<Integer> list = (List<Integer>) d.createRandom(5);
+ *
+ * Example 3:
+ *
+ * Binding d = Bindings.getBinding(List.class, List.class, Integer.class);
+ * List<List<Integer>> list = (List<List<Integer>>) d.createRandom(5);
+ *
+ * @see ClassBindingFactory
+ * @param clazz
+ * @return binding
+ * @throws BindingConstructionException
+ */
+ @SuppressWarnings("unchecked")
+ public static <T extends Binding> T getBinding(Class<?> clazz, Class<?>...parameters)
+ throws BindingConstructionException
+ {
+ BindingRequest request = new BindingRequest( clazz, parameters );
+ synchronized(classBindingFactory) {
+ return (T) classBindingFactory.construct(request);
+ }
+ }
+
+ /**
+ * Try to get a binding for the actual class of a Java object.
+ * @param obj A Java object
+ * @return A binding for the class of the object
+ * @throws BindingConstructionException if no binding can be constructed
+ */
+ public static <T extends Binding> T getInstanceBinding(Object obj)
+ throws BindingConstructionException
+ {
+ return getBinding(obj.getClass());
+ }
+
+ /**
+ * Read binding and type from a class. DataType details and parameters
+ * are read as annotations placed in the class.
+ * (See org.simantics.databoard.annotations)
+ * <p>
+ * As an exception, in the subclasses of {@link Throwable}, the fields of
+ * Throwable are omited.
+ * <p>
+ * This method is used for well-known classes where the caller is 100% sure
+ * that a binding is construable without exception. <p>
+ *
+ * @param clazz
+ * @return binding
+ * @throws RuntimeBindingConstructionException
+ */
+ @SuppressWarnings("unchecked")
+ public static <T extends Binding> T getBindingUnchecked(Class<?> clazz)
+ throws RuntimeBindingConstructionException
+ {
+ try {
+ return (T) getBinding(clazz);
+ } catch (BindingConstructionException e) {
+ throw new RuntimeBindingConstructionException(e);
+ }
+ }
+
+ /**
+ * Get a binding for a Java Class. Use this method to acquire class
+ * parameters for a generics class. <p>
+ *
+ * Example 1:
+ *
+ * Binding binding = Bindings.getBinding(Map.class, String.class, Integer.class);
+ * Map<String, Integer> map = (Map<String, Integer>) binding.createDefault();
+ *
+ * Example 2:
+ *
+ * Binding d = Bindings.getBinding(List.class, Integer.class);
+ * List<Integer> list = (List<Integer>) d.createRandom(5);
+ *
+ * Example 3:
+ *
+ * Binding d = Bindings.getBinding(List.class, List.class, Integer.class);
+ * List<List<Integer>> list = (List<List<Integer>>) d.createRandom(5);
+ *
+ * @see ClassBindingFactory
+ * @param clazz
+ * @return binding
+ * @throws BindingConstructionException
+ */
+ @SuppressWarnings("unchecked")
+ public static <T extends Binding> T getBindingUnchecked(Class<?> clazz, Class<?>...parameters)
+ throws RuntimeBindingConstructionException
+ {
+ try {
+ Arguments args = new ArgumentImpl(parameters);
+ BindingRequest request = new BindingRequest( clazz, args );
+ Binding binding = bindingRepository.get( request );
+ if (binding!=null);
+ synchronized(classBindingFactory) {
+ binding = classBindingFactory.construct(request);
+ }
+ return (T) binding;
+ } catch (BindingConstructionException e) {
+ throw new RuntimeBindingConstructionException(e);
+ }