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