1 /*******************************************************************************
\r
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
\r
3 * in Industry THTH ry.
\r
4 * All rights reserved. This program and the accompanying materials
\r
5 * are made available under the terms of the Eclipse Public License v1.0
\r
6 * which accompanies this distribution, and is available at
\r
7 * http://www.eclipse.org/legal/epl-v10.html
\r
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.db.layer0.variable;
\r
14 import java.util.Collection;
\r
15 import java.util.Collections;
\r
17 import org.simantics.databoard.binding.mutable.Variant;
\r
18 import org.simantics.db.WriteGraph;
\r
19 import org.simantics.db.exception.DatabaseException;
\r
22 * Obtained with Variable.adapt
\r
24 public interface VariableSpaceManipulator {
\r
26 public class PropertyCreationData {
\r
28 public Variant value;
\r
29 public PropertyCreationData(String name, Variant value) {
\r
34 public static PropertyCreationData build(String name, Object value) {
\r
35 return new PropertyCreationData(name, Variant.ofInstance(value));
\r
40 public class ChildCreationData {
\r
43 public PropertyCreationData[] properties;
\r
44 public ChildCreationData(String name, String type, PropertyCreationData[] properties) {
\r
47 this.properties = properties;
\r
50 public static ChildCreationData build(String name, String type, PropertyCreationData ... properties) {
\r
51 return new ChildCreationData(name, type, properties);
\r
56 public class Modification {
\r
58 public String[] removedProperties;
\r
59 public String[] removedChildren;
\r
60 public PropertyCreationData[] newProperties;
\r
61 public ChildCreationData[] newChildren;
\r
63 public Modification(String[] removedProperties, String[] removedChildren, PropertyCreationData[] newProperties, ChildCreationData[] newChildren) {
\r
64 this.removedProperties = removedProperties;
\r
65 this.removedChildren = removedChildren;
\r
66 this.newProperties = newProperties;
\r
67 this.newChildren = newChildren;
\r
70 public static Modification build(Collection<String> removedProperties, Collection<String> removedChildren, Collection<PropertyCreationData> newProperties, Collection<ChildCreationData> newChildren) {
\r
71 return new Modification(
\r
72 removedProperties.toArray(new String[removedProperties.size()]),
\r
73 removedChildren.toArray(new String[removedChildren.size()]),
\r
74 newProperties.toArray(new PropertyCreationData[newProperties.size()]),
\r
75 newChildren.toArray(new ChildCreationData[newChildren.size()]));
\r
78 public static Modification buildChildren(Collection<String> removedChildren, Collection<ChildCreationData> newChildren) {
\r
79 return new Modification(
\r
80 new String[0], removedChildren.toArray(new String[removedChildren.size()]),
\r
81 new PropertyCreationData[0], newChildren.toArray(new ChildCreationData[newChildren.size()]));
\r
84 public static Modification addChildren(Collection<ChildCreationData> newChildren) {
\r
85 return new Modification(
\r
86 new String[0], new String[0],
\r
87 new PropertyCreationData[0], newChildren.toArray(new ChildCreationData[newChildren.size()]));
\r
90 public static Modification addChild(ChildCreationData child) {
\r
91 return addChildren(Collections.singletonList(child));
\r
94 public static Modification removeChildren(Collection<String> removedChildren) {
\r
95 return new Modification(
\r
96 new String[0], removedChildren.toArray(new String[removedChildren.size()]),
\r
97 new PropertyCreationData[0], new ChildCreationData[0]);
\r
100 public static Modification removeChild(String child) {
\r
101 return removeChildren(Collections.singletonList(child));
\r
104 public static Modification addProperties(Collection<PropertyCreationData> newProperties) {
\r
105 return new Modification(
\r
106 new String[0], new String[0],
\r
107 newProperties.toArray(new PropertyCreationData[newProperties.size()]), new ChildCreationData[0]);
\r
110 public static Modification addProperty(PropertyCreationData property) {
\r
111 return addProperties(Collections.singletonList(property));
\r
116 void apply(WriteGraph graph, Modification modification) throws DatabaseException;
\r
118 // Variable createChild(WriteGraph graph, String name, Object content) throws DatabaseException;
\r
119 // Variable createProperty(WriteGraph graph, String name) throws DatabaseException;
\r
120 // Variable createVariable(WriteGraph graph, String rvi) throws DatabaseException;
\r
122 // Variable removeChild(WriteGraph graph, String name) throws DatabaseException;
\r