import java.util.Map;\r
\r
import org.apache.commons.collections.map.ReferenceMap;\r
+import org.simantics.databoard.Bindings;\r
import org.simantics.databoard.Units;\r
import org.simantics.databoard.binding.ArrayBinding;\r
import org.simantics.databoard.binding.Binding;\r
return result;
}\r
\r
+ if (domain instanceof VariantBinding && !(range instanceof VariantBinding))\r
+ {\r
+ // Make a recursive adaptation from a variant source\r
+ final VariantBinding domainBinding = (VariantBinding)domain;\r
+ final Binding rangeBinding = range;\r
+ AbstractAdapter result = new AbstractAdapter() {\r
+ @Override\r
+ public Object adapt(Object obj) throws AdaptException {\r
+ try {\r
+ Object value = domainBinding.getContent(obj);\r
+ Binding contentBinding = domainBinding.getContentBinding(obj);\r
+ AbstractAdapter adapter = (AbstractAdapter) getAdapter(contentBinding, rangeBinding, typeAdapter, mustClone);\r
+ return adapter.adapt(value);\r
+ } catch (BindingException | AdapterConstructionException e) {\r
+ throw new AdaptException(e);\r
+ }\r
+ }\r
+ };\r
+ result.clones = mustClone;\r
+ addToCache(req, result);\r
+ return result; \r
+ }\r
+ \r
if (range instanceof VariantBinding && !(domain instanceof VariantBinding))\r
{\r
// Default to just wrapping the domain type\r
import org.simantics.databoard.type.FloatType;\r
import org.simantics.databoard.type.IntegerType;\r
import org.simantics.databoard.type.LongType;\r
+import org.simantics.databoard.type.MapType;\r
import org.simantics.databoard.type.OptionalType;\r
import org.simantics.databoard.type.RecordType;\r
import org.simantics.databoard.type.StringType;\r
lengths[i] = org.simantics.databoard.util.Range.valueOf(strs[i]); \r
}\r
\r
- if ( binding.componentBinding==null && request.componentBinding!=null ) binding.componentBinding = request.componentBinding;\r
+ if ( binding.componentBinding==null && request.componentBindings!=null ) binding.componentBinding = request.componentBindings[0];\r
if ( binding.componentBinding == null) {\r
- BindingRequest componentRequest = request.componentRequest;\r
- if (componentClass!=null && componentRequest==null) {\r
+ BindingRequest componentRequest = request.componentRequests != null ? request.componentRequests[0] : null;\r
+ if (componentRequest==null) {\r
+ if (componentClass==null) {\r
+ componentClass = Object.class;\r
+ // throw new BindingConstructionException("Cannot determine array component type");\r
+ }\r
componentRequest = new BindingRequest(componentClass, componentAnnotations); \r
}\r
- if (componentRequest==null) {\r
- throw new BindingConstructionException("Cannot determine array component type");\r
- }\r
\r
inprogress.put(request, binding);\r
binding.componentBinding = construct( componentRequest );\r
\r
Arguments argumentsAnnotation = request.getAnnotation(Arguments.class);\r
Annotation[] componentAnnotations = request.dropAnnotations( 2 );\r
+ Class<?>[] arguments = argumentsAnnotation != null ? argumentsAnnotation.value() : null;\r
\r
BindingRequest keyRequest = null;\r
BindingRequest valueRequest = null;\r
+ \r
+ Binding keyBinding = null;\r
+ Binding valueBinding = null;\r
\r
- if (binding.getKeyBinding() == null) {\r
- Class<?> keyClass = argumentsAnnotation.value()[0];\r
+ if (binding.getKeyBinding() != null) {\r
+ keyBinding = binding.getKeyBinding();\r
+ }\r
+ else if (request.componentBindings != null) {\r
+ keyBinding = request.componentBindings[0];\r
+ }\r
+ else if (request.componentRequests != null) {\r
+ keyRequest = request.componentRequests[0];\r
+ }\r
+ else {\r
+ Class<?> keyClass = arguments != null && arguments.length >= 1 ? arguments[0] : null;\r
if (keyClass==null) {\r
- throw new BindingConstructionException("Cannot determine key class, use @Arguments annotation");\r
+ keyClass = Object.class;\r
+ //throw new BindingConstructionException("Cannot determine key class, use @Arguments annotation");\r
}\r
keyRequest = new BindingRequest(keyClass, componentAnnotations);\r
}\r
- else {\r
- binding.type().keyType = binding.getKeyBinding().type(); \r
- }\r
\r
- if (binding.getValueBinding() == null) {\r
- Class<?> valueClass = argumentsAnnotation.value()[1];\r
+ if (binding.getValueBinding() != null) {\r
+ valueBinding = binding.getValueBinding();\r
+ }\r
+ else if (request.componentBindings != null) {\r
+ valueBinding = request.componentBindings[1];\r
+ }\r
+ else if (request.componentRequests != null) {\r
+ valueRequest = request.componentRequests[1];\r
+ }\r
+ else {\r
+ Class<?> valueClass = arguments != null && arguments.length >= 2 ? arguments[1] : null;\r
if (valueClass==null) {\r
- throw new BindingConstructionException("Cannot determine value class, use @Arguments annotation");\r
+ valueClass = Object.class;\r
+ //throw new BindingConstructionException("Cannot determine value class, use @Arguments annotation");\r
}\r
valueRequest = new BindingRequest(valueClass, componentAnnotations);\r
}\r
- else {\r
- binding.type().valueType = binding.getValueBinding().type(); \r
- }\r
- \r
+ \r
inprogress.put(request, result);\r
if (keyRequest!=null) {\r
- Binding keyBinding = construct( keyRequest );\r
- binding.type().keyType = keyBinding.type();\r
- binding.setKeyBinding(keyBinding);\r
+ keyBinding = construct( keyRequest );\r
}\r
if (valueRequest!=null) {\r
- Binding valueBinding = construct( valueRequest );\r
- binding.type().valueType = valueBinding.type();\r
- binding.setValueBinding(valueBinding);\r
+ valueBinding = construct( valueRequest );\r
}\r
- inprogress.remove(request);\r
+ inprogress.remove(request);\r
+ \r
+ MapType type = binding.type();\r
+ type.keyType = keyBinding.type();\r
+ type.valueType = valueBinding.type();\r
+ binding.setKeyBinding( keyBinding );\r
+ binding.setValueBinding( valueBinding );\r
}\r
\r
/// Optional\r