Marshall a Point QTI datatype object.

@throws \qtism\data\storage\php\marshalling\PhpMarshallingException
550840
protected function marshallPoint()
    {
        $point = $this->getToMarshall();
        $ctx = $this->getContext();
        $access = $ctx->getStreamAccess();

        try {
            $varName = $ctx->generateVariableName($point);
            $access->writeVariable($varName);
            $access->writeEquals($ctx->mustFormatOutput());
            $args = new PhpArgumentCollection(array(new PhpArgument($point->getX()), new PhpArgument($point->getY())));
            $access->writeInstantiation(get_class($point), $args);
            $access->writeSemicolon($ctx->mustFormatOutput());

            $ctx->pushOnVariableStack($varName);
        } catch (StreamAccessException $e) {
            $msg = "An error occured while marshalling a Point object into the PHP source code stream.";
            throw new PhpMarshallingException($msg, PhpMarshallingException::STREAM, $e);
        }
    }
783961
public String marshall() {
        if (0 == this.num_items) {
            return "";
        }
        boolean shouldPrepend = false;
        StringBuilder output = new StringBuilder(10 * this.num_items);
        // walk through the list of simple values (no key=value) first
        Iterator<String> i = this.genericValues.iterator();
        while (i.hasNext()) {
            if (shouldPrepend) {
                output.append(this.mySep);
                output.append(' ');
            }
            output.append(i.next());
            shouldPrepend = true;
        }
        // now walk through the list of key=value pairs, where value may actually
        // be multiple values
        i = this.values.keySet().iterator();
        while (i.hasNext()) {
            String key = i.next();
            List<String> vals = this.values.get(key);
            if (null == vals)
                continue;
            int size = vals.size();
            if (0 == size) {
                // ignore an empty key
                continue;
            }
            if (shouldPrepend) {
                output.append(this.mySep);
                output.append(' ');
            }
            output.append(key);
            output.append('=');
            if (1 == size) {
                output.append(vals.get(0));
            } else {
                // multiple values need to be quote wrapped
                shouldPrepend = false;
                output.append('"');
                for (int count = 0; count < size; count++) {
                    if (shouldPrepend) {
                        output.append(this.mySep);
                        output.append(' ');
                    }
                    output.append(vals.get(count));
                    shouldPrepend = true;
                }
                output.append('"');
            }
            shouldPrepend = true;
        }
        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
            Tr.debug(tc, "marshalling [" + output.toString() + "]");
        }
        return output.toString();
    }
372769
protected function marshall(QtiComponent $component)
    {
        $element = parent::marshall($component);
        $baseType = $component->getBaseType();

        if ($component->getCorrectResponse() !== null) {
            $marshaller = $this->getMarshallerFactory()->createMarshaller($component->getCorrectResponse(), array($baseType));
            $element->appendChild($marshaller->marshall($component->getCorrectResponse()));
        }

        if ($component->getMapping() !== null) {
            $marshaller = $this->getMarshallerFactory()->createMarshaller($component->getMapping(), array($baseType));
            $element->appendChild($marshaller->marshall($component->getMapping()));
        }

        if ($component->getAreaMapping() !== null) {
            $marshaller = $this->getMarshallerFactory()->createMarshaller($component->getAreaMapping());
            $element->appendChild($marshaller->marshall($component->getAreaMapping()));
        }

        return $element;
    }
125945
public void marshalling(Xdr x) {
        super.marshalling(x);
        x.putInt(_programToQuery);
        x.putInt(_programVersion);
        x.putInt(_networkProtocol);
        x.putInt(_port);
    }
1198312
private function multiPoint()
    {
        $values = array();
        $count  = $this->readCount();

        for ($i = 0; $i < $count; $i++) {
            $this->readByteOrder();

            $type = $this->readType();

            if ($this->getDimensionedPrimitive(self::WKB_TYPE_POINT) !== $type) {
                throw new UnexpectedValueException($this->getBadTypeInTypeMessage($type, self::WKB_TYPE_MULTIPOINT, array(self::WKB_TYPE_POINT)));
            }

            $values[] = $this->point();
        }

        return $values;
    }
347912
public void marshalling(Xdr xdr) {
        super.marshalling(xdr);
        xdr.putLong(_offsetToCommit);
        xdr.putUnsignedInt(_dataSizeToCommit);
    }
871082
protected function marshall(QtiComponent $component)
    {
        $element = self::getDOMCradle()->createElement('table');

        if ($component->hasSummary() === true) {
            $this->setDOMElementAttribute($element, 'summary', $component->getSummary());
        }

        if ($component->hasXmlBase() === true) {
            self::setXmlBase($element, $component->getXmlBase());
        }

        if ($component->hasCaption() === true) {
            $caption = $component->getCaption();
            $marshaller = $this->getMarshallerFactory()->createMarshaller($caption);
            $element->appendChild($marshaller->marshall($caption));
        }

        $cols = $component->getCols();
        if (count($cols) > 0) {
            foreach ($cols as $c) {
                $marshaller = $this->getMarshallerFactory()->createMarshaller($c);
                $element->appendChild($marshaller->marshall($c));
            }
        }

        $colgroups = $component->getColgroups();
        if (count($colgroups) > 0) {
            foreach ($colgroups as $c) {
                $marshaller = $this->getMarshallerFactory()->createMarshaller($c);
                $element->appendChild($marshaller->marshall($c));
            }
        }

        if ($component->hasThead() === true) {
            $thead = $component->getThead();
            $marshaller = $this->getMarshallerFactory()->createMarshaller($thead);
            $element->appendChild($marshaller->marshall($thead));
        }

        if ($component->hasTfoot() === true) {
            $tfoot = $component->getTfoot();
            $marshaller = $this->getMarshallerFactory()->createMarshaller($tfoot);
            $element->appendChild($marshaller->marshall($tfoot));
        }

        foreach ($component->getTbodies() as $tbody) {
            $marshaller = $this->getMarshallerFactory()->createMarshaller($tbody);
            $element->appendChild($marshaller->marshall($tbody));
        }

        $this->fillElement($element, $component);

        return $element;
    }
178899
protected void setMarshalledBytes() {
        int len = getName().length();
        this.marshalledBytes = new byte[len + BNFHeaders.KEY_VALUE_SEPARATOR.length];
        System.arraycopy(getByteArray(), 0, this.marshalledBytes, 0, len);
        System.arraycopy(BNFHeaders.KEY_VALUE_SEPARATOR, 0, this.marshalledBytes, len, BNFHeaders.KEY_VALUE_SEPARATOR.length);
    }
154027
protected function marshall(QtiComponent $component)
    {
        $element = self::getDOMCradle()->createElement($component->getQtiClassName());

        if ($component->hasTemplate() === true) {
            $this->setDOMElementAttribute($element, 'template', $component->getTemplate());
        }

        if ($component->hasTemplateLocation() === true) {
            $this->setDOMElementAttribute($element, 'templateLocation', $component->getTemplateLocation());
        }

        foreach ($component->getResponseRules() as $responseRule) {
            $marshaller = $this->getMarshallerFactory()->createMarshaller($responseRule);
            $element->appendChild($marshaller->marshall($responseRule));
        }

        return $element;
    }
270181
protected function marshallIdentifier()
    {
        $identifier = $this->getToMarshall();
        $ctx = $this->getContext();
        $access = $ctx->getStreamAccess();

        try {
            $varName = $ctx->generateVariableName($identifier);
            $access->writeVariable($varName);
            $access->writeEquals($ctx->mustFormatOutput());
            $args = new PhpArgumentCollection(array(new PhpArgument($identifier->getValue())));
            $access->writeInstantiation(get_class($identifier), $args);
            $access->writeSemicolon($ctx->mustFormatOutput());

            $ctx->pushOnVariableStack($varName);
        } catch (StreamAccessException $e) {
            $msg = "An error occured while marshalling an Identifier object into the PHP source code stream.";
            throw new PhpMarshallingException($msg, PhpMarshallingException::STREAM, $e);
        }
    }
162156
public function marshall(QtiComponent $component)
    {
        $element = self::getDOMCradle()->createElement('responseValidityConstraint');
        $this->setDOMElementAttribute($element, 'responseIdentifier', $component->getResponseIdentifier());
        $this->setDOMElementAttribute($element, 'minConstraint', $component->getMinConstraint());
        $this->setDOMElementAttribute($element, 'maxConstraint', $component->getMaxConstraint());
        
        if (($patternMask = $component->getPatternMask()) !== '') {
            $this->setDOMElementAttribute($element, 'patternMask', $patternMask);
        }
        
        foreach ($component->getAssociationValidityConstraints() as $associationValidityConstraint) {
            $marshaller = $this->getMarshallerFactory()->createMarshaller($associationValidityConstraint);
            $element->appendChild($marshaller->marshall($associationValidityConstraint));
        }

        return $element;
    }
115332
public function mapRawType()
	{
		if ($this->rawType == 'integer')
			$this->rawType = 'int';

		if (array_key_exists($this->rawType,self::$TYPE_MAPPING))
			$this->type = self::$TYPE_MAPPING[$this->rawType];
		else
			$this->type = self::STRING;

		return $this->type;
	}
1301974
protected function marshallDuration()
    {
        $duration = $this->getToMarshall();
        $ctx = $this->getContext();
        $access = $ctx->getStreamAccess();

        try {
            $varName = $ctx->generateVariableName($duration);
            $access->writeVariable($varName);
            $access->writeEquals($ctx->mustFormatOutput());
            $args = new PhpArgumentCollection(array(new PhpArgument($duration->__toString())));
            $access->writeInstantiation(get_class($duration), $args);
            $access->writeSemiColon($ctx->mustFormatOutput());

            $ctx->pushOnVariableStack($varName);
        } catch (StreamAccessException $e) {
            $msg = "An error occured while marshalling a Duration object into the PHP source code stream.";
            throw new PhpMarshallingException($msg, PhpMarshallingException::STREAM, $e);
        }
    }
150015
ArgumentMarshaller getArgumentMarshaller(final Method getter) {

        synchronized (argumentMarshallerCache) {
            if ( !argumentMarshallerCache.containsKey(getter) ) {
                ArgumentMarshaller marshaller = null;

                if ( isCustomMarshaller(getter) ) {
                    marshaller = new ArgumentMarshaller() {

                        @Override
                        public AttributeValue marshall(Object obj) {
                            return getCustomerMarshallerAttributeValue(getter, obj);
                        }
                    };
                } else {

                    Class<?> returnType = getter.getReturnType();
                    if ( Set.class.isAssignableFrom(returnType) ) {
                        Type genericType = getter.getGenericReturnType();
                        if ( genericType instanceof ParameterizedType ) {
                            if ( ((ParameterizedType) genericType).getActualTypeArguments()[0].toString().equals("byte[]") ) {
                                returnType = byte[].class;
                            } else {
                                returnType = (Class<?>) ((ParameterizedType) genericType).getActualTypeArguments()[0];
                            }
                        }

                        if ( Date.class.isAssignableFrom(returnType) ) {
                            marshaller = new ArgumentMarshaller() {

                                @Override
                                public AttributeValue marshall(Object obj) {
                                    List<String> timestamps = new LinkedList<String>();
                                    for ( Object o : (Set<?>) obj ) {
                                        timestamps.add(DateUtils.formatISO8601Date((Date) o));
                                    }
                                    return new AttributeValue().withSS(timestamps);
                                }
                            };
                        } else if ( Calendar.class.isAssignableFrom(returnType) ) {
                            marshaller = new ArgumentMarshaller() {

                                @Override
                                public AttributeValue marshall(Object obj) {
                                    List<String> timestamps = new LinkedList<String>();
                                    for ( Object o : (Set<?>) obj ) {
                                        timestamps.add(DateUtils.formatISO8601Date(((Calendar) o).getTime()));
                                    }
                                    return new AttributeValue().withSS(timestamps);
                                }
                            };
                        } else if ( boolean.class.isAssignableFrom(returnType)
                                || Boolean.class.isAssignableFrom(returnType) ) {
                            marshaller = new ArgumentMarshaller() {

                                @Override
                                public AttributeValue marshall(Object obj) {
                                    List<String> booleanAttributes = new ArrayList<String>();
                                    for ( Object b : (Set<?>) obj ) {
                                        if ( b == null || !(Boolean) b ) {
                                            booleanAttributes.add("0");
                                        } else {
                                            booleanAttributes.add("1");
                                        }
                                    }
                                    return new AttributeValue().withNS(booleanAttributes);
                                }
                            };
                        } else if ( returnType.isPrimitive() || Number.class.isAssignableFrom(returnType) ) {
                            marshaller = new ArgumentMarshaller() {

                                @Override
                                public AttributeValue marshall(Object obj) {
                                    List<String> attributes = new ArrayList<String>();
                                    for ( Object o : (Set<?>) obj ) {
                                        attributes.add(String.valueOf(o));
                                    }
                                    return new AttributeValue().withNS(attributes);
                                }
                            };
                        } else if (ByteBuffer.class.isAssignableFrom(returnType)) {
                        	 marshaller = new ArgumentMarshaller() {

                                 @Override
                                 public AttributeValue marshall(Object obj) {
                                     List<ByteBuffer> attributes = new ArrayList<ByteBuffer>();
                                     for ( Object o : (Set<?>) obj ) {
                                         attributes.add((ByteBuffer) o);
                                     }
                                     return new AttributeValue().withBS(attributes);
                                 }
                             };
                        } else if (byte[].class.isAssignableFrom(returnType)) { 
                        	 marshaller = new ArgumentMarshaller() {

                                 @Override
                                 public AttributeValue marshall(Object obj) {
                                     List<ByteBuffer> attributes = new ArrayList<ByteBuffer>();
                                     for ( Object o : (Set<?>) obj ) {
                                         attributes.add(ByteBuffer.wrap((byte[])o));
                                     }
                                     return new AttributeValue().withBS(attributes);
                                 }
                             };
                        } else {
                            marshaller = new ArgumentMarshaller() {

                                @Override
                                public AttributeValue marshall(Object obj) {
                                    List<String> attributes = new ArrayList<String>();
                                    for ( Object o : (Set<?>) obj ) {
                                        attributes.add(String.valueOf(o));
                                    }
                                    return new AttributeValue().withSS(attributes);
                                }
                            };
                        }
                    } else if ( Collection.class.isAssignableFrom(returnType) ) {
                        throw new DynamoDBMappingException("Non-set collections aren't supported: "
                                + (getter.getDeclaringClass() + "." + getter.getName()));
                    } else {
                        if ( Date.class.isAssignableFrom(returnType) ) {
                            marshaller = new ArgumentMarshaller() {

                                @Override
                                public AttributeValue marshall(Object obj) {
                                    return new AttributeValue().withS(DateUtils.formatISO8601Date((Date) obj));
                                }
                            };
                        } else if ( Calendar.class.isAssignableFrom(returnType) ) {
                            marshaller = new ArgumentMarshaller() {

                                @Override
                                public AttributeValue marshall(Object obj) {
                                    return new AttributeValue().withS(DateUtils
                                            .formatISO8601Date(((Calendar) obj).getTime()));
                                }
                            };
                        } else if ( boolean.class.isAssignableFrom(returnType)
                                || Boolean.class.isAssignableFrom(returnType) ) {
                            marshaller = new ArgumentMarshaller() {

                                @Override
                                public AttributeValue marshall(Object obj) {
                                    if ( obj == null || !(Boolean) obj ) {
                                        return new AttributeValue().withN("0");
                                    } else {
                                        return new AttributeValue().withN("1");
                                    }
                                }
                            };
                        } else if ( returnType.isPrimitive() || Number.class.isAssignableFrom(returnType) ) {
                            marshaller = new ArgumentMarshaller() {

                                @Override
                                public AttributeValue marshall(Object obj) {
                                    return new AttributeValue().withN(String.valueOf(obj));
                                }
                            };
                        } else if ( returnType == String.class ) {
                            marshaller = new ArgumentMarshaller() {

                                @Override
                                public AttributeValue marshall(Object obj) {
                                    if ( ((String) obj).length() == 0 )
                                        return null;
                                    return new AttributeValue().withS(String.valueOf(obj));
                                }
                            };
                        } else if ( returnType == ByteBuffer.class ) {
                        	marshaller = new ArgumentMarshaller() {

                                @Override
                                public AttributeValue marshall(Object obj) {
                                    return new AttributeValue().withB((ByteBuffer)obj);
                                }
                            };
                        } else if ( returnType == byte[].class) {
                        	 marshaller = new ArgumentMarshaller() {

                                 @Override
                                 public AttributeValue marshall(Object obj) {
                                     return new AttributeValue().withB(ByteBuffer.wrap((byte[])obj));
                                 }
                             };
                        } else {
                            throw new DynamoDBMappingException("Unsupported type: " + returnType + " for " + getter);
                        }
                    }
                }
                argumentMarshallerCache.put(getter, marshaller);
            }
        }

        return argumentMarshallerCache.get(getter);
    }
870839
static byte[] marshall(final AttDataReady dataReady) throws DevFailed {
        XLOGGER.entry();
        final CDROutputStream os = new CDROutputStream();
        try {
            AttDataReadyHelper.write(os, dataReady);
            XLOGGER.exit();
            return cppAlignment(os.getBufferCopy());
        } finally {
            os.close();
        }
    }
637794
@Override
  public ByteBuffer toBytes(T object) {
    if (!type.equals(object.getClass())) {
      throw new RuntimeException(
          "The type of the object does not match the parameter type of this marshaller. ");
    }
    Map<String, Object> jsonObject = dataMarshaller.mapFieldNameToValue(object);
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    try {
      objectMapper.writeValue(out, jsonObject);
      out.write(NEWLINE_CHARACTER.getBytes());
    } catch (IOException e) {
      throw new RuntimeException("Error in serializing to bigquery json " + jsonObject, e);
    }
    return ByteBuffer.wrap(out.toByteArray());
  }
540572
public function marshal($value)
    {
        if ($value === null) {
            return null;
        }
        if ($value === 'true') {
            return true;
        }
        if ($value === 'false') {
            return false;
        }
        if (!is_scalar($value)) {
            return null;
        }

        return !empty($value);
    }