1 /*******************************************************************************
2 * Copyright (c) 2007, 2011 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.db.layer0.variable;
14 import org.simantics.databoard.Datatypes;
15 import org.simantics.databoard.binding.StringBinding;
16 import org.simantics.databoard.binding.error.BindingException;
17 import org.simantics.db.Session;
18 import org.simantics.db.exception.DatabaseException;
19 import org.simantics.db.layer0.request.ResourceURIToVariable;
20 import org.simantics.db.layer0.request.VariableURI;
23 * This class binds Variable to StringType
25 * @author toni.kalajainen
27 public class VariableBinding extends StringBinding {
31 public VariableBinding(Session session) {
32 super(Datatypes.STRING);
33 this.session = session;
37 public boolean isImmutable() {
42 public Object create(String value) throws BindingException {
43 if ( session == null ) throw new BindingException("Cannot create Variable without a Session");
45 return session.sync( new ResourceURIToVariable( value ) );
46 } catch (DatabaseException e) {
47 throw new BindingException(e);
52 public String getValue(Object o) throws BindingException {
53 if ( session == null ) throw new BindingException("Cannot create Variable without a Session");
54 if (o instanceof Variable==false) throw new BindingException("Not a variable");
55 Variable v = (Variable) o;
57 return (String) session.sync( new VariableURI( v ) );
58 } catch (DatabaseException e) {
59 throw new BindingException( e );
64 public void setValue(Object o, String newValue) throws BindingException {
65 throw new BindingException("Cannot set URI to Variable. URI is immutable");
69 public boolean isInstance(Object obj) {
70 return obj instanceof Variable;