- 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 implementingSharedGraphNodes.This implementation is structurally equivalent to
AbstractDataObjectbut adds aScopeto the method signatures.
-
-
Constructor Summary
Constructors Constructor Description AbstractSharedGraphNode()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intid()The ID of this node in it's defaultScope.protected voidinitId(int id)Assigns the given ID.ObjectreadElement(Scope scope, JsonReader in, String field)Read an element of the repeated field with the given name.voidreadField(Scope scope, JsonReader in, String field)Reads the given field from the given input.voidreadFields(Scope scope, JsonReader in)Reads all fields of this instance from the given input.SharedGraphNoderegisterListener(Listener l)Attaches the givenListenerto this object.StringtoString()SharedGraphNodeunregisterListener(Listener l)Removes the givenListenerfrom this object.voidwriteData(Scope scope, JsonWriter out, int id)Writes the complete data of this node including type and ID to the given writer.voidwriteElement(Scope scope, JsonWriter out, String field, Object element)Writes the given element value that is compatible with the repeated field with the given name to the given output.protected voidwriteFields(Scope scope, JsonWriter out)Writes all fields of this instance to the given output.voidwriteFieldValue(Scope scope, JsonWriter out, String field)Writes a single value that is currently assigned to the field with the given name to the given writer.voidwriteTo(Scope scope, JsonWriter out)Writes this node to the given writer.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface de.haumacher.msgbuf.data.ReflectiveDataObject
get, jsonType, properties, set
-
-
-
-
Field Detail
-
_listener
protected Listener _listener
-
-
Method Detail
-
id
public final int id()
The ID of this node in it's defaultScope.
-
initId
protected void initId(int id)
Assigns the given ID.- See Also:
id()
-
registerListener
public SharedGraphNode registerListener(Listener l)
Description copied from interface:ObservableAttaches the givenListenerto this object.If the given
Listeneris already attached, it is not attached again.- Specified by:
registerListenerin interfaceObservable- Parameters:
l- TheListenerto attach.- Returns:
- This object for call chaining.
-
unregisterListener
public SharedGraphNode unregisterListener(Listener l)
Description copied from interface:ObservableRemoves the givenListenerfrom this object.- Specified by:
unregisterListenerin interfaceObservable- Parameters:
l- TheListenerto remove.- Returns:
- This object for call chaining.
-
writeTo
public final void writeTo(Scope scope, JsonWriter out) throws IOException
Description copied from interface:SharedGraphNodeWrites 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 theScope. Otherwise, thecomplete objectdata is transmitted.- Specified by:
writeToin interfaceSharedGraphNode- Parameters:
scope- The shared graphScopethat 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:SharedGraphNodeWrites the complete data of this node including type and ID to the given writer.Note: This method should only be called from a
Scope'sScope.writeRefOrData(JsonWriter, SharedGraphNode)if a fresh ID was assigned.- Specified by:
writeDatain interfaceSharedGraphNode- Parameters:
scope- The shared graphScopethat 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 graphScope.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:SharedGraphNodeReads all fields of this instance from the given input.- Specified by:
readFieldsin interfaceSharedGraphNode- Parameters:
scope- The shared graphScopethat 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:SharedGraphNodeReads the given field from the given input.- Specified by:
readFieldin interfaceSharedGraphNode- Parameters:
scope- The shared graphScopethat 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:SharedGraphNodeWrites the given element value that is compatible with the repeated field with the given name to the given output.- Specified by:
writeElementin interfaceSharedGraphNode- Parameters:
scope- The shared graphScopethat 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:SharedGraphNodeRead an element of the repeated field with the given name.- Specified by:
readElementin interfaceSharedGraphNode- Parameters:
scope- The shared graphScopethat 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:SharedGraphNodeWrites a single value that is currently assigned to the field with the given name to the given writer.- Specified by:
writeFieldValuein interfaceSharedGraphNode- Parameters:
scope- The shared graphScopethat handles object references.out- The writer to write to.field- The name of the field whose value should be written.- Throws:
IOException
-
-