1 /*******************************************************************************
2 * Copyright (c) 2010 Association for Decentralized Information Management in
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.databoard.binding.mutable;
16 import org.simantics.databoard.adapter.AdapterFactory;
17 import org.simantics.databoard.binding.Binding;
18 import org.simantics.databoard.binding.error.BindingException;
19 import org.simantics.databoard.binding.reflection.ClassBindingFactory;
22 * MutableVariantBinding binds VariantType to {@link MutableVariant} Class.
24 public class MutableVariantBinding extends ImmutableVariantBinding {
26 public MutableVariantBinding(ClassBindingFactory bindingFactory, AdapterFactory adapterFactory) {
27 super(bindingFactory, adapterFactory);
31 public Object create(Binding binding, Object value) throws BindingException {
32 return new MutableVariant(binding, value);
36 public boolean isImmutable() {
41 public boolean isInstance(Object obj) {
42 if (obj==null) return false;
43 if (obj instanceof MutableVariant == false) return false;
48 public void assertInstaceIsValid(Object obj, Set<Object> validInstances) throws BindingException {
49 if (obj==null) throw new BindingException("null value is not MutableVariant");
50 if (obj instanceof MutableVariant == false) throw new BindingException("wrong class, MutableVariant expected");
51 MutableVariant var = (MutableVariant) obj;
52 if (var.binding==null) throw new BindingException("Binding is expected");
53 var.binding.assertInstaceIsValid(var.value, validInstances);
57 public void setContent(Object variant, Binding binding, Object value)
58 throws BindingException {
59 assert(isValid(binding, value));
60 MutableVariant var = (MutableVariant) variant;
61 var.binding = binding;