Class AbstractSharedGraphNode

java.lang.Object
de.haumacher.msgbuf.graph.AbstractSharedGraphNode
All Implemented Interfaces:
ReflectiveDataObject, SharedGraphNode, Observable

public abstract class AbstractSharedGraphNode extends Object implements SharedGraphNode
Base class for generated code implementing SharedGraphNodes.

This implementation is structurally equivalent to AbstractDataObject but adds a Scope to the method signatures.

  • Field Details

    • _listener

      protected Listener _listener
  • Constructor Details

    • AbstractSharedGraphNode

      public AbstractSharedGraphNode()
  • Method Details

    • id

      public final int id()
      The ID of this node in it's default Scope.
    • initId

      protected void initId(int id)
      Assigns the given ID.
      See Also:
    • registerListener

      public SharedGraphNode registerListener(Listener l)
      Description copied from interface: Observable
      Attaches the given Listener to this object.

      If the given Listener is already attached, it is not attached again.

      Specified by:
      registerListener in interface Observable
      Parameters:
      l - The Listener to attach.
      Returns:
      This object for call chaining.
    • unregisterListener

      public SharedGraphNode unregisterListener(Listener l)
      Description copied from interface: Observable
      Removes the given Listener from this object.
      Specified by:
      unregisterListener in interface Observable
      Parameters:
      l - The Listener to remove.
      Returns:
      This object for call chaining.
    • writeTo

      public final void writeTo(Scope scope, JsonWriter out) throws IOException
      Description copied from interface: SharedGraphNode
      Writes this node to the given writer.

      Depending on the given Scope, only a reference to this object is transmitted, if this node is already known by the Scope. Otherwise, the complete object data is transmitted.

      Specified by:
      writeTo in interface SharedGraphNode
      Parameters:
      scope - The shared graph Scope that handles object references.
      out - The writer to write to.
      Throws:
      IOException
    • writeData

      public final void writeData(Scope scope, JsonWriter out, int id) throws IOException
      Description copied from interface: SharedGraphNode
      Writes the complete data of this node including type and ID to the given writer.

      Note: This method should only be called from a Scope's Scope.writeRefOrData(JsonWriter, SharedGraphNode) if a fresh ID was assigned.

      Specified by:
      writeData in interface SharedGraphNode
      Parameters:
      scope - The shared graph Scope that handles object references.
      out - The writer to write to.
      id - The ID to use for this node.
      Throws:
      IOException
    • writeFields

      protected void writeFields(Scope scope, JsonWriter out) throws IOException
      Writes all fields of this instance to the given output.
      Parameters:
      scope - The shared graph Scope.
      out - The writer to write to.
      Throws:
      IOException - If writing fails.
    • readFields

      public final void readFields(Scope scope, JsonReader in) throws IOException
      Description copied from interface: SharedGraphNode
      Reads all fields of this instance from the given input.
      Specified by:
      readFields in interface SharedGraphNode
      Parameters:
      scope - The shared graph Scope that handles object references.
      in - The reader to take the input from.
      Throws:
      IOException
    • readField

      public void readField(Scope scope, JsonReader in, String field) throws IOException
      Description copied from interface: SharedGraphNode
      Reads the given field from the given input.
      Specified by:
      readField in interface SharedGraphNode
      Parameters:
      scope - The shared graph Scope that handles object references.
      in - The reader to take the value from.
      field - The name of the field whose value should be read.
      Throws:
      IOException
    • writeElement

      public void writeElement(Scope scope, JsonWriter out, String field, Object element) throws IOException
      Description copied from interface: SharedGraphNode
      Writes the given element value that is compatible with the repeated field with the given name to the given output.
      Specified by:
      writeElement in interface SharedGraphNode
      Parameters:
      scope - The shared graph Scope that handles object references.
      out - The writer to write to.
      field - The name of the field whose element should be written.
      element - The element value of the given field.
      Throws:
      IOException
    • readElement

      public Object readElement(Scope scope, JsonReader in, String field) throws IOException
      Description copied from interface: SharedGraphNode
      Read an element of the repeated field with the given name.
      Specified by:
      readElement in interface SharedGraphNode
      Parameters:
      scope - The shared graph Scope that handles object references.
      in - The reader to take the value from.
      field - The repeated field where an element value should be read for.
      Returns:
      The read element value.
      Throws:
      IOException
    • writeFieldValue

      public void writeFieldValue(Scope scope, JsonWriter out, String field) throws IOException
      Description copied from interface: SharedGraphNode
      Writes a single value that is currently assigned to the field with the given name to the given writer.
      Specified by:
      writeFieldValue in interface SharedGraphNode
      Parameters:
      scope - The shared graph Scope that handles object references.
      out - The writer to write to.
      field - The name of the field whose value should be written.
      Throws:
      IOException
    • toString

      public String toString()
      Overrides:
      toString in class Object