public function createMarshaller($object, array $args = array())
    {
        if ($object instanceof QtiComponent) {
            // Asking for a Marshaller...
            $qtiClassName = $object->getQtiClassName();
            
            if ($this->isWebComponentFriendly() === true && in_array($qtiClassName, Marshaller::$webComponentFriendlyClasses)) {
                $qtiClassName = XmlUtils::webComponentFriendlyClassName($qtiClassName);
            }
        } elseif ($object instanceof DOMElement) {
            // Asking for an Unmarshaller...
            $qtiClassName = $object->localName;
        }

        if (isset($qtiClassName)) {

            try {
                // Look for a mapping entry.
                if ($object instanceof DOMElement && $this->hasMappingEntry($qtiClassName, $object->namespaceURI)) {
                    $class = new ReflectionClass($this->getMappingEntry($qtiClassName, $object->namespaceURI));
                } elseif ($object instanceof ExternalQtiComponent && $this->hasMappingEntry($qtiClassName, $object->getTargetNamespace())) {
                    $class = new ReflectionClass($this->getMappingEntry($qtiClassName, $object->getTargetNamespace()));
                } elseif ($this->hasMappingEntry($qtiClassName)) {
                    $class = new ReflectionClass($this->getMappingEntry($qtiClassName));
                } else {
                    // No qtiClassName/mapping entry found.
                    $msg ="No mapping entry found for QTI class name '${qtiClassName}'.";
                    throw new MarshallerNotFoundException($msg, $qtiClassName);
                    
                }
            } catch (ReflectionException $e) {
                $msg = "No marshaller implementation could be found for component '${qtiClassName}'.";
                throw new MarshallerNotFoundException($msg, $qtiClassName, $e);
            }

            $marshaller = $this->instantiateMarshaller($class, $args);
            $marshaller->setMarshallerFactory($this);

            return $marshaller;
        } else {
            $msg = "The object argument must be a QtiComponent or a DOMElementObject, '" . gettype($object) . "' given.";
            throw new InvalidArgumentException($msg);
        }
    }