1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 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 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.modeling.mapping;
14 import gnu.trove.map.hash.TIntIntHashMap;
15 import gnu.trove.set.hash.TIntHashSet;
17 import org.simantics.db.Resource;
18 import org.simantics.db.WriteGraph;
19 import org.simantics.db.common.utils.CommonDBUtils;
20 import org.simantics.db.exception.DatabaseException;
21 import org.simantics.db.layer0.util.Layer0Utils;
22 import org.simantics.layer0.Layer0;
23 import org.simantics.layer0.utils.direct.GraphUtils;
24 import org.simantics.mapping.constraint.instructions.TypedBracketInstruction.CreationInstruction;
25 import org.simantics.modeling.services.ComponentNamingUtil;
26 import org.simantics.modeling.services.NamingException;
27 import org.simantics.project.IProject;
29 public class NamingCreationInstruction extends CreationInstruction {
32 int configurationRoot;
36 public NamingCreationInstruction(IProject project, int configurationRoot, int variableId, int componentType,
39 this.project = project;
40 this.configurationRoot = configurationRoot;
41 lComponentType = componentType;
42 lConfiguration = configuration;
46 public Resource create(WriteGraph g, Object[] bindings) throws DatabaseException {
47 Resource componentType = (Resource) bindings[lComponentType];
48 Resource configuration = (Resource) bindings[lConfiguration];
51 CommonDBUtils.selectClusterSet(g, configuration);
52 String proposition = ComponentNamingUtil.findFreshInstanceName(g, project, (Resource)bindings[configurationRoot], configuration, componentType);
53 Layer0 b = Layer0.getInstance(g);
54 Resource result = GraphUtils.create(g,
55 b.HasName, proposition
57 Layer0Utils.claimNewIdentifier(g, result, true);
59 } catch (NamingException e1) {
60 throw new DatabaseException(e1);
65 public void mapVariables(TIntIntHashMap map) {
66 super.mapVariables(map);
67 lComponentType = map.get(lComponentType);
68 lConfiguration = map.get(lConfiguration);
69 configurationRoot = map.get(configurationRoot);
73 public void collectVariables(TIntHashSet reads, TIntHashSet writes) {
74 reads.add(lComponentType);
75 reads.add(lConfiguration);
76 reads.add(configurationRoot);