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.db.layer0.variable;
14 import java.util.Collection;
15 import java.util.Collections;
17 import org.simantics.databoard.binding.mutable.Variant;
18 import org.simantics.db.WriteGraph;
19 import org.simantics.db.exception.DatabaseException;
22 * Obtained with Variable.adapt
24 public interface VariableSpaceManipulator {
26 public class PropertyCreationData {
29 public PropertyCreationData(String name, Variant value) {
34 public static PropertyCreationData build(String name, Object value) {
35 return new PropertyCreationData(name, Variant.ofInstance(value));
40 public class ChildCreationData {
43 public PropertyCreationData[] properties;
44 public ChildCreationData(String name, String type, PropertyCreationData[] properties) {
47 this.properties = properties;
50 public static ChildCreationData build(String name, String type, PropertyCreationData ... properties) {
51 return new ChildCreationData(name, type, properties);
56 public class Modification {
58 public String[] removedProperties;
59 public String[] removedChildren;
60 public PropertyCreationData[] newProperties;
61 public ChildCreationData[] newChildren;
63 public Modification(String[] removedProperties, String[] removedChildren, PropertyCreationData[] newProperties, ChildCreationData[] newChildren) {
64 this.removedProperties = removedProperties;
65 this.removedChildren = removedChildren;
66 this.newProperties = newProperties;
67 this.newChildren = newChildren;
70 public static Modification build(Collection<String> removedProperties, Collection<String> removedChildren, Collection<PropertyCreationData> newProperties, Collection<ChildCreationData> newChildren) {
71 return new Modification(
72 removedProperties.toArray(new String[removedProperties.size()]),
73 removedChildren.toArray(new String[removedChildren.size()]),
74 newProperties.toArray(new PropertyCreationData[newProperties.size()]),
75 newChildren.toArray(new ChildCreationData[newChildren.size()]));
78 public static Modification buildChildren(Collection<String> removedChildren, Collection<ChildCreationData> newChildren) {
79 return new Modification(
80 new String[0], removedChildren.toArray(new String[removedChildren.size()]),
81 new PropertyCreationData[0], newChildren.toArray(new ChildCreationData[newChildren.size()]));
84 public static Modification addChildren(Collection<ChildCreationData> newChildren) {
85 return new Modification(
86 new String[0], new String[0],
87 new PropertyCreationData[0], newChildren.toArray(new ChildCreationData[newChildren.size()]));
90 public static Modification addChild(ChildCreationData child) {
91 return addChildren(Collections.singletonList(child));
94 public static Modification removeChildren(Collection<String> removedChildren) {
95 return new Modification(
96 new String[0], removedChildren.toArray(new String[removedChildren.size()]),
97 new PropertyCreationData[0], new ChildCreationData[0]);
100 public static Modification removeChild(String child) {
101 return removeChildren(Collections.singletonList(child));
104 public static Modification addProperties(Collection<PropertyCreationData> newProperties) {
105 return new Modification(
106 new String[0], new String[0],
107 newProperties.toArray(new PropertyCreationData[newProperties.size()]), new ChildCreationData[0]);
110 public static Modification addProperty(PropertyCreationData property) {
111 return addProperties(Collections.singletonList(property));
116 void apply(WriteGraph graph, Modification modification) throws DatabaseException;
118 // Variable createChild(WriteGraph graph, String name, Object content) throws DatabaseException;
119 // Variable createProperty(WriteGraph graph, String name) throws DatabaseException;
120 // Variable createVariable(WriteGraph graph, String rvi) throws DatabaseException;
122 // Variable removeChild(WriteGraph graph, String name) throws DatabaseException;