]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.databoard/src/org/simantics/databoard/binding/factory/BindingRepository.java
Improved Bindings.getBinding(Class) caching for Datatype.class
[simantics/platform.git] / bundles / org.simantics.databoard / src / org / simantics / databoard / binding / factory / BindingRepository.java
index 4680eee6a961b9d147fc5c0b3cb4478ae49a5e0e..ba24353712c7f90f415b4b2652f7699dba5b27d0 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************
 /*******************************************************************************
- * Copyright (c) 2007, 2011 Association for Decentralized Information Management in
+ * Copyright (c) 2007, 2018 Association for Decentralized Information Management in
  * Industry THTH ry.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * Industry THTH ry.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
@@ -8,6 +8,7 @@
  *
  * Contributors:
  *     VTT Technical Research Centre of Finland - initial API and implementation
  *
  * Contributors:
  *     VTT Technical Research Centre of Finland - initial API and implementation
+ *     Semantum Oy - gitlab #82
  *******************************************************************************/
 package org.simantics.databoard.binding.factory;
 
  *******************************************************************************/
 package org.simantics.databoard.binding.factory;
 
@@ -17,6 +18,7 @@ import java.util.Map.Entry;
 
 import org.simantics.databoard.binding.Binding;
 import org.simantics.databoard.binding.reflection.BindingRequest;
 
 import org.simantics.databoard.binding.Binding;
 import org.simantics.databoard.binding.reflection.BindingRequest;
+import org.simantics.databoard.type.Datatype;
 
 public class BindingRepository {
        
 
 public class BindingRepository {
        
@@ -114,9 +116,20 @@ public class BindingRepository {
                classMap.clear();
        }
 
                classMap.clear();
        }
 
+       /**
+        * {@link Datatype} class has annotations but it can be considered a "class
+        * request" as it is a fundamental building block of Databoard and it has a
+        * fixed structure. Therefore {@link #classMap} is allowed to contain a cached
+        * Datatype.class -> Binding mapping.
+        */
+       private static final String DATATYPE_CLASS_NAME = Datatype.class.getName();
+
        boolean isClassRequest( BindingRequest request )
        {
        boolean isClassRequest( BindingRequest request )
        {
-               return request.className != null && (request.annotations==null || request.annotations.length==0);
+               return (request.className != null
+                               && ((request.annotations==null || request.annotations.length==0)
+                                               || DATATYPE_CLASS_NAME.equals(request.className))
+                               );
        }
 
 }
        }
 
 }