- java.lang.Object
-
- de.haumacher.msgbuf.data.AbstractDataObject
-
- de.haumacher.msgbuf.graph.cmd.Command
-
- All Implemented Interfaces:
BinaryDataObject,DataObject,ReflectiveDataObject,Observable
- Direct Known Subclasses:
ListUpdate,SetProperty
public abstract class Command extends AbstractDataObject implements BinaryDataObject, Observable
Base class of commands that encode changes to data objects.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classCommand.TypeKindType codes for theCommandhierarchy.static interfaceCommand.Visitor<R,A,E extends Throwable>Visitor interface for theCommandhierarchy.
-
Field Summary
Fields Modifier and Type Field Description protected Listener_listenerstatic StringIDstatic intID__IDIdentifier for the propertygetId()in binary format.static StringNODEstatic StringPROPERTYstatic intPROPERTY__IDIdentifier for the propertygetProperty()in binary format.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description Objectget(String field)Retrieves value of the field with the given name.intgetId()The network ID of the changed object.SharedGraphNodegetNode()Cache for the reference to the changed graph node itself.StringgetProperty()The name of the changed property of the object with the givengetId().booleanhasNode()Checks, whethergetNode()has a value.abstract Command.TypeKindkind()The type code of this instance.List<String>properties()All properties that are supported by this object.static CommandreadCommand(DataReader in)Reads a new instance from the given reader.static CommandreadCommand(JsonReader in)Reads a new instance from the given reader.protected voidreadField(DataReader in, int field)Consumes the value for the field with the given ID and assigns its value.protected voidreadField(JsonReader in, String field)Reads the given field from the given input.CommandregisterListener(Listener l)Attaches the givenListenerto this object.voidset(String field, Object value)Sets the value of the property with the given name.CommandsetId(int value)CommandsetNode(SharedGraphNode value)CommandsetProperty(String value)abstract inttypeId()The binary identifier for this concrete type in the polymorphicCommandhierarchy.CommandunregisterListener(Listener l)Removes the givenListenerfrom this object.abstract <R,A,E extends Throwable>
Rvisit(Command.Visitor<R,A,E> v, A arg)Accepts the given visitor.protected voidwriteFields(DataWriter out)Serializes all fields of this instance to the given binary output.protected voidwriteFields(JsonWriter out)Writes all fields of this instance to the given output.voidwriteTo(DataWriter out)Writes the content of thisDataObjectto the given binary output.voidwriteTo(JsonWriter out)Writes this instance to the given output.-
Methods inherited from class de.haumacher.msgbuf.data.AbstractDataObject
readContent, readFields, toString, writeContent
-
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
jsonType
-
-
-
-
Field Detail
-
ID
public static final String ID
- See Also:
getId(), Constant Field Values
-
PROPERTY
public static final String PROPERTY
- See Also:
getProperty(), Constant Field Values
-
NODE
public static final String NODE
- See Also:
getNode(), Constant Field Values
-
ID__ID
public static final int ID__ID
Identifier for the propertygetId()in binary format.- See Also:
- Constant Field Values
-
PROPERTY__ID
public static final int PROPERTY__ID
Identifier for the propertygetProperty()in binary format.- See Also:
- Constant Field Values
-
_listener
protected Listener _listener
-
-
Constructor Detail
-
Command
protected Command()
Creates aCommandinstance.
-
-
Method Detail
-
kind
public abstract Command.TypeKind kind()
The type code of this instance.
-
getId
public final int getId()
The network ID of the changed object.
-
getProperty
public final String getProperty()
The name of the changed property of the object with the givengetId().
-
setProperty
public final Command setProperty(String value)
- See Also:
getProperty()
-
getNode
public final SharedGraphNode getNode()
Cache for the reference to the changed graph node itself.
-
setNode
public final Command setNode(SharedGraphNode value)
- See Also:
getNode()
-
hasNode
public final boolean hasNode()
Checks, whethergetNode()has a value.
-
registerListener
public Command 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 Command 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.
-
properties
public List<String> properties()
Description copied from interface:ReflectiveDataObjectAll properties that are supported by this object.- Specified by:
propertiesin interfaceReflectiveDataObject- See Also:
ReflectiveDataObject.get(String)
-
get
public Object get(String field)
Description copied from interface:ReflectiveDataObjectRetrieves value of the field with the given name.- Specified by:
getin interfaceReflectiveDataObject- Parameters:
field- The name of the property.- Returns:
- The value of the property with the given name.
- See Also:
ReflectiveDataObject.properties()
-
set
public void set(String field, Object value)
Description copied from interface:ReflectiveDataObjectSets the value of the property with the given name.- Specified by:
setin interfaceReflectiveDataObject- Parameters:
field- The name of the property to update.value- The new value of the property.- See Also:
ReflectiveDataObject.get(String)
-
readCommand
public static Command readCommand(JsonReader in) throws IOException
Reads a new instance from the given reader.- Throws:
IOException
-
writeTo
public final void writeTo(JsonWriter out) throws IOException
Description copied from interface:DataObjectWrites this instance to the given output.- Specified by:
writeToin interfaceDataObject- Parameters:
out- TheJsonWriterto write this instance to.- Throws:
IOException- if writing fails.
-
writeFields
protected void writeFields(JsonWriter out) throws IOException
Description copied from class:AbstractDataObjectWrites all fields of this instance to the given output.- Overrides:
writeFieldsin classAbstractDataObject- Parameters:
out- The writer to write to.- Throws:
IOException- If writing fails.
-
readField
protected void readField(JsonReader in, String field) throws IOException
Description copied from class:AbstractDataObjectReads the given field from the given input.- Overrides:
readFieldin classAbstractDataObject- Parameters:
in- The reader to take the value from.field- The name of the field whose value should be read.- Throws:
IOException
-
typeId
public abstract int typeId()
The binary identifier for this concrete type in the polymorphicCommandhierarchy.
-
writeTo
public final void writeTo(DataWriter out) throws IOException
Description copied from interface:BinaryDataObjectWrites the content of thisDataObjectto the given binary output.- Specified by:
writeToin interfaceBinaryDataObject- Parameters:
out- The writer to write this object to.- Throws:
IOException- If writing fails.
-
writeFields
protected void writeFields(DataWriter out) throws IOException
Serializes all fields of this instance to the given binary output.- Parameters:
out- The binary output to write to.- Throws:
IOException- If writing fails.
-
readCommand
public static Command readCommand(DataReader in) throws IOException
Reads a new instance from the given reader.- Throws:
IOException
-
readField
protected void readField(DataReader in, int field) throws IOException
Consumes the value for the field with the given ID and assigns its value.- Throws:
IOException
-
visit
public abstract <R,A,E extends Throwable> R visit(Command.Visitor<R,A,E> v, A arg) throws E extends Throwable
Accepts the given visitor.- Throws:
E extends Throwable
-
-