org.instantreality.InstantIO
Class Field

java.lang.Object
  extended by org.instantreality.InstantIO.Field

public final class Field
extends java.lang.Object

Keeps information about Node fields.

Most Nodes need some kind of parameters when they are started, e.g. which serial port they should use to communicate with a device. The Field class contains meta information that describes one parameter of a Node. The meta information consists of:

For example, let's say you want to create a Node that operates a device that is connected to a serial port of the computer. So, you need to specify the number of the serial port and the baud rate. First, you have to write methods for setting and getting the port number and the baud rate:
 public class MyNode extends Node
 {
   ...
   public void setPort(int port) { ... }
   public int getPort() { ... }
   public void setBaudRate(int baudRate) { ... }
   public int getBaudRate() { ... }
   ...
 }
 
Then, you have to create instances of the Field class that describe the parameters. Usually, you do this by creating a static array in the Node class:
 public class MyNode extends Node
 {
   ...
    public static final Field[] fields =
    {
      new Field(
        "port",
        "The serial port the device is connected to",
        "0",
        MyNode.class, int.class, "setPort", "getPort"
      ),
      new Field(
        "BaudRate",
        "The baud rate the device is operating at",
        "115200",
        MyNode.class, int.class, "setBaudRate", "getBaudRate"
      )
    };
   ...
 }
 
Finally, you have to specify the fields when you create the Instance of the NodeType object that contains meta information about the Node:
 public static final NodeType myType = new NodeType(
   "MyNode", MyNode.class,
   "Example node", null, "Patrick Dähne", MyNode.fields);
 

Author:
Patrick Dähne
See Also:
Node, NodeType

Constructor Summary
Field(java.lang.String name, java.lang.String description, java.lang.String defaultValue, java.lang.Class nodeType, java.lang.Class valueType, java.lang.String setMethod, java.lang.String getMethod)
          Creates a new Field object.
 
Method Summary
 java.lang.String getDefaultValue()
          Returns the default value of the field.
 java.lang.String getDescription()
          Returns the description of the field.
 java.lang.String getName()
          Returns the name of the field.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Field

public Field(java.lang.String name,
             java.lang.String description,
             java.lang.String defaultValue,
             java.lang.Class nodeType,
             java.lang.Class valueType,
             java.lang.String setMethod,
             java.lang.String getMethod)
Creates a new Field object.

Parameters:
name - The name of the field. The name is used to identify the field. Case does not matter.
description - A description of the field. This description is not used by the system in any way. It solely serves documentation purposes. It contains information about the field in a human-readable way. Some user interfaces for managing the system display the description to the user.
defaultValue - The default value of the field. The default value is a string representation of the value the field contains when the user does not explicitly specify a value.
nodeType - The type of the Nodes that contain this field.
valueType - The type of the values that this field contains. Currently, only basic Java data types are supported (boolean, double, float, int, long, short, byte, char as well as their corresponding wrapper classes) and String and InetAdress objects. You can also use all kinds of classes that implement the standard toString method and a static method called valueOf that takes a string as parameter and returns an instance of the class that is the corresponding value of the parsed string. Most data types defined in this package have these methods implemented and can therefore be used for fields.
setMethod - A method of the Node used to set new values of this field.
getMethod - A method of the Node used to return values of this field.
Method Detail

getName

public java.lang.String getName()
Returns the name of the field. The name is used to identify the field.

The following example prints the name of a field to the console:

 Field field = ...;
 System.out.println("Name = " + field.getName());
 

Returns:
The name of the field.

getDescription

public java.lang.String getDescription()
Returns the description of the field. The description of the field is not used by the system in any way. It solely serves documentation purposes. It contains information about the field in a human-readable way. Some user interfaces for managing the system display the description to the user.

The following example prints the description of a field to the console:

 Field field = ...;
 System.out.println("Description = " + field.getDescription());
 

Returns:
The description of the field.

getDefaultValue

public java.lang.String getDefaultValue()
Returns the default value of the field. The default value is a string representation of the value the field contains when the user does not explicitly specify a value.

The following example prints the default value of a field to the console:

 Field field = ...;
 System.out.println("Default value = " + field.getDefaultValue());
 

Returns:
The default value.