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.impl;
14 import org.simantics.databoard.binding.Binding;
15 import org.simantics.databoard.binding.OptionalBinding;
16 import org.simantics.databoard.binding.error.BindingException;
17 import org.simantics.databoard.binding.error.UnsupportedOperationException;
18 import org.simantics.databoard.type.OptionalType;
21 * This implementation binds OptionalType to null / Object assignment.
23 * @author Toni Kalajainen
25 public class OptionalBindingDefault extends OptionalBinding {
27 public OptionalBindingDefault(Binding componentBinding) {
28 super(componentBinding);
31 public OptionalBindingDefault(OptionalType type, Binding componentBinding) {
32 super(type, componentBinding);
36 * Create result with no value
40 public Object createNoValue() {
45 * Create result with a value
48 * @return argument that contains a value
50 public Object createValue(Object value)
51 throws BindingException {
52 // Only this implementation, sub-classes may have another behaviour
53 if (value==null) throw new BindingException("Cannot bind null as a value");
58 * Tests whether arg contains a value
61 * @return true if arg contained a value
63 public boolean hasValue(Object arg) {
68 * Get the non-null value, the arg did not contain a value,
69 * BindingException is thrown.
71 * @param arg argument that contains a value
72 * @return the composite value
73 * @throws BindingException
75 public Object getValue(Object arg)
76 throws BindingException {
77 if (arg == null) throw new BindingException("Optional value ("+arg+") does not contain value.");
81 public void setValue(Object optional, Object componentValue)
82 throws BindingException {
83 if (componentValue==optional) return;
84 throw new UnsupportedOperationException("Cannot set new value to container of java.lang.Object");
87 public void setNoValue(Object optional)
88 throws BindingException
90 if (optional==null) return;
91 throw new UnsupportedOperationException("Cannot remove value from container of java.lang.Object");
95 public boolean isInstance(Object obj) {
96 if (obj==null) return true;
97 return componentBinding.isInstance(obj);
101 public boolean isImmutable() {