fr.emn.reactiveinput
Class DeviceUtilities

java.lang.Object
  extended byfr.emn.reactiveinput.DeviceUtilities

public class DeviceUtilities
extends java.lang.Object

Utility methods for creating your own device, and generic methods for accessing device's properties.


Constructor Summary
DeviceUtilities()
           
 
Method Summary
static boolean belongsTo(Device d, DeviceFolder f)
          REMOVE ?
static void copyPropertyValues(Device source, Device dest)
          Dest must be the same class, or a subclass of source.
static Device createNewInstance(java.lang.Class cl)
          This method instanciates a device with its no-arg constructor.
static Device createNewInstance(Device d)
          This method re-instanciates a device with its no-arg constructor.
static Device defaultCopy(Device d)
          Default method for copying a device : calls createNewInstance(), setPrototype(), then copyPropertyValues().
static boolean defaultIsOpenable(Device d)
          Default method for telling if a device can be open: returns false if one or several obligatory input slots are not valid (see In.isValid()).
static DeviceFolder[] getFolders(Device prototype)
          Returns all folders containing the given prototype.
static java.lang.String getGenericPropertyValue(Device d, java.lang.String name)
          Returns the value of a property in its generic string form.
static java.lang.String[] getProperties(Device d)
          Returns the valid properties of the device, matching declared properties and implemented accessors.
static java.util.Vector getPropertiesWithTypes(Device d)
          Returns the valid properties of the device, matching declared properties and implemented accessors.
static java.lang.Object getPropertyValue(Device d, java.lang.String name)
          rem : Primitive return values are automatically wrapped into objects.
static Device getPrototype(Device device)
          Returns the prototype from which this device has been created.
static Slot getSlot(Device d, java.lang.String name, boolean inSlot, boolean outSlot)
           
static void register(DeviceFolder f)
          Register the folder f and all its subfolders, so that we can retreive all folders containing a given prototype.
static boolean setPropertyValue(Device d, java.lang.String name, java.lang.Object value)
          Sets the value of a property.
static boolean setPropertyValue(Device d, java.lang.String name, java.lang.String genericValue)
          Sets the value of a property with a generic String form.
static boolean setPropertyValues(Device d, java.lang.String[] names, java.lang.String[] genericValues)
           
static void setPrototype(Device device, Device prototype)
          Call this method in your own device copy() method.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DeviceUtilities

public DeviceUtilities()
Method Detail

belongsTo

public static boolean belongsTo(Device d,
                                DeviceFolder f)
REMOVE ? Returns true if this device belongs to or comes from the given DeviceFolder, i.e. if this device's original prototype is among DeviceFolder's prototypes.


copyPropertyValues

public static void copyPropertyValues(Device source,
                                      Device dest)
Dest must be the same class, or a subclass of source.


createNewInstance

public static Device createNewInstance(java.lang.Class cl)
This method instanciates a device with its no-arg constructor.


createNewInstance

public static Device createNewInstance(Device d)
This method re-instanciates a device with its no-arg constructor.


defaultCopy

public static Device defaultCopy(Device d)
Default method for copying a device : calls createNewInstance(), setPrototype(), then copyPropertyValues().


defaultIsOpenable

public static boolean defaultIsOpenable(Device d)
Default method for telling if a device can be open: returns false if one or several obligatory input slots are not valid (see In.isValid()).


getFolders

public static DeviceFolder[] getFolders(Device prototype)
Returns all folders containing the given prototype.

Returns only registered folders (see register() method).


getGenericPropertyValue

public static java.lang.String getGenericPropertyValue(Device d,
                                                       java.lang.String name)
Returns the value of a property in its generic string form.


getProperties

public static java.lang.String[] getProperties(Device d)
Returns the valid properties of the device, matching declared properties and implemented accessors.


getPropertiesWithTypes

public static java.util.Vector getPropertiesWithTypes(Device d)
Returns the valid properties of the device, matching declared properties and implemented accessors.

The resulting Vector contains the names (String) and the types (Class) of the properties found.


getPropertyValue

public static java.lang.Object getPropertyValue(Device d,
                                                java.lang.String name)
rem : Primitive return values are automatically wrapped into objects.


getPrototype

public static Device getPrototype(Device device)
Returns the prototype from which this device has been created. A prototype is a device belonging to a DeviceFolder.

Returns the device itself if it already a prototype, or if its original prototype is unknown.


getSlot

public static Slot getSlot(Device d,
                           java.lang.String name,
                           boolean inSlot,
                           boolean outSlot)

register

public static void register(DeviceFolder f)
Register the folder f and all its subfolders, so that we can retreive all folders containing a given prototype. Called automatically by FRoot (???).


setPropertyValue

public static boolean setPropertyValue(Device d,
                                       java.lang.String name,
                                       java.lang.Object value)
Sets the value of a property.

Integer, Boolean and Float arguments are automatically wrapped into primitives.


setPropertyValue

public static boolean setPropertyValue(Device d,
                                       java.lang.String name,
                                       java.lang.String genericValue)
Sets the value of a property with a generic String form. Examples:

"120" (int)

"120.58" (float)

"abc" (String)

"true" (boolean)

"[120, 55, 28]" (int array)

"[[2, 50], [3, 20]]" (2-dimensions int array)

etc.


setPropertyValues

public static boolean setPropertyValues(Device d,
                                        java.lang.String[] names,
                                        java.lang.String[] genericValues)

setPrototype

public static void setPrototype(Device device,
                                Device prototype)
Call this method in your own device copy() method. Do not call this method in other cases.