-package org.simantics.databoard.adapter;\r
-\r
-import java.util.HashMap;\r
-import java.util.Map;\r
-\r
-import org.simantics.databoard.binding.Binding;\r
-import org.simantics.databoard.binding.error.BindingConstructionException;\r
-import org.simantics.databoard.binding.error.RuntimeBindingConstructionException;\r
-import org.simantics.databoard.type.Datatype;\r
-\r
-public abstract class NewAdapterFactory {\r
- \r
- /**\r
- * Map of failed constructions. \r
- */\r
- protected Map<Datatype, BindingConstructionException> failures = new HashMap<Datatype, BindingConstructionException>();\r
- \r
- /**\r
- * Map that contains in incomplete constructions.\r
- */\r
- protected Map<Datatype, Binding> inprogress = new HashMap<Datatype, Binding>();\r
- \r
- /**\r
- * Repository where successful constructions are placed. \r
- */\r
- protected Map<Datatype, Binding> repository; \r
- \r
- /**\r
- * Create a scheme factory. \r
- */\r
- public NewAdapterFactory() { \r
- }\r
- \r
- /**\r
- * Create scheme factory that appends constructed bindings to the user given\r
- * repository \r
- * \r
- * @param repository repository where bindings are placed\r
- */\r
- public NewAdapterFactory(Map<Datatype, Binding> repository) {\r
- this.repository = repository;\r
- }\r
- \r
- /**\r
- * Get adapter repository\r
- * \r
- * @return adapter repository\r
- */\r
- public Map<Datatype, Binding> getRepository() {\r
- return repository;\r
- }\r
-\r
- /**\r
- * Constructs a binding to comply to datatype request.\r
- * This is the method sub-classes implement. \r
- * The implementation should use the inprogress -map for construction of \r
- * bindings that have component types.\r
- * \r
- * e.g. \r
- * inprogress.put(request, notCompletelyConstructedBinding);\r
- * Binding componentBinding = construct( componentRequest );\r
- * notCompletelyConstructedBinding.setChild( componentBinding );\r
- * inprogress.remove(request);\r
- * \r
- * try-finally is not needed.\r
- * \r
- * @param request\r
- * @return\r
- * @throws BindingConstructionException\r
- */\r
- protected abstract Binding doConstruct(Datatype request) throws BindingConstructionException;\r
- \r
- public Binding construct(Datatype request) throws BindingConstructionException\r
- {\r
- if (failures.containsKey(request)) throw failures.get(request);\r
- if (inprogress.containsKey(request)) return inprogress.get(request);\r
- if (repository.containsKey(request)) return repository.get(request);\r
- \r
- // Start construction\r
- try { \r
- Binding binding = doConstruct(request);\r
- repository.put(request, binding);\r
- return binding;\r
- } catch (BindingConstructionException e) {\r
- inprogress.remove( request );\r
- failures.put(request, e);\r
- throw e;\r
- }\r
- }\r
-\r
- public Binding getBinding(Datatype type)\r
- throws BindingConstructionException { \r
- return construct(type);\r
- }\r
- \r
- public Binding getBindingUnchecked(Datatype type)\r
- throws RuntimeBindingConstructionException {\r
- try {\r
- return construct(type);\r
- } catch (BindingConstructionException e) {\r
- throw new RuntimeBindingConstructionException(e);\r
- }\r
- } \r
-\r
-}\r
+package org.simantics.databoard.adapter;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.simantics.databoard.binding.Binding;
+import org.simantics.databoard.binding.error.BindingConstructionException;
+import org.simantics.databoard.binding.error.RuntimeBindingConstructionException;
+import org.simantics.databoard.type.Datatype;
+
+public abstract class NewAdapterFactory {
+
+ /**
+ * Map of failed constructions.
+ */
+ protected Map<Datatype, BindingConstructionException> failures = new HashMap<Datatype, BindingConstructionException>();
+
+ /**
+ * Map that contains in incomplete constructions.
+ */
+ protected Map<Datatype, Binding> inprogress = new HashMap<Datatype, Binding>();
+
+ /**
+ * Repository where successful constructions are placed.
+ */
+ protected Map<Datatype, Binding> repository;
+
+ /**
+ * Create a scheme factory.
+ */
+ public NewAdapterFactory() {
+ }
+
+ /**
+ * Create scheme factory that appends constructed bindings to the user given
+ * repository
+ *
+ * @param repository repository where bindings are placed
+ */
+ public NewAdapterFactory(Map<Datatype, Binding> repository) {
+ this.repository = repository;
+ }
+
+ /**
+ * Get adapter repository
+ *
+ * @return adapter repository
+ */
+ public Map<Datatype, Binding> getRepository() {
+ return repository;
+ }
+
+ /**
+ * Constructs a binding to comply to datatype request.
+ * This is the method sub-classes implement.
+ * The implementation should use the inprogress -map for construction of
+ * bindings that have component types.
+ *
+ * e.g.
+ * inprogress.put(request, notCompletelyConstructedBinding);
+ * Binding componentBinding = construct( componentRequest );
+ * notCompletelyConstructedBinding.setChild( componentBinding );
+ * inprogress.remove(request);
+ *
+ * try-finally is not needed.
+ *
+ * @param request
+ * @return
+ * @throws BindingConstructionException
+ */
+ protected abstract Binding doConstruct(Datatype request) throws BindingConstructionException;
+
+ public Binding construct(Datatype request) throws BindingConstructionException
+ {
+ if (failures.containsKey(request)) throw failures.get(request);
+ if (inprogress.containsKey(request)) return inprogress.get(request);
+ if (repository.containsKey(request)) return repository.get(request);
+
+ // Start construction
+ try {
+ Binding binding = doConstruct(request);
+ repository.put(request, binding);
+ return binding;
+ } catch (BindingConstructionException e) {
+ inprogress.remove( request );
+ failures.put(request, e);
+ throw e;
+ }
+ }
+
+ public Binding getBinding(Datatype type)
+ throws BindingConstructionException {
+ return construct(type);
+ }
+
+ public Binding getBindingUnchecked(Datatype type)
+ throws RuntimeBindingConstructionException {
+ try {
+ return construct(type);
+ } catch (BindingConstructionException e) {
+ throw new RuntimeBindingConstructionException(e);
+ }
+ }
+
+}