public function getComponentsByClassName($classNames, $recursive = true)
    {
        if (gettype($classNames) !== 'string' && !is_array($classNames)) {
            $msg = "The QtiComponent::getComponentsByClassName method only accepts ";
            $msg.= "a string or an array as its main argument, '" . gettype($classNames) . "' given.";
            throw new InvalidArgumentException($classNames);
        }

        if (!is_array($classNames)) {
            $classNames = array($classNames);
        }

        $toIterate = ($recursive === true) ? $this->getIterator() : $this->getComponents();
        $foundComponents = new QtiComponentCollection();

        foreach ($toIterate as $component) {
            if (in_array($component->getQtiClassName(), $classNames)) {
                $foundComponents[] = $component;
            }
        }

        return $foundComponents;
    }