User Tools

Site Tools


dev-guide:add-object-as-node-production

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
dev-guide:add-object-as-node-production [2025/01/08 11:50] – created gaetandev-guide:add-object-as-node-production [2025/01/08 16:33] (current) – [ProducingNode interface] gaetan
Line 1: Line 1:
 ====== Includes object in production ====== ====== Includes object in production ======
  
-XL rules can include a [[:tutorials:common_rewriting_rules|Production]], in which some Node and Edges are created (and possibly added - depends on the rule).+XL rules can include a [[:tutorials:common_rewriting_rules|production statement]], in which some Node and Edges are created (and possibly added - depends on the rule). 
 + 
 +The production statement is managed by a [[https://javadoc.grogra.de/xl.impl/de/grogra/xl/impl/base/Producer.html|Producer]] object.  
 +By default, RGG files use a [[https://javadoc.grogra.de/xl.impl/de/grogra/xl/impl/base/Producer.html|RGGProducer]]. 
 + 
 +===== RGG producer ===== 
 + 
 +By default, all java objects that extends [[https://javadoc.grogra.de/graph/de/grogra/graph/impl/Node.html|Node]] can be added in a production statement. As ''module'' in RGG are extending Node by default, they can be added in production. 
 + 
 +Java objects that do not extend Node, can still be added in a production statement, but they will be wrapped in a [[https://javadoc.grogra.de/rgg/de/grogra/rgg/ObjectNode.html|ObjectNode]] object. 
 + 
 +It is possible to provide a specific way to add a java object in the graph in a production statement using either: toNode() method, or by implementing the 
 +[[https://javadoc.grogra.de/imp/de/grogra/imp/objects/ProducingNode.html|ProducingNode]] interface. 
 + 
 +==== toNode method ==== 
 + 
 +The RGGProducer is testing if a java object that do not extend Node have a  
 +<code java>  
 +public Node toNode() { // return a Node } 
 +</code> 
 +method. 
 + 
 +If it is the case it uses that method to create the Node to be added in the graph. The Node can have edges toward other Nodes (in the graph or not). Additional nodes will be set persistent. 
 + 
 +==== ProducingNode interface ==== 
 + 
 +The toNode() method works well but requires a class. When working on bigger projects you might want to create interfaces that includes the knowledge that all implementation classes should have a "toNode()" method. Such classes or interface should implements/ extends [[https://javadoc.grogra.de/imp/de/grogra/imp/objects/ProducingNode.html|ProducingNode]]. 
 +Then, instead of using "toNode()", which is taken, the classes needs to implements 
 + 
 +<code java> 
 +public Node produceNode() { //return a Node } 
 +</code>
  
-===== P 
dev-guide/add-object-as-node-production.1736333419.txt.gz · Last modified: 2025/01/08 11:50 by gaetan