public function generate(BundleInterface $bundle, $document, ClassMetadataInfo $metadata)
    {
        $parts = explode('\\', $document);
        $class = array_pop($parts);

        $this->className = $class.'Type';
        $dirPath = $bundle->getPath().'/Form';
        $this->classPath = $dirPath.'/'.str_replace('\\', '/', $document).'Type.php';

        if (file_exists($this->classPath)) {
            throw new \RuntimeException(sprintf('Unable to generate the %s form class as it already exists under the %s file', $this->className, $this->classPath));
        }

        if (count($metadata->identifier) > 1) {
            throw new \RuntimeException('The form generator does not support document classes with multiple primary keys.');
        }

        $parts = explode('\\', $document);
        array_pop($parts);

        $this->renderFile('FormType.php.twig', $this->classPath, array(
            'dir' => $this->skeletonDir,
            'fields' => $this->getFieldsFromMetadata($metadata),
            'namespace' => $bundle->getNamespace(),
            'document_class' => $class,
            'document_namespace' => implode('\\', $parts),
            'form_class' => $this->className,
            'form_type_name' => strtolower(str_replace('\\', '_', $bundle->getNamespace()).($parts ? '_' : '').implode('_', $parts).'_'.$this->className),
        ));
    }