1 /*******************************************************************************
\r
2 * Copyright (c) 2007, 2011 Association for Decentralized Information Management in
\r
4 * All rights reserved. This program and the accompanying materials
\r
5 * are made available under the terms of the Eclipse Public License v1.0
\r
6 * which accompanies this distribution, and is available at
\r
7 * http://www.eclipse.org/legal/epl-v10.html
\r
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.db.layer0.variable;
\r
14 import org.simantics.databoard.Datatypes;
\r
15 import org.simantics.databoard.binding.StringBinding;
\r
16 import org.simantics.databoard.binding.error.BindingException;
\r
17 import org.simantics.db.Session;
\r
18 import org.simantics.db.exception.DatabaseException;
\r
19 import org.simantics.db.layer0.request.ResourceURIToVariable;
\r
20 import org.simantics.db.layer0.request.VariableURI;
\r
23 * This class binds Variable to StringType
\r
25 * @author toni.kalajainen
\r
27 public class VariableBinding extends StringBinding {
\r
31 public VariableBinding(Session session) {
\r
32 super(Datatypes.STRING);
\r
33 this.session = session;
\r
37 public boolean isImmutable() {
\r
42 public Object create(String value) throws BindingException {
\r
43 if ( session == null ) throw new BindingException("Cannot create Variable without a Session");
\r
45 return session.sync( new ResourceURIToVariable( value ) );
\r
46 } catch (DatabaseException e) {
\r
47 throw new BindingException(e);
\r
52 public String getValue(Object o) throws BindingException {
\r
53 if ( session == null ) throw new BindingException("Cannot create Variable without a Session");
\r
54 if (o instanceof Variable==false) throw new BindingException("Not a variable");
\r
55 Variable v = (Variable) o;
\r
57 return (String) session.sync( new VariableURI( v ) );
\r
58 } catch (DatabaseException e) {
\r
59 throw new BindingException( e );
\r
64 public void setValue(Object o, String newValue) throws BindingException {
\r
65 throw new BindingException("Cannot set URI to Variable. URI is immutable");
\r
69 public boolean isInstance(Object obj) {
\r
70 return obj instanceof Variable;
\r