public function setSelection(SwatViewSelection $selection, $selector = null)
    {
        if ($selector === null) {
            if (count($this->selectors) > 0) {
                $selector = reset($this->selectors);
            } else {
                throw new SwatException(
                    'This view does not have any selectors.'
                );
            }
        } elseif (is_string($selector)) {
            if (isset($this->selectors[$selector])) {
                $selector = $this->selectors[$selector];
            } else {
                throw new SwatObjectNotFoundException(
                    'Selector with an id ' .
                        "of {$selector} does not exist in this view.",
                    0,
                    $selector
                );
            }
        } elseif (!($selector instanceof SwatViewSelector)) {
            throw new SwatInvalidClassException(
                'Specified object is not a SwatViewSelector object.',
                0,
                $selector
            );
        } elseif (!isset($this->selections[$selector->getId()])) {
            throw new SwatException(
                'Specified SwatViewSelector is not a selector of this view.'
            );
        }

        $this->selections[$selector->getId()] = $selection;
    }