1 It is possible to define procedural values in the graph and compute their values using graph interface.
\r
3 Currently the methods for computing the values are:
\r
4 * <T> T getRelatedValue2(Resource subject, Resource relation) throws DatabaseException;
\r
5 * <T> T getPossibleRelatedValue2(Resource subject, Resource relation) throws DatabaseException;
\r
6 * <T> T getRelatedValue2(Resource subject, Resource relation, Object context) throws DatabaseException;
\r
7 * <T> T getPossibleRelatedValue2(Resource subject, Resource relation, Object context) throws DatabaseException;
\r
8 * <T> T getRelatedValue2(Resource subject, Resource relation, Binding binding) throws DatabaseException;
\r
9 * <T> T getPossibleRelatedValue2(Resource subject, Resource relation, Binding binding) throws DatabaseException;
\r
10 * <T> T getRelatedValue2(Resource subject, Resource relation, Object context, Binding binding) throws DatabaseException;
\r
11 * <T> T getPossibleRelatedValue2(Resource subject, Resource relation, Object context, Binding binding) throws DatabaseException;
\r
13 These methods work like getRelatedValue and getPossibleRelatedValue -methods. They follow the given relation from the given subject and then determine the value based on the resource found. If the resource is a literal, then they work exactly like getRelatedValue and getPossibleRelatedValue. They however extend the old functionality in two ways:
\r
14 * If the found resource is an instance of ExternalValue, then the URI of the resource is used to find a value that is declared using extensions and Java annotations.
\r
15 * If the found resource is an instance of Value, the mechanism first finds the property ConvertsToValueWith of the value and uses it compute the value.
\r
16 These two mechanisms are detailed below.
\r
20 External values are resources in the graph with type ExternalValue. They must have URIs. Let's consider for example
\r
21 SEL.Functions.inputModifier : L0.ExternalValue
\r
22 defined in SelectionView -ontology.
\r
24 The definitions of the values are declared in the extension point `org.simantics.scl.reflection.binding` like this
\r
27 <extension point="org.simantics.scl.reflection.binding">
\r
28 <namespace path="http://www.simantics.org/SelectionView-0.0/Functions">
\r
29 <externalClass className="org.simantics.db.Resource"/>
\r
30 <externalClass className="org.simantics.db.ReadGraph"/>
\r
31 <externalClass className="org.simantics.db.WriteGraph"/>
\r
32 <externalClass className="org.simantics.db.layer0.variable.Variable"/>
\r
33 <class className="org.simantics.selectionview.function.All"/>
\r
38 The value itself is defined as:
\r
41 @SCLValue(type = "WriteGraph -> Variable -> a -> b -> String")
\r
42 public static String inputModifier(WriteGraph graph, Variable variable, Object value, Object _binding) throws DatabaseException {
\r
48 Any static method or field can be declared an external value with `@SCLValue` annotation. The SCL -type of the value is given as an attribute to the annotation. By default the method name and resource name are matched, but the method name can be overridden in the annotation with name attribute.
\r
50 ## Contextual values
\r
52 External values can be used to define complex constants, in particular functions. Contextual values extend the functionality so that the value may depend on the other properties of the original subject resource that was used for finding the value resource. In some cases, even more needs to be known about the context of the computation than just a resource. Therefore some of the `getRelatedValue2` -methods take a context as a parameter. If it is not given, the default context is the subject resource.
\r
54 A contextual value is defined as a resource with type `Value` and properties `ConvertsToValueWith`. For example:
\r
58 L0.HasDescription """Represents a list of resources that may contain repetitions."""
\r
59 L0.HasValueType "[Resource]"
\r
60 @L0.assert L0.ConvertsToValueWith L0.Functions.listResources : L0.ExternalValue
\r
63 The conversion function must have type
\r
65 ReadGraph => Resource -> Context -> Result
\r
67 The second parameter is the resource of the value itself (in this case the linked list) and the context type can be any type. Result type must be the type annotated with `HasValueType`.
\r
71 Types of the values must be annotated with relation `HasValueType`. The type is an SCL type in a string format. A relation may require that its range has a certain value type using `RequiresValueType` -property.
\r