]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.simulator.variable/src/org/simantics/simulator/variable/NodeManager.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.simulator.variable / src / org / simantics / simulator / variable / NodeManager.java
diff --git a/bundles/org.simantics.simulator.variable/src/org/simantics/simulator/variable/NodeManager.java b/bundles/org.simantics.simulator.variable/src/org/simantics/simulator/variable/NodeManager.java
new file mode 100644 (file)
index 0000000..2b9b2ef
--- /dev/null
@@ -0,0 +1,147 @@
+/*******************************************************************************\r
+ * Copyright (c) 2013 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
+ *     VTT Technical Research Centre of Finland - initial API and implementation\r
+ *     Semantum Oy - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.simulator.variable;\r
+\r
+import java.util.Collections;\r
+import java.util.List;\r
+import java.util.Set;\r
+\r
+import org.simantics.databoard.binding.Binding;\r
+import org.simantics.databoard.binding.error.BindingException;\r
+import org.simantics.databoard.binding.mutable.Variant;\r
+import org.simantics.databoard.type.Datatype;\r
+import org.simantics.simulator.variable.exceptions.InvalidPathException;\r
+import org.simantics.simulator.variable.exceptions.NoSuchNodeException;\r
+import org.simantics.simulator.variable.exceptions.NoValueException;\r
+import org.simantics.simulator.variable.exceptions.NodeManagerException;\r
+import org.simantics.simulator.variable.exceptions.NotInRealmException;\r
+\r
+/**\r
+ * {@code NodeManager} provides access to a local simulator\r
+ * or a similar entity. Because simulation may be ongoing, access\r
+ * is restricted to a certain realm.\r
+ * \r
+ * @author Hannu Niemistö\r
+ * @author Antti Villberg\r
+ */\r
+public interface NodeManager<Node> {\r
+\r
+       // --- Do not require a realm access ---\r
+       \r
+       /**\r
+        * The realm of the node manager. Almost all other methods\r
+        * of this class must be called inside this realm.\r
+        */\r
+       Realm getRealm();\r
+\r
+       /**\r
+        * Returns the name of the node. This method does not require \r
+        * that caller is in realm.\r
+        */\r
+       String getName(Node node);\r
+\r
+       /**\r
+        * Adds a listener to a certain node. The new listener is called as\r
+        * soon as possible (for example before simulator takes the next simulation\r
+        * step). After the first call, it is called always the node value \r
+        * or structure may have changed. This can be called outside of the realm.\r
+        */\r
+       void addNodeListener(Node node, Runnable listener);\r
+       \r
+       /**\r
+        * Removes previously added listener. This can be called outside of\r
+        * the realm.\r
+        */\r
+       void removeNodeListener(Node node, Runnable listener);\r
+       \r
+       // --- Require a realm access ---\r
+       \r
+       /**\r
+        * @return {@code null} if node cannot be found, otherwise a node with the given path\r
+        * @throws InvalidPathException if the path is not in a valid path format\r
+        * @throws NotInRealmException if not synchronized to the realm\r
+        */\r
+       Node getNode(String path) throws NodeManagerException;  \r
+       /**\r
+        * @return {@code null} if node cannot be found, otherwise a child node with the given name\r
+        * @throws NotInRealmException if not synchronized to the realm\r
+        */\r
+       Node getChild(Node node, String name) throws NodeManagerException;\r
+       Node getProperty(Node node, String name) throws NodeManagerException;\r
+       List<String> getChildNames(Node node) throws NodeManagerException;\r
+       List<String> getPropertyNames(Node node) throws NodeManagerException;\r
+       List<Node> getChildren(Node node) throws NodeManagerException;\r
+       List<Node> getProperties(Node node) throws NodeManagerException;\r
+\r
+       /**\r
+        * @throws NoValueException if the node has no value (and therefore no datatype)\r
+        * @throws NotInRealmException if not synchronized to the realm\r
+        */\r
+       Datatype getDatatype(Node node) throws NodeManagerException;\r
+       /**\r
+        * @throws NoValueException if the node has no value\r
+        * @throws BindingException if the value can not be bound to the given binding\r
+        * @throws NotInRealmException if not synchronized to the realm\r
+        */\r
+       Object getValue(Node node, Binding binding) throws NodeManagerException, BindingException;\r
+       /**\r
+        * A variant of {@link #getValue(Object, Binding)} that uses\r
+        * a binding chosen by the node manager.\r
+        */\r
+       Variant getValue(Node node) throws NodeManagerException;\r
+       /**\r
+        * @throws NoSuchNodeException if the property does not exist\r
+        * @throws NoValueException if the property has no value\r
+        * @throws NotInRealmException if not synchronized to the realm\r
+        * @throws BindingException if the value can not be bound to the given binding\r
+        */\r
+       Object getValue(Node node, String property, Binding binding) throws NodeManagerException, BindingException;\r
+       /**\r
+        * A variant of {@link #getValue(Object, String, Binding)} that uses\r
+        * a binding chosen by the node manager.\r
+        */\r
+       Variant getValue(Node node, String property) throws NodeManagerException;       \r
+       \r
+       /**\r
+        * @throws BindingException if the value can not be bound to the given binding\r
+        * @throws NoValueException if the property has no value that could be assigned\r
+        * @throws NotInRealmException if not synchronized to the realm\r
+        */\r
+       void setValue(Node node, Object value, Binding binding) throws NodeManagerException, BindingException;\r
+       /**\r
+        * @throws BindingException if the value can not be bound to the given binding\r
+        * @throws NoSuchNodeException if the property does not exist\r
+        * @throws NoValueException if the property has no value that could be assigned\r
+        * @throws NotInRealmException if not synchronized to the realm\r
+        */\r
+       void setValue(Node node, String property, Object value, Binding binding) throws NodeManagerException, BindingException;\r
+\r
+       /**\r
+        * Asks the full URI of a property node. The parent of the property is also given as a parameter.\r
+        * This is an optional method, NodeManager does not have to implement it for all nodes.\r
+        */\r
+    String getPropertyURI(Node parent, Node property);\r
+\r
+       /**\r
+        * Asks for the classifications of a property node.\r
+        * This is an optional method, NodeManager does not have to implement it for all nodes.\r
+        * A default implementation should just return {@link Collections#emptySet()}.\r
+        * Classifications can be any strings, however a recommended interpretation is to return\r
+        * the URIs of the primary ontological types that this node corresponds to.\r
+        * \r
+        * @param node the node to classify\r
+        * @return classifications of the node, empty set if the node has no classifications\r
+        */\r
+       Set<String> getClassifications(Node node) throws NodeManagerException;\r
+\r
+}
\ No newline at end of file