#!/usr/bin/env python

from dm.common.utility.loggingManager import LoggingManager

class ObjectUtility:

    @classmethod
    def createObjectInstance(cls, moduleName, className, constructor, importPath=None):
        logger = LoggingManager.getInstance().getLogger(cls.__name__)
        logger.debug('Creating object: %s, %s, %s' % (moduleName, className, constructor))
        if importPath is not None:
            # Add import path if it was provided
            sys.path.append[importPath]

        cmd = 'from %s import %s' % (moduleName, className)
        exec cmd
        cmd = 'objectInstance = %s' % (constructor)
        exec cmd

        if importPath is not None:
            # Remove import path that was added
            del sys.path[-1]
        return objectInstance