1 /*******************************************************************************
2 * Copyright (c) 2014 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.db.layer0.adapter.impl;
14 import org.simantics.databoard.Bindings;
15 import org.simantics.db.ReadGraph;
16 import org.simantics.db.Resource;
17 import org.simantics.db.WriteGraph;
18 import org.simantics.db.exception.DatabaseException;
19 import org.simantics.db.layer0.adapter.StringModifier;
20 import org.simantics.layer0.Layer0;
23 * A modifier that enforces all the same naming validations as
24 * {@link EntityNameModifier} but also makes sure that entities directly related
25 * to the specified entity with the specified relation are renamed at the same
28 * @author Tuukka Lehtonen
29 * @see EntityNameModifier
31 public final class RelatedEntityNameModifier implements StringModifier {
33 private EntityNameModifier entityModifier;
34 private Resource entity;
35 private Resource relation;
37 public RelatedEntityNameModifier(ReadGraph graph, Resource entity, Resource property, Resource relation) throws DatabaseException {
38 this.entityModifier = new EntityNameModifier(graph, entity, property);
40 this.relation = relation;
44 public String getValue() {
45 return entityModifier.getValue();
49 public String isValid(String value) {
50 return entityModifier.isValid(value);
54 final public void modify(WriteGraph graph, String value) throws DatabaseException {
55 entityModifier.modify(graph, value);
57 Layer0 L0 = Layer0.getInstance(graph);
58 String v = entityModifier.finalValue(value);
59 for (Resource related : graph.getObjects(entity, relation))
60 graph.claimLiteral(related, L0.HasName, L0.NameOf, v, Bindings.STRING);