java.lang.Object
org.praxislive.project.GraphModel
Model for graph and subgraph scripts, encompassing the element tree and
related information.
A graph model can be parsed from a script (eg. contents of .pxr / .pxg file),
or created from the serialization data returned from
SerializableProtocol. A graph model can also be written back out to a
script for execution or saving to a file.
A graph model, and the underlying tree, are immutable. Transformative methods return a new model instance.
-
Method Summary
Modifier and TypeMethodDescriptioncontext()Access the optional context (eg. working dir) for resolving relative file values.booleanstatic GraphModelfromSerializedComponent(String componentID, org.praxislive.core.types.PMap data) Create a graph model from the serialization data of a single component.static GraphModelfromSerializedRoot(String rootID, org.praxislive.core.types.PMap data) Create a graph model from the serialization data of a complete root.static GraphModelfromSerializedSubgraph(org.praxislive.core.types.PMap data) Create a graph model from the serialization data of a container.static GraphModelfromSerializedSubgraph(org.praxislive.core.types.PMap data, Predicate<String> filter) Create a graph model from the serialization data of a container.inthashCode()static GraphModelof(GraphElement.Root root) Create a graph model of the provided root element.static GraphModelof(GraphElement.Root root, URI context) Create a graph model of the provided root element and context.static GraphModelParse the given graph script into a graph model.static GraphModelParse the given graph script into a graph model.static GraphModelparseSubgraph(String graph) Parse the given subgraph script into a graph model.static GraphModelparseSubgraph(URI context, String graph) Parse the given subgraph script into a graph model.root()Access the root of the element tree.toString()withContext(URI context) Create a new graph model based on this one, with a different context.withRename(String id) Create a new graph model based on this one, with a renamed root.withTransform(Consumer<GraphBuilder.Root> transform) Create a new graph model based on this one after applying the provided transform function.voidwrite(Appendable target) Write the model as a script to the given target.Write the graph model to a String.
-
Method Details
-
root
Access the root of the element tree. For a subgraph, the root will be synthetic.- Returns:
- root element
-
context
Access the optional context (eg. working dir) for resolving relative file values.- Returns:
- optional context
-
withContext
Create a new graph model based on this one, with a different context. The context is used to relativize resources when writing. Usenullto create a model without context.- Parameters:
context- new resource context- Returns:
- new graph model
-
withRename
Create a new graph model based on this one, with a renamed root. All other elements are kept the same. This method will throw an exception if called on a (subgraph) model with a synthetic root.- Parameters:
id- new root ID- Returns:
- new graph model
-
withTransform
Create a new graph model based on this one after applying the provided transform function. The builder passed into the transform will be pre-configured with all the elements of this model.- Parameters:
transform- transforming builder consumer- Returns:
- new graph model
-
write
Write the model as a script to the given target.- Parameters:
target- write destination- Throws:
IOException
-
writeToString
Write the graph model to a String. This is shorthand for passing in aStringBuildertowrite(java.lang.Appendable).The output of this method is suitable for parsing back into a model, as distinct from the output of
toString().- Returns:
- model as script
-
equals
-
hashCode
public int hashCode() -
toString
-
fromSerializedComponent
public static GraphModel fromSerializedComponent(String componentID, org.praxislive.core.types.PMap data) Create a graph model from the serialization data of a single component. The data should be in the format specified bySerializableProtocol. The graph model will consist of a synthetic root with a single child component element with the given ID and data.- Parameters:
componentID- id of the componentdata- serialization data- Returns:
- created graph model
-
fromSerializedRoot
Create a graph model from the serialization data of a complete root. The data should be in the format specified bySerializableProtocol.- Parameters:
rootID- if of the rootdata- serialization data- Returns:
- created graph model
-
fromSerializedSubgraph
Create a graph model from the serialization data of a container. The data should be in the format specified bySerializableProtocol. The graph model will consist of a synthetic root with all the children and connections of the container. Properties of the container itself will be ignored.- Parameters:
data- container serialization data- Returns:
- created graph model
-
fromSerializedSubgraph
public static GraphModel fromSerializedSubgraph(org.praxislive.core.types.PMap data, Predicate<String> filter) Create a graph model from the serialization data of a container. The data should be in the format specified bySerializableProtocol. The graph model will consist of a synthetic root with all the children of the container that pass the given child ID filter. Connections will be filtered to those between included components. Properties of the container itself will be ignored.- Parameters:
data- container serialization datafilter- child ID filter- Returns:
- created graph model
-
of
Create a graph model of the provided root element.- Parameters:
root- root element- Returns:
- created graph model
-
of
Create a graph model of the provided root element and context.- Parameters:
root- root elementcontext- resource context- Returns:
- created graph model
-
parse
Parse the given graph script into a graph model. The script must be a valid full root graph.- Parameters:
graph- graph script- Returns:
- created graph model
- Throws:
ParseException- if the graph is invalid
-
parse
Parse the given graph script into a graph model. Relative resources will be resolved against the provided context. The script must be a full root graph.- Parameters:
context- resource contextgraph- graph script- Returns:
- created graph model
- Throws:
ParseException- if the graph is invalid
-
parseSubgraph
Parse the given subgraph script into a graph model. The script must be a valid subgraph script.- Parameters:
graph- subgraph script- Returns:
- created graph model
- Throws:
ParseException- if the subgraph is invalid
-
parseSubgraph
Parse the given subgraph script into a graph model. Relative resources will be resolved against the provided context. The script must be a valid subgraph script.- Parameters:
context- resource contextgraph- subgraph script- Returns:
- created graph model
- Throws:
ParseException- if the subgraph is invalid
-