public function getDocument()
    {
        if (null === $this->document) {
            $parent = $this->parent;
            while (true) {
                if (!$parent) {
                    break;
                }
                if ($parent->parent) {
                    $parent = $parent->parent;
                } else {
                    break;
                }
            }
            $this->document = $parent;
        }

        return $this->document;
    }