1 package org.simantics.databoard.binding.mutable;
\r
3 import org.simantics.databoard.binding.Binding;
\r
4 import org.simantics.databoard.binding.UnionBinding;
\r
5 import org.simantics.databoard.binding.error.BindingException;
\r
6 import org.simantics.databoard.type.UnionType;
\r
9 * Binds UnionType to TaggedObject.class
\r
11 * @author Toni Kalajainen <toni.kalajainen@vtt.fi>
\r
13 public class UnionTaggedObjectBinding extends UnionBinding {
\r
15 public UnionTaggedObjectBinding(UnionType type, Binding[] componentBindings)
\r
17 this.componentBindings = componentBindings;
\r
18 if (type==null) throw new IllegalArgumentException("null arg");
\r
23 public Object create(int tag, Object value) {
\r
24 TaggedObject result = new TaggedObject();
\r
26 result.value = value;
\r
31 public void setValue(Object union, int tag, Object value)
\r
32 throws BindingException {
\r
33 TaggedObject result = (TaggedObject)union;
\r
35 result.value = value;
\r
39 public int getTag(Object obj) throws BindingException {
\r
40 if (!isInstance(obj)) throw new BindingException("Unexpected class "+obj.getClass().getSimpleName()+", TaggedObject expected");
\r
41 TaggedObject to = (TaggedObject) obj;
\r
46 public Object getValue(Object obj) throws BindingException {
\r
47 if (!isInstance(obj)) throw new BindingException("Unexpected class "+obj.getClass().getSimpleName()+", TaggedObject expected");
\r
48 TaggedObject to = (TaggedObject) obj;
\r
53 public boolean isInstance(Object obj) {
\r
54 return obj instanceof TaggedObject;
\r