#    "$Name:  $";
#    "$Header:  $";
# =============================================================================
#
# file :        NXSConfigServer.py
#
# description : Python source for the NXSConfigServer and its commands.
#                The class is derived from Device. It represents the
#                CORBA servant object which will be accessed from the
#                network. All commands which can be executed on the
#                NXSConfigServer are implemented in this file.
#
# project :     TANGO Device Server
#
# $Author:  $
#
# $Revision:  $
#
# $Log:  $
#
# copyleft :    European Synchrotron Radiation Facility
#               BP 220, Grenoble 38043
#               FRANCE
#
# =============================================================================
#          This file is generated by POGO
#    (Program Obviously used to Generate tango Object)
#
#         (c) - Software Engineering Group - ESRF
# =============================================================================
#

""" Configuration Server for Nexus Data Writer """

try:
    import tango
except Exception:
    import PyTango as tango

from .XMLConfigurator import XMLConfigurator as XMLC


# ==================================================================
# ==================================================================


class NXSConfigServer(tango.LatestDeviceImpl):

    """   NXSConfigServer Class Description:

    :brief: Configuration Server based on MySQL database.
            Device States Description:
            DevState.OPEN -     Open connection to the database,
            DevState.ON -       Server is ON,
            DevState.RUNNING -  Performing a query,
    """

    def __init__(self, cl, name):
        """ Device constructor

        :param cl: class name
        :type cl: :obj:`str`
        :param name: device name
        :type name: :obj:`str`
        """
        tango.LatestDeviceImpl.__init__(self, cl, name)
        self.debug_stream("In __init__()")
        #: (:class:`nxsconfigserver.XMLConfigutator.XMLConfigutator`) \
        #:    xml configurator instance
        self.xmlc = None
        NXSConfigServer.init_device(self)

    def delete_device(self):
        """ Device destructor
        """
        self.debug_stream("In delete_device()")
        if hasattr(self, "xmlc") and self.xmlc:
            if hasattr(self.xmlc, "close"):
                self.xmlc.close()
            del self.xmlc
            self.xmlc = None
        self.set_state(tango.DevState.OFF)

    def init_device(self):
        """ Device initialization
        """
        self.debug_stream("In init_device()")
        self.xmlc = XMLC(self)
        self.set_state(tango.DevState.ON)
        self.get_device_properties(self.get_device_class())
        self.xmlc.versionLabel = self.VersionLabel
        self.xmlc.extraLinkPath = self.ExtraLinkPath

    def always_executed_hook(self):
        """ Always excuted hook method
        """
        self.debug_stream("In always_excuted_hook()")

    # ==================================================================
    #
    #    NXSConfigServer read/write attribute methods
    #
    # ==================================================================
    def read_attr_hardware(self, _):
        """ Read Attribute Hardware
        """
        self.debug_stream("In read_attr_hardware()")

    def read_XMLString(self, attr):
        """ Read XMLString attribute

        :param attr: xml string attribute
        :type attr: :class:`tango.Attribute`
        """
        self.debug_stream("In read_XMLString()")
        attr.set_value(self.xmlc.xmlstring)

    def write_XMLString(self, attr):
        """ Write XMLString attribute

        :param attr: xml string attribute
        :type attr: :class:`tango.Attribute`
        """
        self.debug_stream("In write_XMLString()")
        self.xmlc.xmlstring = attr.get_write_value()

    def is_XMLString_allowed(self, _):
        """ XMLString attribute State Machine

        :returns: True if the operation allowed
        :rtype: :obj:`bool`
        """
        if self.get_state() in [tango.DevState.ON,
                                tango.DevState.RUNNING]:
            return False
        return True

    def read_MergedXML(self, attr):
        """ Read MergedXML attribute

        :param attr: xml string attribute
        :type attr: :class:`tango.Attribute`
        """
        self.debug_stream("In read_MergedXML()")
        attr.set_value(self.xmlc.mergedxml)

    def is_MergedXML_allowed(self, _):
        """ MergedXML attribute State Machine

        :returns: True if the operation allowed
        :rtype: :obj:`bool`
        """
        if self.get_state() in [tango.DevState.ON,
                                tango.DevState.RUNNING]:
            return False
        return True

    def read_Selection(self, attr):
        """ Read Selection attribute

        :param attr: selection attribute
        :type attr: :class:`tango.Attribute`
        """
        self.debug_stream("In read_Selection()")
        attr.set_value(self.xmlc.selection)

    def write_Selection(self, attr):
        """ Write Selection attribute

        :param attr: selection attribute
        :type attr: :class:`tango.Attribute`
        """
        self.debug_stream("In write_Selection()")
        self.xmlc.selection = attr.get_write_value()

    def is_Selection_allowed(self, _):
        """ Selection attribute State Machine

        :returns: True if the operation allowed
        :rtype: :obj:`bool`
        """
        if self.get_state() in [tango.DevState.ON,
                                tango.DevState.RUNNING]:
            return False
        return True

    def read_JSONSettings(self, attr):
        """ Read JSONSettings attribute

        :param attr: jsonsettings attribute
        :type attr: :class:`tango.Attribute`
        """
        self.debug_stream("In read_JSONSettings()")
        attr.set_value(self.xmlc.jsonsettings)

    def write_JSONSettings(self, attr):
        """ Read JSONSettings attribute

        :param attr: jsonsettings attribute
        :type attr: :class:`tango.Attribute`
        """
        self.debug_stream("In write_JSONSettings()")
        if self.is_JSONSettings_write_allowed():
            self.xmlc.jsonsettings = attr.get_write_value()
        else:
            self.warn_stream("To change the settings please close the server.")
            raise Exception(
                "To change the settings please close the server.")

    def is_JSONSettings_write_allowed(self):
        """ JSONSettings attribute Write State Machine

        :returns: True if the operation allowed
        :rtype: :obj:`bool`
        """
        if self.get_state() in [tango.DevState.OPEN,
                                tango.DevState.RUNNING]:
            return False
        return True

    def read_STEPDataSources(self, attr):
        """ Read STEPDataSources attribute

        :param attr: step datasources attribute
        :type attr: :class:`tango.Attribute`
        """
        self.debug_stream("In read_STEPDataSources()")
        attr.set_value(self.xmlc.stepdatasources or "")

    def write_STEPDataSources(self, attr):
        """ Write STEPDataSources attribute

        :param attr: step datasources attribute
        :type attr: :class:`tango.Attribute`
        """
        self.debug_stream("In write_STEPDataSources()")
        if self.is_STEPDataSources_write_allowed():
            self.xmlc.stepdatasources = attr.get_write_value() or ""
        else:
            self.warn_stream("To change the settings please close the server.")
            raise Exception(
                "To change the settings please close the server.")

    def is_STEPDataSources_write_allowed(self):
        """ STEPDataSources attribute Write State Machine

        :returns: True if the operation allowed
        :rtype: :obj:`bool`
        """
        if self.get_state() in [tango.DevState.RUNNING]:
            return False
        return True

    def read_LinkDataSources(self, attr):
        """ Read LinkDataSources attribute

        :param attr: link datasources attribute
        :type attr: :class:`tango.Attribute`
        """
        self.debug_stream("In read_LinkDataSources()")
        attr.set_value(self.xmlc.linkdatasources or "")

    def write_LinkDataSources(self, attr):
        """ Write LinkDataSources attribute

        :param attr: link datasources attribute
        :type attr: :class:`tango.Attribute`
        """
        self.debug_stream("In write_LinkDataSources()")
        if self.is_LinkDataSources_write_allowed():
            self.xmlc.linkdatasources = attr.get_write_value() or ""
        else:
            self.warn_stream("To change the settings please close the server.")
            raise Exception(
                "To change the settings please close the server.")

    def is_LinkDataSources_write_allowed(self):
        """ LinkDataSources attribute Write State Machine

        :returns: True if the operation allowed
        :rtype: :obj:`bool`
        """
        if self.get_state() in [tango.DevState.RUNNING]:
            return False
        return True

    def read_ExtraLinkDataSources(self, attr):
        """ Read ExtraLinkDataSources attribute

        :param attr: extra link datasources attribute
        :type attr: :class:`tango.Attribute`
        """
        self.debug_stream("In read_ExtraLinkDataSources()")
        attr.set_value(self.xmlc.extralinkdatasources or "")

    def write_ExtraLinkDataSources(self, attr):
        """ Write ExtraLinkDataSources attribute

        :param attr: extra link datasources attribute
        :type attr: :class:`tango.Attribute`
        """
        self.debug_stream("In write_ExtraLinkDataSources()")
        if self.is_ExtraLinkDataSources_write_allowed():
            self.xmlc.extralinkdatasources = attr.get_write_value() or ""
        else:
            self.warn_stream("To change the settings please close the server.")
            raise Exception(
                "To change the settings please close the server.")

    def is_ExtraLinkDataSources_write_allowed(self):
        """ ExtraLinkDataSources attribute Write State Machine

        :returns: True if the operation allowed
        :rtype: :obj:`bool`
        """
        if self.get_state() in [tango.DevState.RUNNING]:
            return False
        return True

    def read_CanFailDataSources(self, attr):
        """ Read CanFailDataSources attribute

        :param attr: step datasources attribute
        :type attr: :class:`tango.Attribute`
        """
        self.debug_stream("In read_CanFailDataSources()")
        attr.set_value(self.xmlc.canfaildatasources or "")

    def write_CanFailDataSources(self, attr):
        """ Write CanFailDataSources attribute

        :param attr: step datasources attribute
        :type attr: :class:`tango.Attribute`
        """
        self.debug_stream("In write_CanFailDataSources()")
        if self.is_CanFailDataSources_write_allowed():
            self.xmlc.canfaildatasources = attr.get_write_value() or ""
        else:
            self.warn_stream("To change the settings please close the server.")
            raise Exception(
                "To change the settings please close the server.")

    def is_CanFailDataSources_write_allowed(self):
        """ CanFailDataSources attribute Write State Machine

        :returns: True if the operation allowed
        :rtype: :obj:`bool`
        """
        if self.get_state() in [tango.DevState.RUNNING]:
            return False
        return True

    def read_Version(self, attr):
        """ Read Version attribute

        :param attr: version attribute
        :type attr: :class:`tango.Attribute`
        """
        self.debug_stream("In read_Version()")

        self.get_device_properties(self.get_device_class())
        self.xmlc.versionLabel = self.VersionLabel
        attr.set_value(self.xmlc.version)

    def read_Variables(self, attr):
        """ Read Variables attribute

        :param attr: variables attribute
        :type attr: :class:`tango.Attribute`
        """
        self.debug_stream("In read_Variables()")
        attr.set_value(self.xmlc.variables)

    def write_Variables(self, attr):
        """ Write Variables attribute

        :param attr: variables attribute
        :type attr: :class:`tango.Attribute`
        """
        self.debug_stream("In write_Variables()")
        self.xmlc.variables = attr.get_write_value()

    def is_Variables_allowed(self, _):
        """ Variables attribute State Machine

        :returns: True if the operation allowed
        :rtype: :obj:`bool`
        """
        if self.get_state() in [tango.DevState.RUNNING]:
            return False
        return True

    # ==================================================================
    #
    #    NXSConfigServer command methods
    #
    # ==================================================================

    def Open(self):
        """ Open command

        :brief: Opens connection to the database
        """
        self.debug_stream("In Open()")
        try:
            self.set_state(tango.DevState.RUNNING)
            self.xmlc.open()
            self.set_state(tango.DevState.OPEN)
        finally:
            if self.get_state() == tango.DevState.RUNNING:
                self.set_state(tango.DevState.ON)

    def is_Open_allowed(self):
        """ Open command State Machine

        :returns: True if the operation allowed
        :rtype: :obj:`bool`
        """
        if self.get_state() in [tango.DevState.RUNNING]:
            return False
        return True

    def Close(self):
        """ Close command

        :brief: Closes connection into the database
        """
        self.debug_stream("In Close()")

        try:
            self.set_state(tango.DevState.RUNNING)
            self.xmlc.close()
            self.set_state(tango.DevState.ON)
        finally:
            if self.get_state() == tango.DevState.RUNNING:
                self.set_state(tango.DevState.ON)

    def is_Close_allowed(self):
        """ Close command State Machine

        :returns: True if the operation allowed
        :rtype: :obj:`bool`
        """
        if self.get_state() in [tango.DevState.ON,
                                tango.DevState.RUNNING]:
            return False
        return True

    def Components(self, argin):
        """Components command

        :brief: Returns a list of required components

        :param argin:  DevVarStringArray    list of component names
        :type argin: :obj:`list` <:obj:`str`>
        :returns: DevVarStringArray    list of required components
        :rtype: :obj:`list` <:obj:`str`>
        """
        self.debug_stream("In Components()")
        try:
            self.set_state(tango.DevState.RUNNING)
            argout = self.xmlc.components(argin)
            self.set_state(tango.DevState.OPEN)
        finally:
            if self.get_state() == tango.DevState.RUNNING:
                self.set_state(tango.DevState.OPEN)

        return argout

    def is_Components_allowed(self):
        """ Components command State Machine

        :returns: True if the operation allowed
        :rtype: :obj:`bool`
        """
        if self.get_state() in [tango.DevState.ON,
                                tango.DevState.RUNNING]:
            return False
        return True

    def Selections(self, argin):
        """ Selections command

        :brief: Returns a list of required selections

        :param argin:  DevVarStringArray    list of selection names
        :type argin: :obj:`list` <:obj:`str`>
        :returns: DevVarStringArray    list of required selections
        :rtype: :obj:`list` <:obj:`str`>
        """
        self.debug_stream("In Selections()")
        try:
            self.set_state(tango.DevState.RUNNING)
            argout = self.xmlc.selections(argin)
            self.set_state(tango.DevState.OPEN)
        finally:
            if self.get_state() == tango.DevState.RUNNING:
                self.set_state(tango.DevState.OPEN)

        return argout

    def is_Selections_allowed(self):
        """ Selections command State Machine

        :returns: True if the operation allowed
        :rtype: :obj:`bool`
        """
        if self.get_state() in [tango.DevState.ON,
                                tango.DevState.RUNNING]:
            return False
        return True

    def InstantiatedComponents(self, argin):
        """ InstantiatedComponents command

        :brief: Returns a list of required components

        :param argin:  DevVarStringArray    list of component names
        :type argin: :obj:`list` <:obj:`str`>
        :returns: DevVarStringArray    list of instantiated components
        :rtype: :obj:`list` <:obj:`str`>
        """
        self.debug_stream("In InstantiateComponents()")
        try:
            self.set_state(tango.DevState.RUNNING)
            argout = self.xmlc.instantiatedComponents(argin)
            self.set_state(tango.DevState.OPEN)
        finally:
            if self.get_state() == tango.DevState.RUNNING:
                self.set_state(tango.DevState.OPEN)

        return argout

    def is_InstantiatedComponents_allowed(self):
        """ Components command State Machine

        :returns: True if the operation allowed
        :rtype: :obj:`bool`
        """
        if self.get_state() in [tango.DevState.ON,
                                tango.DevState.RUNNING]:
            return False
        return True

    def InstantiatedDataSources(self, argin):
        """ InstantiatedDataSources command

        :brief: Returns a list of required components

        :param argin:  DevVarStringArray    list of component names
        :type argin: :obj:`list` <:obj:`str`>
        :returns: DevVarStringArray    list of instantiated components
        :rtype: :obj:`list` <:obj:`str`>
        """
        self.debug_stream("In InstantiateDataSources()")
        try:
            self.set_state(tango.DevState.RUNNING)
            argout = self.xmlc.instantiatedDataSources(argin)
            self.set_state(tango.DevState.OPEN)
        finally:
            if self.get_state() == tango.DevState.RUNNING:
                self.set_state(tango.DevState.OPEN)

        return argout

    def is_InstantiatedDataSources_allowed(self):
        """ DataSources command State Machine

        :returns: True if the operation allowed
        :rtype: :obj:`bool`
        """
        if self.get_state() in [tango.DevState.ON,
                                tango.DevState.RUNNING]:
            return False
        return True

    def DataSources(self, argin):
        """ DataSources command

        :brief: Returns a list of required DataSources

        :param argin:  DevVarStringArray    list of DataSource names
        :type argin: :obj:`list` <:obj:`str`>
        :returns: DevVarStringArray    list of required DataSources
        :rtype: :obj:`list` <:obj:`str`>
        """
        self.debug_stream("In DataSources()")
        try:
            self.set_state(tango.DevState.RUNNING)
            argout = self.xmlc.dataSources(argin)
            self.set_state(tango.DevState.OPEN)
        finally:
            if self.get_state() == tango.DevState.RUNNING:
                self.set_state(tango.DevState.OPEN)

        return argout

    def is_DataSources_allowed(self):
        """ DataSources command State Machine

        :returns: True if the operation allowed
        :rtype: :obj:`bool`
        """
        if self.get_state() in [tango.DevState.ON,
                                tango.DevState.RUNNING]:
            return False
        return True

    def AvailableComponents(self):
        """ AvailableComponents command

        :brief: Returns a list of available component names

        :returns: DevVarStringArray    list of available component names
        :rtype: :obj:`list` <:obj:`str`>
        """
        self.debug_stream("In AvailableComponents()")
        try:
            self.set_state(tango.DevState.RUNNING)
            argout = self.xmlc.availableComponents()
            self.set_state(tango.DevState.OPEN)
        finally:
            if self.get_state() == tango.DevState.RUNNING:
                self.set_state(tango.DevState.OPEN)

        return argout

    def is_AvailableComponents_allowed(self):
        """ AvailableComponents command State Machine

        :returns: True if the operation allowed
        :rtype: :obj:`bool`
        """
        if self.get_state() in [tango.DevState.ON,
                                tango.DevState.RUNNING]:
            return False
        return True

    def AvailableSelections(self):
        """ AvailableSelections command

        :brief: Returns a list of available selection names

        :returns: DevVarStringArray    list of available selection names
        :rtype: :obj:`list` <:obj:`str`>
        """
        self.debug_stream("In AvailableSelections()")
        try:
            self.set_state(tango.DevState.RUNNING)
            argout = self.xmlc.availableSelections()
            self.set_state(tango.DevState.OPEN)
        finally:
            if self.get_state() == tango.DevState.RUNNING:
                self.set_state(tango.DevState.OPEN)

        return argout

    def is_AvailableSelections_allowed(self):
        """ AvailableSelections command State Machine

        :returns: True if the operation allowed
        :rtype: :obj:`bool`
        """
        if self.get_state() in [tango.DevState.ON,
                                tango.DevState.RUNNING]:
            return False
        return True

    def AvailableDataSources(self):
        """ AvailableDataSources command

        :brief: Returns a list of available DataSource names

        :returns: DevVarStringArray    list of available DataSource names
        :rtype: :obj:`list` <:obj:`str`>
        """
        self.debug_stream("In AvailableDataSources()")
        try:
            self.set_state(tango.DevState.RUNNING)
            argout = self.xmlc.availableDataSources()
            self.set_state(tango.DevState.OPEN)
        finally:
            if self.get_state() == tango.DevState.RUNNING:
                self.set_state(tango.DevState.OPEN)

        return argout

    def is_AvailableDataSources_allowed(self):
        """ AvailableDataSources command State Machine

        :returns: True if the operation allowed
        :rtype: :obj:`bool`
        """
        if self.get_state() in [tango.DevState.ON,
                                tango.DevState.RUNNING]:
            return False
        return True

    def StoreComponent(self, argin):
        """ StoreComponent command

        :brief: Stores the component from XMLString

        :param argin:  DevString    component name
        :type argin: :obj:`str`
        """
        self.debug_stream("In StoreComponent()")
        try:
            self.set_state(tango.DevState.RUNNING)
            self.xmlc.storeComponent(argin)
            self.set_state(tango.DevState.OPEN)
        finally:
            if self.get_state() == tango.DevState.RUNNING:
                self.set_state(tango.DevState.OPEN)

    def is_StoreComponent_allowed(self):
        """ StoreComponent command State Machine

        :returns: True if the operation allowed
        :rtype: :obj:`bool`
        """
        if self.get_state() in [tango.DevState.ON,
                                tango.DevState.RUNNING]:
            return False
        return True

    def StoreSelection(self, argin):
        """ StoreSelection command

        :brief: Stores the selection from XMLString

        :param argin:  DevString    selection name
        :type argin: :obj:`str`
        """
        self.debug_stream("In StoreSelection()")
        try:
            self.set_state(tango.DevState.RUNNING)
            self.xmlc.storeSelection(argin)
            self.set_state(tango.DevState.OPEN)
        finally:
            if self.get_state() == tango.DevState.RUNNING:
                self.set_state(tango.DevState.OPEN)

    def is_StoreSelection_allowed(self):
        """ StoreSelection command State Machine

        :returns: True if the operation allowed
        :rtype: :obj:`bool`
        """
        if self.get_state() in [tango.DevState.ON,
                                tango.DevState.RUNNING]:
            return False
        return True

    def StoreDataSource(self, argin):
        """ StoreDataSource command

        :brief: Stores the DataSource from XMLString

        :param argin:  DevString    datasource name
        :type argin: :obj:`str`
        """
        self.debug_stream("In StoreDataSource()")
        try:
            self.set_state(tango.DevState.RUNNING)
            self.xmlc.storeDataSource(argin)
            self.set_state(tango.DevState.OPEN)
        finally:
            if self.get_state() == tango.DevState.RUNNING:
                self.set_state(tango.DevState.OPEN)

    def is_StoreDataSource_allowed(self):
        """ StoreDataSource command State Machine

        :returns: True if the operation allowed
        :rtype: :obj:`bool`
        """
        if self.get_state() in [tango.DevState.ON,
                                tango.DevState.RUNNING]:
            return False
        return True

    def CreateConfiguration(self, argin):
        """ CreateConfiguration command

        :brief: Creates the NDTS configuration script from the
                given components. The result is strored in XMLString
                and MergedXML

        :param argin:  DevVarStringArray    list of component names
        :type argin: :obj:`list` <:obj:`str`>
        """
        self.debug_stream("In CreateConfiguration()")
        try:
            self.set_state(tango.DevState.RUNNING)
            self.xmlc.createConfiguration(argin)
            self.set_state(tango.DevState.OPEN)
        finally:
            if self.get_state() == tango.DevState.RUNNING:
                self.set_state(tango.DevState.OPEN)

    def is_CreateConfiguration_allowed(self):
        """ CreateConfiguration command State Machine

        :returns: True if the operation allowed
        :rtype: :obj:`bool`
        """
        if self.get_state() in [tango.DevState.ON,
                                tango.DevState.RUNNING]:
            return False
        return True

    def DeleteComponent(self, argin):
        """ DeleteComponent command

        :brief: Deletes the given component

        :param argin:  DevString    component name
        :type argin: :obj:`str`
        """
        self.debug_stream("In DeleteComponent()")
        try:
            self.set_state(tango.DevState.RUNNING)
            self.xmlc.deleteComponent(argin)
            self.set_state(tango.DevState.OPEN)
        finally:
            if self.get_state() == tango.DevState.RUNNING:
                self.set_state(tango.DevState.OPEN)

    def is_DeleteComponent_allowed(self):
        """ DeleteComponent command State Machine

        :returns: True if the operation allowed
        :rtype: :obj:`bool`
        """
        if self.get_state() in [tango.DevState.ON,
                                tango.DevState.RUNNING]:
            return False
        return True

    def DeleteSelection(self, argin):
        """ DeleteSelection command

        :brief: Deletes the given selection

        :param argin:  DevString    selection name
        :type argin: :obj:`str`
        """
        self.debug_stream("In DeleteSelection()")
        try:
            self.set_state(tango.DevState.RUNNING)
            self.xmlc.deleteSelection(argin)
            self.set_state(tango.DevState.OPEN)
        finally:
            if self.get_state() == tango.DevState.RUNNING:
                self.set_state(tango.DevState.OPEN)

    def is_DeleteSelection_allowed(self):
        """ DeleteSelection command State Machine

        :returns: True if the operation allowed
        :rtype: :obj:`bool`
        """
        if self.get_state() in [tango.DevState.ON,
                                tango.DevState.RUNNING]:
            return False
        return True

    def DeleteDataSource(self, argin):
        """ DeleteDataSource command

        :brief: Deletes the given datasource

        :param argin:  DevString    datasource name
        :type argin: :obj:`str`
        """
        self.debug_stream("In DeleteDataSource()")
        #    Add your own code here
        try:
            self.set_state(tango.DevState.RUNNING)
            self.xmlc.deleteDataSource(argin)
            self.set_state(tango.DevState.OPEN)
        finally:
            if self.get_state() == tango.DevState.RUNNING:
                self.set_state(tango.DevState.OPEN)

    def is_DeleteDataSource_allowed(self):
        """ DeleteDataSource command State Machine

        :returns: True if the operation allowed
        :rtype: :obj:`bool`
        """
        if self.get_state() in [tango.DevState.ON,
                                tango.DevState.RUNNING]:
            return False
        return True

    def SetComponentDataSources(self, argin):
        """ SetComponentDataSources command

        :brief: Sets component datasources according to given dictionary

        :param argin:  DevString   JSON dict { comp1: {ds: tds, ...}, ...}
        :type argin: :obj:`str`
        """
        self.debug_stream("In SetComponentDataSources()")
        try:
            self.set_state(tango.DevState.RUNNING)
            self.xmlc.setComponentDataSources(argin)
            self.set_state(tango.DevState.OPEN)
        finally:
            if self.get_state() == tango.DevState.RUNNING:
                self.set_state(tango.DevState.OPEN)

    def is_SetComponentDataSources_allowed(self):
        """ SetComponentDataSources command State Machine

        :returns: True if the operation allowed
        :rtype: :obj:`bool`
        """
        if self.get_state() in [tango.DevState.ON,
                                tango.DevState.RUNNING]:
            return False
        return True

    def SetMandatoryComponents(self, argin):
        """ SetMandatoryComponents command

        :brief: Sets the mandatory components

        :param argin:  DevVarStringArray    component names
        :type argin: :obj:`list` <:obj:`str`>
        """
        self.debug_stream("In SetMandatoryComponents()")
        try:
            self.set_state(tango.DevState.RUNNING)
            self.xmlc.setMandatoryComponents(argin)
            self.set_state(tango.DevState.OPEN)
        finally:
            if self.get_state() == tango.DevState.RUNNING:
                self.set_state(tango.DevState.OPEN)

    def is_SetMandatoryComponents_allowed(self):
        """ SetMandatoryComponents command State Machine

        :returns: True if the operation allowed
        :rtype: :obj:`bool`
        """
        if self.get_state() in [tango.DevState.ON,
                                tango.DevState.RUNNING]:
            return False
        return True

    def MandatoryComponents(self):
        """ MandatoryComponents command

        :brief: Returns the mandatory components

        :returns: DevVarStringArray    component names
        :rtype: :obj:`list` <:obj:`str`>
        """
        self.debug_stream("In MandatoryComponents()")

        try:
            self.set_state(tango.DevState.RUNNING)
            argout = self.xmlc.mandatoryComponents()
            self.set_state(tango.DevState.OPEN)
        finally:
            if self.get_state() == tango.DevState.RUNNING:
                self.set_state(tango.DevState.OPEN)
        return argout

    def is_MandatoryComponents_allowed(self):
        """ MandatoryComponents command State Machine

        :returns: True if the operation allowed
        :rtype: :obj:`bool`
        """
        if self.get_state() in [tango.DevState.ON,
                                tango.DevState.RUNNING]:
            return False
        return True

    def UnsetMandatoryComponents(self, argin):
        """ UnsetMandatoryComponents command

        :brief: Removes the given components
                from the mandatory components

        :param argin:  DevVarStringArray    list of component names
        :type argin: :obj:`list` <:obj:`str`>
        """
        self.debug_stream("In UnsetMandatoryComponents()")
        try:
            self.set_state(tango.DevState.RUNNING)
            self.xmlc.unsetMandatoryComponents(argin)
            self.set_state(tango.DevState.OPEN)
        finally:
            if self.get_state() == tango.DevState.RUNNING:
                self.set_state(tango.DevState.OPEN)

    def is_UnsetMandatoryComponents_allowed(self):
        """ UnsetMandatoryComponents command State Machine

        :returns: True if the operation allowed
        :rtype: :obj:`bool`
        """
        if self.get_state() in [tango.DevState.ON,
                                tango.DevState.RUNNING]:
            return False
        return True

    def ComponentDataSources(self, argin):
        """ ComponentDataSources command

        :brief: Returns a list of datasource names for a given component

        :param argin:  DevString    component name
        :type argin: :obj:`str`
        :returns: DevVarStringArray    list of datasource names
        :rtype: :obj:`list` <:obj:`str`>
        """
        self.debug_stream("In ComponentDataSources()")
        try:
            self.set_state(tango.DevState.RUNNING)
            argout = self.xmlc.componentDataSources(argin)
            self.set_state(tango.DevState.OPEN)
        finally:
            if self.get_state() == tango.DevState.RUNNING:
                self.set_state(tango.DevState.OPEN)

        return argout

    def is_ComponentDataSources_allowed(self):
        """ ComponentDataSources command State Machine

        :returns: True if the operation allowed
        :rtype: :obj:`bool`
        """
        if self.get_state() in [tango.DevState.ON,
                                tango.DevState.RUNNING]:
            return False
        return True

    def ComponentsDataSources(self, argin):
        """ ComponentsDataSources command

        :brief: Returns a list of datasource names for a given components

        :param argin:  DevVarStringArray    component names
        :type argin: :obj:`list` <:obj:`str`>
        :returns: DevVarStringArray    list of datasource names
        :rtype: :obj:`list` <:obj:`str`>
        """
        self.debug_stream("In ComponentsDataSources()")
        try:
            self.set_state(tango.DevState.RUNNING)
            argout = self.xmlc.componentsDataSources(argin)
            self.set_state(tango.DevState.OPEN)
        finally:
            if self.get_state() == tango.DevState.RUNNING:
                self.set_state(tango.DevState.OPEN)

        return argout

    def is_ComponentsDataSources_allowed(self):
        """ComponentsDataSources command State Machine

        :returns: True if the operation allowed
        :rtype: :obj:`bool`
        """
        if self.get_state() in [tango.DevState.ON,
                                tango.DevState.RUNNING]:
            return False
        return True

    def ComponentsVariables(self, argin):
        """ ComponentsVariables command

        :brief: Returns a list of variable names for a given components

        :param argin:  DevVarStringArray    component names
        :type argin: :obj:`list` <:obj:`str`>
        :returns: DevVarStringArray    list of variable names
        :rtype: :obj:`list` <:obj:`str`>
        """
        self.debug_stream("In ComponentsVariables()")
        try:
            self.set_state(tango.DevState.RUNNING)
            argout = self.xmlc.componentsVariables(argin)
            self.set_state(tango.DevState.OPEN)
        finally:
            if self.get_state() == tango.DevState.RUNNING:
                self.set_state(tango.DevState.OPEN)

        return argout

    def is_ComponentsVariables_allowed(self):
        """ ComponentsVariables command State Machine

        :returns: True if the operation allowed
        :rtype: :obj:`bool`
        """
        if self.get_state() in [tango.DevState.ON,
                                tango.DevState.RUNNING]:
            return False
        return True

    def ComponentVariables(self, argin):
        """ ComponentVariables command

        :brief: Returns a list of variable names for a given component

        :param argin:  DevString    component name
        :type argin: :obj:`str`
        :returns: DevVarStringArray    list of variable names
        :rtype: :obj:`list` <:obj:`str`>
        """
        self.debug_stream("In ComponentVariables()")
        try:
            self.set_state(tango.DevState.RUNNING)
            argout = self.xmlc.componentVariables(argin)
            self.set_state(tango.DevState.OPEN)
        finally:
            if self.get_state() == tango.DevState.RUNNING:
                self.set_state(tango.DevState.OPEN)

        return argout

    def is_ComponentVariables_allowed(self):
        """ ComponentVariables command State Machine

        :returns: True if the operation allowed
        :rtype: :obj:`bool`
        """
        if self.get_state() in [tango.DevState.ON,
                                tango.DevState.RUNNING]:
            return False
        return True

    def Merge(self, argin):
        """ Merge command

        :brief: Merges give components

        :param argin:  DevVarStringArray    list of component names
        :type argin: :obj:`list` <:obj:`str`>
        :returns: DevString    merged components
        :rtype: :obj:`str`
        """
        self.debug_stream("In Merge()")
        try:
            self.set_state(tango.DevState.RUNNING)
            argout = self.xmlc.merge(argin)
            self.set_state(tango.DevState.OPEN)
        finally:
            if self.get_state() == tango.DevState.RUNNING:
                self.set_state(tango.DevState.OPEN)
        return argout

    def is_Merge_allowed(self):
        """ Merge command State Machine

        :returns: True if the operation allowed
        :rtype: :obj:`bool`
        """
        if self.get_state() in [tango.DevState.ON,
                                tango.DevState.RUNNING]:
            return False
        return True

    def DependentComponents(self, argin):
        """ DependentComponents command

        :brief: returns a list of dependent component names
            for a given components

        :param argin:  DevVarStringArray    component names
        :type argin: :obj:`list` <:obj:`str`>
        :returns: DevVarStringArray    list of component names
        :rtype: :obj:`list` <:obj:`str`>
        """
        self.debug_stream("In DependentComponents()")
        try:
            self.set_state(tango.DevState.RUNNING)
            argout = self.xmlc.dependentComponents(argin)
            self.set_state(tango.DevState.OPEN)
        finally:
            if self.get_state() == tango.DevState.RUNNING:
                self.set_state(tango.DevState.OPEN)

        return argout

    def is_DependentComponents_allowed(self):
        """ DependentComponents command State Machine

        :returns: True if the operation allowed
        :rtype: :obj:`bool`
        """
        if self.get_state() in [tango.DevState.ON,
                                tango.DevState.RUNNING]:
            return False
        return True


class NXSConfigServerClass(tango.DeviceClass):

    """ NXSConfigServerClass class definition
    """

    #: (:obj:`dict` <:obj:`str`, \
    #:       [ :obj:`str`, :class:`tango.CmdArgType`, \
    #:       [ :obj:`list` <:obj:`int`> ] ] > ) Class Properties
    class_property_list = {
    }

    #: (:obj:`dict` <:obj:`str`, \
    #:       [ :obj:`str`, :class:`tango.CmdArgType`, \
    #:       [ :obj:`list` <:obj:`int`> ] ] > ) Device Properties
    device_property_list = {
        'VersionLabel':
        [tango.DevString,
         "version label",
         ["XCS"]],
        'ExtraLinkPath':
        [tango.DevString,
         "extra link NeXus path below NXentry. "
         "Default: instrument:NXinstrument/collection:NXcollection",
         ["instrument:NXinstrument/collection:NXcollection"]],
    }

    #: (:obj:`dict` <:obj:`str`, \
    #:       [[ :class:`tango.CmdArgType`, :obj:`str`]] >)
    #:       Command definitions
    cmd_list = {
        'Open':
            [[tango.DevVoid, ""],
             [tango.DevVoid, ""]],
        'Close':
            [[tango.DevVoid, ""],
             [tango.DevVoid, ""]],
        'Components':
            [[tango.DevVarStringArray, "list of component names"],
             [tango.DevVarStringArray, "list of required components"]],
        'Selections':
            [[tango.DevVarStringArray, "list of selection names"],
             [tango.DevVarStringArray, "list of required selections"]],
        'InstantiatedComponents':
            [[tango.DevVarStringArray, "list of component names"],
             [tango.DevVarStringArray, "list of instantiated components"]],
        'InstantiatedDataSources':
            [[tango.DevVarStringArray, "list of component names"],
             [tango.DevVarStringArray, "list of instantiated datasources"]],
        'DataSources':
            [[tango.DevVarStringArray, "list of DataSource names"],
             [tango.DevVarStringArray, "list of required DataSources"]],
        'AvailableComponents':
            [[tango.DevVoid, ""],
             [tango.DevVarStringArray, "list of available component names"]],
        'AvailableSelections':
            [[tango.DevVoid, ""],
             [tango.DevVarStringArray, "list of available selection names"]],
        'AvailableDataSources':
            [[tango.DevVoid, ""],
             [tango.DevVarStringArray,
              "list of available DataSource names"]],
        'StoreSelection':
            [[tango.DevString, "selection name"],
             [tango.DevVoid, ""]],
        'StoreComponent':
            [[tango.DevString, "component name"],
             [tango.DevVoid, ""]],
        'StoreDataSource':
            [[tango.DevString, "datasource name"],
             [tango.DevVoid, ""]],
        'CreateConfiguration':
            [[tango.DevVarStringArray, "list of component names"],
             [tango.DevVoid, ""]],
        'DeleteComponent':
            [[tango.DevString, "component name"],
             [tango.DevVoid, ""]],
        'DeleteSelection':
            [[tango.DevString, "selection name"],
             [tango.DevVoid, ""]],
        'DeleteDataSource':
            [[tango.DevString, "datasource name"],
             [tango.DevVoid, ""]],
        'SetComponentDataSources':
            [[tango.DevString, "JSON dict {comp1: {tds1: ds1, ...}, ...}"],
             [tango.DevVoid, ""]],
        'SetMandatoryComponents':
            [[tango.DevVarStringArray, "component names"],
             [tango.DevVoid, ""]],
        'MandatoryComponents':
            [[tango.DevVoid, ""],
             [tango.DevVarStringArray, "component names"]],
        'UnsetMandatoryComponents':
            [[tango.DevVarStringArray, "list of component names"],
             [tango.DevVoid, ""]],
        'ComponentDataSources':
            [[tango.DevString, "component name"],
             [tango.DevVarStringArray, "list of datasource names"]],
        'ComponentsDataSources':
            [[tango.DevVarStringArray, "component names"],
             [tango.DevVarStringArray, "list of datasource names"]],
        'ComponentsVariables':
            [[tango.DevVarStringArray, "component names"],
             [tango.DevVarStringArray, "list of variable names"]],
        'ComponentVariables':
            [[tango.DevString, "component name"],
             [tango.DevVarStringArray, "list of variable names"]],
        'Merge':
            [[tango.DevVarStringArray, "list of component names"],
             [tango.DevString, "merged components"]],
        'DependentComponents':
            [[tango.DevVarStringArray, "component names"],
             [tango.DevVarStringArray, "list of component names"]],
    }

    #: (:obj:`dict` <:obj:`str`, \
    #       [ [ \
    #          :class:`tango.CmdArgType`,
    #          :class:`tango.AttrDataFormat`,
    #          :class:`tango.AttrWriteType` ],
    #          :obj:`dict` < :obj:`str` , any > ] > ) Attribute definitions
    attr_list = {
        'XMLString':
        [[tango.DevString,
          tango.SCALAR,
          tango.READ_WRITE],
         {
             'label': "XML Configuration",
             'description':
             "It allows to pass XML strings into database during "
             "performing StoreComponent and StoreDataSource."
             "\nMoreover, after performing CreateConfiguration "
             "it contains the resulting XML configuration.",
             'Display level': tango.DispLevel.EXPERT,
        }],
        'MergedXML':
        [[tango.DevString,
          tango.SCALAR,
          tango.READ],
         {
             'label': "XML for merged components",
             'description':
             "XML for merged components without applied variables ",
             'Display level': tango.DispLevel.EXPERT,
         }],
        'Selection':
        [[tango.DevString,
          tango.SCALAR,
          tango.READ_WRITE],
         {
            'label': "Selected Component",
            'description':
            "It allows to pass JSON strings into database during "
            "performing StoreSelection.",
            'Display level': tango.DispLevel.EXPERT,
        }],
        'JSONSettings':
        [[tango.DevString,
          tango.SCALAR,
          tango.READ_WRITE],
         {
             'label': "Arguments of MySQLdb.connect(...)",
             'description': "The JSON string with parameters of "
             "MySQLdb.connect(...).",
             'Memorized': "true",
             'Display level': tango.DispLevel.EXPERT,
        }],
        'Version':
        [[tango.DevString,
          tango.SCALAR,
          tango.READ],
         {
             'label': "Configuration Version",
             'description': "Configuration version",
        }],
        'Variables':
        [[tango.DevString,
          tango.SCALAR,
          tango.READ_WRITE],
         {
             'label': "XML Configuration Variables",
             'description': "The JSON string with "
             "XML configuration variables",
        }],
        'STEPDataSources':
        [[tango.DevString,
          tango.SCALAR,
          tango.READ_WRITE],
         {
             'label': "Datasources to be switched into STEP Mode",
             'description': "JSON list of datasources to be switched "
             "into STEP mode during creating configuration process",
        }],
        'LinkDataSources':
        [[tango.DevString,
          tango.SCALAR,
          tango.READ_WRITE],
         {
             'label': "Datasources to which links will be added",
             'description': "JSON list of datasources"
             "to which links will be added",
        }],
        'ExtraLinkDataSources':
        [[tango.DevString,
          tango.SCALAR,
          tango.READ_WRITE],
         {
             'label': "Datasources to which extra links will be added",
             'description': "JSON list of datasources"
             "to which extra links will be added",
        }],
        'CanFailDataSources':
        [[tango.DevString,
          tango.SCALAR,
          tango.READ_WRITE],
         {
             'label': "Datasources to be switched into CanFail Mode",
             'description': "JSON list of datasources to be switched "
             "into CanFail mode during creating configuration process",
        }],
    }

    def __init__(self, name):
        """ NXSConfigServerClass Constructor
        """
        tango.DeviceClass.__init__(self, name)
        self.set_type(name)
        print("In NXSConfigServerClass  constructor")


#    NXSConfigServer class main method
if __name__ == '__main__':
    pass
