public function prepare()
    {
        if (empty($this->targetBundle) && empty($this->bundleExtensionDir)) {
            throw new \RuntimeException(sprintf(
                "Runtime Error: Any Bundle was selected for ui generation."
            ));
        }

        // load reader from factory
        $this->reader = $this->readerFactory->load($this->metaFile);
        $elementType = $this->reader->getElement()->getXtype();

        $bundleDir = empty($this->targetBundle)
            ? $this->bundleExtensionDir . DS . $elementType . DS
            : $this->bundleExtensionDir . DS . $this->targetBundle . DS . $elementType . DS;

        if (! file_exists($bundleDir . 'components.genscript') && ! file_exists($bundleDir . 'mapping.php')) {
            $bundleDir = __DIR__ . DS . 'bundle' . DS . $this->targetBundle . DS . $elementType . DS;
            if (! file_exists($bundleDir . 'components.genscript') && ! file_exists($bundleDir . 'mapping.php')) {
                throw new \Exception(sprintf("Error: Bundle '%s' does not exist!.", $this->targetBundle));
            }
        }

        $genscriptFilename = $bundleDir . 'components.genscript';
        $mappingFilename   = $bundleDir . 'mapping.php';

        //verify if the bundle is registered
        if (! file_exists($genscriptFilename)) {
            throw new \Exception(sprintf("Error: genscript file for '%s' bundle is missing.", $this->targetBundle));
        }

        if (! file_exists($genscriptFilename)) {
            throw new \Exception(sprintf("Error: mapping file for '%s' bundle is missing.", $this->targetBundle));
        }

        if (! file_exists($this->metaFile)) {
            throw new \Exception(sprintf("Error: meta file '%s' does not exist.", $this->metaFile));
        }

        $this->parser->setScriptFile($genscriptFilename);
        $this->parser->parse();
        $this->mapping = file_exists($mappingFilename) ? include($mappingFilename) : null;
    }