1 /*******************************************************************************
2 * Copyright (c) 2013 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 * Semantum Oy - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.modeling.typicals.rules;
14 import java.util.Collection;
16 import org.simantics.db.Resource;
17 import org.simantics.db.WriteGraph;
18 import org.simantics.db.common.utils.NameUtils;
19 import org.simantics.db.exception.DatabaseException;
20 import org.simantics.layer0.Layer0;
21 import org.simantics.modeling.typicals.ITypicalSynchronizationRule;
22 import org.simantics.modeling.typicals.TypicalInfo;
25 * Synchronizes L0.InstanceOf relations from template to instance.
27 * @author Tuukka Lehtonen
29 public enum InstanceOfRule implements ITypicalSynchronizationRule {
33 public static InstanceOfRule getInstance() {
38 public boolean synchronize(WriteGraph graph, Resource template, Resource instance, TypicalInfo info) throws DatabaseException {
39 boolean changed = false;
40 Layer0 L0 = Layer0.getInstance(graph);
41 Collection<Resource> templateInstanceOf = graph.getObjects(template, L0.InstanceOf);
42 Collection<Resource> instanceInstanceOf = graph.getObjects(instance, L0.InstanceOf);
44 for (Resource instanceOf : templateInstanceOf) {
45 if (!graph.hasStatement(instance, L0.InstanceOf, instanceOf)) {
46 graph.claim(instance, L0.InstanceOf, instanceOf);
47 info.messageLog.add("\t\t\tadd type " + NameUtils.getSafeName(graph, instanceOf));
51 for (Resource instanceOf : instanceInstanceOf) {
52 if (!templateInstanceOf.contains(instanceOf) && graph.hasStatement(instance, L0.InstanceOf, instanceOf)) {
53 graph.deny(instance, L0.InstanceOf, instanceOf);
54 info.messageLog.add("\t\t\tremove type " + NameUtils.getSafeName(graph, instanceOf));