Marshall a Param object into a DOMElement object.

@param \qtism\data\QtiComponent $component A Param object.
@return \DOMElement The according DOMElement object.
@throws \qtism\data\storage\xml\marshalling\MarshallingException
422723
protected function marshall(QtiComponent $component)
    {
        $element = self::getDOMCradle()->createElement('param');
        $this->setDOMElementAttribute($element, 'name', $component->getName());
        $this->setDOMElementAttribute($element, 'value', $component->getValue());
        $this->setDOMElementAttribute($element, 'valuetype', ParamType::getNameByConstant($component->getValueType()));

        if ($component->hasType() === true) {
            $this->setDOMElementAttribute($element, 'type', $component->getType());
        }

        return $element;
    }
759051
public static XContentBuilder marshall(GatewayBean bean) throws StorageException {
        try (XContentBuilder builder = XContentFactory.jsonBuilder()) {
            preMarshall(bean);
            builder
                .startObject()
                    .field("id", bean.getId())
                    .field("name", bean.getName())
                    .field("description", bean.getDescription())
                    .field("type", bean.getType())
                    .field("configuration", bean.getConfiguration())
                    .field("createdBy", bean.getCreatedBy())
                    .field("createdOn", bean.getCreatedOn().getTime())
                    .field("modifiedBy", bean.getModifiedBy())
                    .field("modifiedOn", bean.getModifiedOn().getTime())
                .endObject();
            postMarshall(bean);
            return builder;
        } catch (IOException e) {
            throw new StorageException(e);
        }
    }
1284484
public function marshall(QtiComponent $component)
    {
        $element = self::getDOMCradle()->createElement($component->getQtiClassName());
        $this->setDOMElementAttribute($element, 'identifier', $component->getIdentifier());
        $this->setDOMElementAttribute($element, 'minConstraint', $component->getMinConstraint());
        $this->setDOMElementAttribute($element, 'maxConstraint', $component->getMaxConstraint());

        return $element;
    }
1067539
protected function createFinalRendering(QtiComponent $component)
    {
        $dom = $this->getDocument();
        if (($last = $this->getLastRendering()) !== null) {
            $dom->appendChild($last);
        }

        // If we are rendering an item, let's try to find some Math to
        // for template variable mapping. 
        if ($component instanceof AssessmentItem && count($templateDeclarations = $component->getTemplateDeclarations()) > 0) {
            $xpath = new DOMXPath($dom);
            $xpath->registerNamespace('m', 'http://www.w3.org/1998/Math/MathML');
            $maths = $xpath->query('//m:math|//math');
            
            if ($maths->length > 0) {
                $printedVariableRenderer = new PrintedVariableRenderer($this);
                
                foreach ($templateDeclarations as $templateDeclaration) {
                    if ($templateDeclaration->isMathVariable() === true) {
                        $templateIdentifier = $templateDeclaration->getIdentifier();
                        
                        foreach ($maths as $math) {
                            // Find <mi> and <ci> elements.
                            foreach ($xpath->query(".//m:mi[text() = '${templateIdentifier}']|.//m:ci[text() = '${templateIdentifier}']|.//mi[text() = '${templateIdentifier}']|.//ci[text() = '${templateIdentifier}']", $math) as $mathElement) {
                                $localElementName = ($mathElement->localName === 'mi') ? 'mn' : 'cn';
                                $newMathElement = $mathElement->ownerDocument->createElement($localElementName);
                                $printedVariable = new PrintedVariable($templateIdentifier);
                                $printedVariableFragment = $printedVariableRenderer->render($printedVariable);
                                
                                if ($this->getPrintedVariablePolicy() === self::CONTEXT_STATIC) {
                                    foreach ($printedVariableFragment->childNodes as $node) {
                                        $newMathElement->appendChild($node);
                                        $mathElement->parentNode->replaceChild($newMathElement, $mathElement);
                                    }
                                } else if ($this->getPrintedVariablePolicy() === self::CONTEXT_AWARE) {
                                    $newMathElement->appendChild($newMathElement->ownerDocument->createTextNode($printedVariableFragment->firstChild->nodeValue));
                                    $mathElement->parentNode->replaceChild($newMathElement, $mathElement);
                                } else {
                                    foreach ($printedVariableFragment->firstChild->childNodes as $node) {
                                        $newMathElement->appendChild($node);
                                        $mathElement->parentNode->replaceChild($newMathElement, $mathElement);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }

        return $dom;
    }
217581
public static XContentBuilder marshall(PluginBean bean) throws StorageException {
        try (XContentBuilder builder = XContentFactory.jsonBuilder()) {
            preMarshall(bean);
            builder
                .startObject()
                    .field("id", bean.getId())
                    .field("name", bean.getName())
                    .field("description", bean.getDescription())
                    .field("createdBy", bean.getCreatedBy())
                    .field("createdOn", bean.getCreatedOn().getTime())
                    .field("groupId", bean.getGroupId())
                    .field("artifactId", bean.getArtifactId())
                    .field("version", bean.getVersion())
                    .field("classifier", bean.getClassifier())
                    .field("type", bean.getType())
                    .field("deleted", bean.isDeleted())
                .endObject();
            postMarshall(bean);
            return builder;
        } catch (IOException e) {
            throw new StorageException(e);
        }
    }
653300
public function marshall()
    {
        $toMarshall = $this->getToMarshall();

        try {
            if ($toMarshall instanceof QtiCoords) {
                $this->marshallCoords();

                return;
            } elseif ($toMarshall instanceof QtiPair) {
                $this->marshallPair();

                return;
            } elseif ($toMarshall instanceof QtiDuration) {
                $this->marshallDuration();

                return;
            } elseif ($toMarshall instanceof QtiPoint) {
                $this->marshallPoint();

                return;
            } else if ($toMarshall instanceof QtiIdentifier) {
                $this->marshallIdentifier();
                
                return;
            }
        } catch (PhpMarshallingException $e) {
            $msg = "An error occured while marshalling a QtiDatatype object.";
            throw new PhpMarshallingException($msg, PhpMarshallingException::RUNTIME, $e);
        }

        $className = get_class($toMarshall);
        $msg = "Cannot deal with QtiDatatype '${className}'.";
        throw new PhpMarshallingException($msg, PhpMarshallingException::RUNTIME);
    }
524072
public function marshall()
    {
        $ctx = $this->getContext();
        $access = $ctx->getStreamAccess();
        $array = $this->getToMarshall();
        $args = new PhpArgumentCollection();

        foreach ($array as $a) {
            if (PhpUtils::isScalar($a) === false) {
                $msg = "The PhpArrayMarshaller class only deals with PHP scalar values, object or resource given.";
                throw new PhpMarshallingException($msg);
            }

            $args[] = new PhpArgument($a);
        }

        $arrayVarName = $ctx->generateVariableName($array);
        $access->writeVariable($arrayVarName);
        $access->writeEquals($ctx->mustFormatOutput());
        $access->writeFunctionCall('array', $args);
        $access->writeSemicolon($ctx->mustFormatOutput());

        $ctx->pushOnVariableStack($arrayVarName);
    }
566126
public function getComponent($component)
    {
        if (isset($this->_components[$component])) {
            return self::createComponents($this->_components[$component]);
        } else {
            throw new \Exception($component . '组件不存在');
        }
    }
187941
public static XContentBuilder marshall(RoleMembershipBean bean) throws StorageException {
        try (XContentBuilder builder = XContentFactory.jsonBuilder()) {
            preMarshall(bean);
            builder
                .startObject()
                    .field("id", bean.getId())
                    .field("organizationId", bean.getOrganizationId())
                    .field("roleId", bean.getRoleId())
                    .field("userId", bean.getUserId())
                    .field("createdOn", bean.getCreatedOn().getTime())
                .endObject();
            postMarshall(bean);
            return builder;
        } catch (IOException e) {
            throw new StorageException(e);
        }
    }
697636
protected function marshall(QtiComponent $component)
    {
        $element = parent::marshall($component);
        $version = $this->getVersion();

        // deal with views.
        // !!! If $arrayViews contain all possible views, it means that the treated
        // !!! outcome is relevant to all views, as per QTI 2.1 spec.
        if (Version::compare($version, '2.1.0', '>=') === true && !in_array($component->getViews()->getArrayCopy(), View::asArray())) {
            $arrayViews = array();
            foreach ($component->getViews() as $view) {
                $arrayViews[] = View::getNameByConstant($view);
            }

            if (count($arrayViews) > 0) {
                $this->setDOMElementAttribute($element, 'view', implode("\x20", $arrayViews));
            }
        }

        // deal with interpretation.
        if ($component->getInterpretation() != '') {
            $this->setDOMElementAttribute($element, 'interpretation', $component->getInterpretation());
        }

        // deal with long interpretation.
        if ($component->getLongInterpretation() != '') {
            $this->setDOMElementAttribute($element, 'longInterpretation', $component->getLongInterpretation());
        }

        // Deal with normal maximum.
        if ($component->getNormalMaximum() !== false) {
            $this->setDOMElementAttribute($element, 'normalMaximum', $component->getNormalMaximum());
        }

        // Deal with normal minimum.
        if (Version::compare($version, '2.1.0', '>=') === true && $component->getNormalMinimum() !== false) {
            $this->setDOMElementAttribute($element, 'normalMinimum', $component->getNormalMinimum());
        }

        // Deal with mastery value.
        if (Version::compare($version, '2.1.0', '>=') === true && $component->getMasteryValue() !== false) {
            $this->setDOMElementAttribute($element, 'masteryValue', $component->getMasteryValue());
        }

        // Deal with lookup table.
        if ($component->getLookupTable() != null) {
            $lookupTableMarshaller = $this->getMarshallerFactory()->createMarshaller($component->getLookupTable(), array($component->getBaseType()));
            $element->appendChild($lookupTableMarshaller->marshall($component->geTLookupTable()));
        }

        return $element;
    }
1326148
public function addComponent(ComponentInterface $component)
    {
        $this->getComponents()->push($component);
        $component->attachTo($this);
        return $this;
    }
778688
public function setComponent($componentName, $item)
    {
        // Validate component
        $schema = static::getSchema();
        if ($class = $schema->hasOneComponent(static::class, $componentName)) {
            // Force item to be written if not by this point
            // @todo This could be lazy-written in a beforeWrite hook, but force write here for simplicity
            // https://github.com/silverstripe/silverstripe-framework/issues/7818
            if ($item && !$item->isInDB()) {
                $item->write();
            }

            // Update local ID
            $joinField = $componentName . 'ID';
            $this->setField($joinField, $item ? $item->ID : null);
            // Update Class (Polymorphic has_one)
            // Extract class name for polymorphic relations
            if ($class === self::class) {
                $this->setField($componentName . 'Class', $item ? get_class($item) : null);
            }
        } elseif ($class = $schema->belongsToComponent(static::class, $componentName)) {
            if ($item) {
                // For belongs_to, add to has_one on other component
                $joinField = $schema->getRemoteJoinField(static::class, $componentName, 'belongs_to', $polymorphic);
                if (!$polymorphic) {
                    $joinField = substr($joinField, 0, -2);
                }
                $item->setComponent($joinField, $this);
            }
        } else {
            throw new InvalidArgumentException(
                "DataObject->setComponent(): Could not find component '$componentName'."
            );
        }

        $this->components[$componentName] = $item;
        return $this;
    }
441028
protected function marshall(QtiComponent $component)
    {
        $element = static::getDOMCradle()->createElement($component->getQtiClassName());

        $this->setDOMElementAttribute($element, 'identifier', $component->getIdentifier());

        return $element;
    }
836382
public function marshall(QtiComponent $component)
    {
        $element = self::getDOMCradle()->createElement('modalFeedbackRule');
        $this->setDOMElementAttribute($element, 'outcomeIdentifier', $component->getOutcomeIdentifier());
        $this->setDOMElementAttribute($element, 'showHide', ShowHide::getNameByConstant($component->getShowHide()));
        $this->setDOMElementAttribute($element, 'identifier', $component->getIdentifier());
        
        if ($component->hasTitle() === true) {
            $this->setDOMElementAttribute($element, 'title', $component->getTitle());
        }

        return $element;
    }
895237
public function update(Component $component)
    {
        try {
            execute(new UpdateComponentCommand(
                $component,
                Binput::get('name'),
                Binput::get('description'),
                Binput::get('status'),
                Binput::get('link'),
                Binput::get('order'),
                Binput::get('group_id'),
                Binput::get('enabled', $component->enabled),
                Binput::get('meta', null),
                (bool) Binput::get('silent', false)
            ));
        } catch (QueryException $e) {
            throw new BadRequestHttpException();
        }

        if (Binput::has('tags')) {
            $component->tags()->delete();

            // The component was added successfully, so now let's deal with the tags.
            Collection::make(preg_split('/ ?, ?/', $tags))->map(function ($tag) {
                return trim($tag);
            })->map(function ($tag) {
                return execute(new CreateTagCommand($tag));
            })->each(function ($tag) use ($component) {
                execute(new ApplyTagCommand($component, $tag));
            });
        }

        return $this->item($component);
    }
467523
protected function marshall(QtiComponent $component)
    {
        $element = static::getDOMCradle()->createElement($component->getQtiClassName());

        $this->setDOMElementAttribute($element, 'identifier', $component->getIdentifier());

        $weightIdentifier = $component->getWeightIdentifier();
        if (!empty($weightIdentifier)) {
            $this->setDOMElementAttribute($element, 'weightIdentifier', $weightIdentifier);
        }

        return $element;
    }
625782
protected function marshall(QtiComponent $component)
    {
        $element = static::getDOMCradle()->createElement($component->getQtiClassName());

        $this->setDOMElementAttribute($element, 'name', MathEnumeration::getNameByConstant($component->getName()));

        return $element;
    }