1 /*******************************************************************************
2 * Copyright (c) 2013 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 * Semantum Oy - initial API and implementation
12 *******************************************************************************/
13 package org.simantics.simulator.variable;
15 import java.util.Collections;
16 import java.util.List;
19 import org.simantics.databoard.binding.Binding;
20 import org.simantics.databoard.binding.error.BindingException;
21 import org.simantics.databoard.binding.mutable.Variant;
22 import org.simantics.databoard.type.Datatype;
23 import org.simantics.simulator.variable.exceptions.InvalidPathException;
24 import org.simantics.simulator.variable.exceptions.NoSuchNodeException;
25 import org.simantics.simulator.variable.exceptions.NoValueException;
26 import org.simantics.simulator.variable.exceptions.NodeManagerException;
27 import org.simantics.simulator.variable.exceptions.NotInRealmException;
30 * {@code NodeManager} provides access to a local simulator
31 * or a similar entity. Because simulation may be ongoing, access
32 * is restricted to a certain realm.
34 * @author Hannu Niemistö
35 * @author Antti Villberg
37 public interface NodeManager<Node> {
39 // --- Do not require a realm access ---
42 * The realm of the node manager. Almost all other methods
43 * of this class must be called inside this realm.
48 * Returns the name of the node. This method does not require
49 * that caller is in realm.
51 String getName(Node node);
54 * Adds a listener to a certain node. The new listener is called as
55 * soon as possible (for example before simulator takes the next simulation
56 * step). After the first call, it is called always the node value
57 * or structure may have changed. This can be called outside of the realm.
59 void addNodeListener(Node node, Runnable listener);
62 * Removes previously added listener. This can be called outside of
65 void removeNodeListener(Node node, Runnable listener);
67 // --- Require a realm access ---
70 * @return {@code null} if node cannot be found, otherwise a node with the given path
71 * @throws InvalidPathException if the path is not in a valid path format
72 * @throws NotInRealmException if not synchronized to the realm
74 Node getNode(String path) throws NodeManagerException;
76 * @return {@code null} if node cannot be found, otherwise a child node with the given name
77 * @throws NotInRealmException if not synchronized to the realm
79 Node getChild(Node node, String name) throws NodeManagerException;
80 Node getProperty(Node node, String name) throws NodeManagerException;
81 List<String> getChildNames(Node node) throws NodeManagerException;
82 List<String> getPropertyNames(Node node) throws NodeManagerException;
83 List<Node> getChildren(Node node) throws NodeManagerException;
84 List<Node> getProperties(Node node) throws NodeManagerException;
87 * @throws NoValueException if the node has no value (and therefore no datatype)
88 * @throws NotInRealmException if not synchronized to the realm
90 Datatype getDatatype(Node node) throws NodeManagerException;
92 * @throws NoValueException if the node has no value
93 * @throws BindingException if the value can not be bound to the given binding
94 * @throws NotInRealmException if not synchronized to the realm
96 Object getValue(Node node, Binding binding) throws NodeManagerException, BindingException;
98 * A variant of {@link #getValue(Object, Binding)} that uses
99 * a binding chosen by the node manager.
101 Variant getValue(Node node) throws NodeManagerException;
103 * @throws NoSuchNodeException if the property does not exist
104 * @throws NoValueException if the property has no value
105 * @throws NotInRealmException if not synchronized to the realm
106 * @throws BindingException if the value can not be bound to the given binding
108 Object getValue(Node node, String property, Binding binding) throws NodeManagerException, BindingException;
110 * A variant of {@link #getValue(Object, String, Binding)} that uses
111 * a binding chosen by the node manager.
113 Variant getValue(Node node, String property) throws NodeManagerException;
116 * @throws BindingException if the value can not be bound to the given binding
117 * @throws NoValueException if the property has no value that could be assigned
118 * @throws NotInRealmException if not synchronized to the realm
120 void setValue(Node node, Object value, Binding binding) throws NodeManagerException, BindingException;
122 * @throws BindingException if the value can not be bound to the given binding
123 * @throws NoSuchNodeException if the property does not exist
124 * @throws NoValueException if the property has no value that could be assigned
125 * @throws NotInRealmException if not synchronized to the realm
127 void setValue(Node node, String property, Object value, Binding binding) throws NodeManagerException, BindingException;
130 * Asks the full URI of a property node. The parent of the property is also given as a parameter.
131 * This is an optional method, NodeManager does not have to implement it for all nodes.
133 String getPropertyURI(Node parent, Node property);
136 * Asks for the classifications of a property node.
137 * This is an optional method, NodeManager does not have to implement it for all nodes.
138 * A default implementation should just return {@link Collections#emptySet()}.
139 * Classifications can be any strings, however a recommended interpretation is to return
140 * the URIs of the primary ontological types that this node corresponds to.
142 * @param node the node to classify
143 * @return classifications of the node, empty set if the node has no classifications
145 Set<String> getClassifications(Node node) throws NodeManagerException;