--- /dev/null
+/*******************************************************************************\r
+ * Copyright (c) 2014 Association for Decentralized Information Management\r
+ * in Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ * Semantum Oy - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.db.layer0.adapter.impl;\r
+\r
+import org.simantics.databoard.Bindings;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.WriteGraph;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.layer0.adapter.StringModifier;\r
+import org.simantics.layer0.Layer0;\r
+\r
+/**\r
+ * A modifier that enforces all the same naming validations as\r
+ * {@link EntityNameModifier} but also makes sure that entities directly related\r
+ * to the specified entity with the specified relation are renamed at the same\r
+ * time.\r
+ * \r
+ * @author Tuukka Lehtonen\r
+ * @see EntityNameModifier\r
+ */\r
+public final class RelatedEntityNameModifier implements StringModifier {\r
+\r
+ private EntityNameModifier entityModifier;\r
+ private Resource entity;\r
+ private Resource relation;\r
+\r
+ public RelatedEntityNameModifier(ReadGraph graph, Resource entity, Resource property, Resource relation) throws DatabaseException {\r
+ this.entityModifier = new EntityNameModifier(graph, entity, property);\r
+ this.entity = entity;\r
+ this.relation = relation;\r
+ }\r
+\r
+ @Override\r
+ public String getValue() {\r
+ return entityModifier.getValue();\r
+ }\r
+\r
+ @Override\r
+ public String isValid(String value) {\r
+ return entityModifier.isValid(value);\r
+ }\r
+\r
+ @Override\r
+ final public void modify(WriteGraph graph, String value) throws DatabaseException {\r
+ entityModifier.modify(graph, value);\r
+\r
+ Layer0 L0 = Layer0.getInstance(graph);\r
+ String v = entityModifier.finalValue(value); \r
+ for (Resource related : graph.getObjects(entity, relation))\r
+ graph.claimLiteral(related, L0.HasName, L0.NameOf, v, Bindings.STRING);\r
+ }\r
+\r
+}\r