import importlib


def data_node_from_schema(schema_node, module_name, parent, data_storage=None,
                          new_params=None):
    """Create a new data node from a given schema node.

    Finds the data node class corresponding to the given schema node and
    creates an instance. However, the module containing the data node class
    must be given, which allows to select the desired storage backend.

    If ``data_storage`` is given, the new data node is initialized from that
    storage object. Otherwise, a new data node with a new storage object is
    created. Backends may use a ``new_params`` object to supply parameters
    for new data node creation.

    Args:
        schema_node: Schema node instance to create a data node for.
        module_name (str): The full module name of the data storage backend.
        parent: Parent data node object.
        data_storage: Backend-specific data storage object to load.
        new_params: Backend-specific metadata for data node creation.

    Returns:
        Data node corresponding to the given schema node.
    """
    backend_module = importlib.import_module(module_name)
    node_type_name = type(schema_node).__name__
    data_node_type = getattr(backend_module, node_type_name)
    return data_node_type(schema_node, parent, data_storage=data_storage,
                          new_params=new_params)