1 /*******************************************************************************
2 * Copyright (c) 2017 Association for Decentralized Information Management
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 * Semantum Oy - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.modeling.ui.scl.scriptEditor;
14 import org.simantics.databoard.Bindings;
15 import org.simantics.db.Resource;
16 import org.simantics.db.WriteGraph;
17 import org.simantics.db.common.request.WriteRequest;
18 import org.simantics.db.exception.DatabaseException;
19 import org.simantics.layer0.Layer0;
22 * @author Tuukka Lehtonen
25 public class WriteSCLScriptDefinition extends WriteRequest {
27 private final String scriptURI;
28 private final String definition;
30 public WriteSCLScriptDefinition(String scriptURI, String sourceText) {
31 this.scriptURI = scriptURI;
32 this.definition = sourceText;
36 public void perform(WriteGraph graph) throws DatabaseException {
37 Resource moduleResource = graph.getPossibleResource(scriptURI);
38 if (moduleResource == null)
40 Layer0 L0 = Layer0.getInstance(graph);
41 if (!graph.isInstanceOf(moduleResource, L0.SCLScript))
43 graph.claimLiteral(moduleResource, L0.SCLScript_definition, definition, Bindings.STRING);