Class DefaultDriver

  • All Implemented Interfaces:
    Annotations, Driver

    public class DefaultDriver
    extends java.lang.Object
    implements Driver
    Default implementation of extensible driver.
    • Constructor Summary

      Constructors 
      Constructor Description
      DefaultDriver​(java.lang.String name, java.util.List<Driver> parents, java.lang.String manufacturer, java.lang.String hwVersion, java.lang.String swVersion, java.util.Map<java.lang.Class<? extends Behaviour>,​java.lang.Class<? extends Behaviour>> behaviours, java.util.Map<java.lang.String,​java.lang.String> properties)
      Creates a driver with the specified name.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.util.Set<java.lang.Class<? extends Behaviour>> behaviours()
      Returns the set of behaviours supported by this driver.
      <T extends Behaviour>
      T
      createBehaviour​(DriverData data, java.lang.Class<T> behaviourClass)
      Creates an instance of behaviour primed with the specified driver data.
      <T extends Behaviour>
      T
      createBehaviour​(DriverHandler handler, java.lang.Class<T> behaviourClass)
      Creates an instance of behaviour primed with the specified driver handler.
      boolean equals​(java.lang.Object driverToBeCompared)  
      java.lang.String getProperty​(java.lang.String name)
      Gets the value of given property name.
      boolean hasBehaviour​(java.lang.Class<? extends Behaviour> behaviourClass)
      Indicates whether or not the driver, or any of its parents, support the specified class of behaviour.
      int hashCode()  
      java.lang.String hwVersion()
      Returns the device hardware version.
      java.lang.Class<? extends Behaviour> implementation​(java.lang.Class<? extends Behaviour> behaviour)
      Returns the implementation class for the specified behaviour.
      java.util.Set<java.lang.String> keys()
      Returns the set of keys for available annotations.
      java.lang.String manufacturer()
      Returns the device manufacturer name.
      Driver merge​(Driver other)
      Merges the specified driver behaviours and properties into this one, giving preference to the other driver when dealing with conflicts.
      java.lang.String name()
      Returns the driver name.
      Driver parent()
      Returns the parent driver from which this driver inherits behaviours and properties.
      java.util.List<Driver> parents()
      Returns all the parent drivers from which this driver inherits behaviours and properties.
      java.util.Map<java.lang.String,​java.lang.String> properties()
      Returns the set of annotations as map of key/value properties.
      java.lang.String swVersion()
      Returns the device software version.
      java.lang.String toString()  
      java.lang.String value​(java.lang.String key)
      Returns the value of the specified annotation.
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • DefaultDriver

        public DefaultDriver​(java.lang.String name,
                             java.util.List<Driver> parents,
                             java.lang.String manufacturer,
                             java.lang.String hwVersion,
                             java.lang.String swVersion,
                             java.util.Map<java.lang.Class<? extends Behaviour>,​java.lang.Class<? extends Behaviour>> behaviours,
                             java.util.Map<java.lang.String,​java.lang.String> properties)
        Creates a driver with the specified name.
        Parameters:
        name - driver name
        parents - optional parent drivers
        manufacturer - device manufacturer
        hwVersion - device hardware version
        swVersion - device software version
        behaviours - device behaviour classes
        properties - properties for configuration of device behaviour classes
    • Method Detail

      • merge

        public Driver merge​(Driver other)
        Description copied from interface: Driver
        Merges the specified driver behaviours and properties into this one, giving preference to the other driver when dealing with conflicts.
        Specified by:
        merge in interface Driver
        Parameters:
        other - other driver
        Returns:
        merged driver
      • name

        public java.lang.String name()
        Description copied from interface: Driver
        Returns the driver name. This is expected to be a reverse-DNS, Java package-like name.
        Specified by:
        name in interface Driver
        Returns:
        driver name
      • manufacturer

        public java.lang.String manufacturer()
        Description copied from interface: Driver
        Returns the device manufacturer name.
        Specified by:
        manufacturer in interface Driver
        Returns:
        manufacturer name
      • hwVersion

        public java.lang.String hwVersion()
        Description copied from interface: Driver
        Returns the device hardware version.
        Specified by:
        hwVersion in interface Driver
        Returns:
        hardware version
      • swVersion

        public java.lang.String swVersion()
        Description copied from interface: Driver
        Returns the device software version.
        Specified by:
        swVersion in interface Driver
        Returns:
        software version
      • parent

        public Driver parent()
        Description copied from interface: Driver
        Returns the parent driver from which this driver inherits behaviours and properties.
        Specified by:
        parent in interface Driver
        Returns:
        parent driver; null if driver has no parent
      • parents

        public java.util.List<Driver> parents()
        Description copied from interface: Driver
        Returns all the parent drivers from which this driver inherits behaviours and properties.
        Specified by:
        parents in interface Driver
        Returns:
        list of parent drivers
      • behaviours

        public java.util.Set<java.lang.Class<? extends Behaviour>> behaviours()
        Description copied from interface: Driver
        Returns the set of behaviours supported by this driver. It reflects behaviours of only this driver and not its parent.
        Specified by:
        behaviours in interface Driver
        Returns:
        set of device driver behaviours
      • implementation

        public java.lang.Class<? extends Behaviour> implementation​(java.lang.Class<? extends Behaviour> behaviour)
        Description copied from interface: Driver
        Returns the implementation class for the specified behaviour. It reflects behaviours of only this driver and not its parent.
        Specified by:
        implementation in interface Driver
        Parameters:
        behaviour - behaviour interface
        Returns:
        implementation class
      • hasBehaviour

        public boolean hasBehaviour​(java.lang.Class<? extends Behaviour> behaviourClass)
        Description copied from interface: Driver
        Indicates whether or not the driver, or any of its parents, support the specified class of behaviour.
        Specified by:
        hasBehaviour in interface Driver
        Parameters:
        behaviourClass - behaviour class
        Returns:
        true if behaviour is supported
      • createBehaviour

        public <T extends Behaviour> T createBehaviour​(DriverData data,
                                                       java.lang.Class<T> behaviourClass)
        Description copied from interface: Driver
        Creates an instance of behaviour primed with the specified driver data. If the current driver does not support the specified behaviour and the driver has parent, the request is delegated to the parent driver.
        Specified by:
        createBehaviour in interface Driver
        Type Parameters:
        T - type of behaviour
        Parameters:
        data - driver data context
        behaviourClass - driver behaviour class
        Returns:
        behaviour instance
      • createBehaviour

        public <T extends Behaviour> T createBehaviour​(DriverHandler handler,
                                                       java.lang.Class<T> behaviourClass)
        Description copied from interface: Driver
        Creates an instance of behaviour primed with the specified driver handler. If the current driver does not support the specified behaviour and the driver has parent, the request is delegated to the parent driver.
        Specified by:
        createBehaviour in interface Driver
        Type Parameters:
        T - type of behaviour
        Parameters:
        handler - driver handler context
        behaviourClass - driver behaviour class
        Returns:
        behaviour instance
      • keys

        public java.util.Set<java.lang.String> keys()
        Description copied from interface: Annotations
        Returns the set of keys for available annotations.
        Specified by:
        keys in interface Annotations
        Returns:
        annotation keys
      • value

        public java.lang.String value​(java.lang.String key)
        Description copied from interface: Annotations
        Returns the value of the specified annotation.
        Specified by:
        value in interface Annotations
        Parameters:
        key - annotation key
        Returns:
        annotation value
      • properties

        public java.util.Map<java.lang.String,​java.lang.String> properties()
        Description copied from interface: Driver
        Returns the set of annotations as map of key/value properties.
        Specified by:
        properties in interface Driver
        Returns:
        map of properties
      • getProperty

        public java.lang.String getProperty​(java.lang.String name)
        Description copied from interface: Driver
        Gets the value of given property name. If the driver does not define the property, a BFS will be performed to search its ancestors.
        Specified by:
        getProperty in interface Driver
        Parameters:
        name - property name
        Returns:
        the value of the property, or null if the property is not defined in this driver nor in any of its ancestors
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • equals

        public boolean equals​(java.lang.Object driverToBeCompared)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object