public function adminUrl($subject, $action, $parameters = array())
    {
        if (is_object($subject)) {
            $className = get_class($subject);
        } elseif (is_string($subject)) {
            $className = $subject;
            if (strpos($className, ':') !== false) {
                list($namespace, $entity) = explode(':', $className);
                $className = $this->doctrine->getAliasNamespace($namespace) . '\\' . $entity;
            }
        } else {
            throw new InvalidArgumentException("Unsupported subject, need either an object or a string");
        }

        /** @var $admin \Sonata\AdminBundle\Admin\Admin */
        $admin = $this->sonata->getAdminByClass($className);
        if (!$admin) {
            // assume the string is an admincode.
            $admin = $this->sonata->getAdminByAdminCode($className);
        }

        if (!$admin) {
            throw new InvalidArgumentException("No admin found for {$className}");
        }
        if (is_object($subject)) {
            return $admin->generateObjectUrl($action, $subject, $parameters);
        } else {
            return $admin->generateUrl($action, $parameters);
        }
    }