/*
(non-Javadoc)

@see
com.thoughtworks.xstream.converters.Converter#marshal(java.lang.Object,
com.thoughtworks.xstream.io.HierarchicalStreamWriter,
com.thoughtworks.xstream.converters.MarshallingContext)
168771
public void marshal(Object obj, HierarchicalStreamWriter writer,
			MarshallingContext context) {
		XTrace trace = (XTrace) obj;
		writer.startNode("XAttributeMap");
		context.convertAnother(trace.getAttributes(),
				XesXStreamPersistency.attributeMapConverter);
		writer.endNode();
		for (XEvent event : trace) {
			writer.startNode("XEvent");
			context.convertAnother(event, XesXStreamPersistency.eventConverter);
			writer.endNode();
		}
	}
133344
public Object unmarshal(HierarchicalStreamReader reader,
			UnmarshallingContext context) {
		URI uri = URI.create(reader.getAttribute("uri"));
		return XExtensionManager.instance().getByUri(uri);
	}
492890
public static <T> String marshal(String rootName, Collection<T> c) throws JAXBException {
    StringWriter sw = new StringWriter();
    marshal(rootName, c, sw);
    return sw.toString();
  }
1219612
public String marshalObject(Object message)
    {
        try {
            IBindingFactory jc = BindingDirectory.getFactory(Model.class);
            IMarshallingContext marshaller = jc.createMarshallingContext();
            ByteArrayOutputStream out = new ByteArrayOutputStream();
            marshaller.setIndent(2);
            marshaller.marshalDocument(message, URL_ENCODING, null, out);
            String xml = out.toString(STRING_ENCODING);
            return xml;
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        } catch (JiBXException e) {
            e.printStackTrace();
        }
        return null;
    }
150097
public Marshaller getMarshaller(boolean reuse)
    throws JAXBException {
    if (!reuse || this.marshaller == null) {
      Marshaller marshaller = context.createMarshaller();
      marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
      marshaller.setProperty(Marshaller.JAXB_ENCODING,         "UTF-8");
      this.marshaller = marshaller;
    }
    return this.marshaller;
  }
946595
public void marshalling(Xdr xdr) {
        super.marshalling(xdr);
        xdr.putString(_name);
        _attributes.marshalling(xdr);
    }
958747
public function marshall()
    {
        $collection = $this->getToMarshall();
        $ctx = $this->getContext();
        $access = $ctx->getStreamAccess();

        $valueArray = $collection->getArrayCopy();
        $valueArrayVarName = $ctx->generateVariableName($valueArray);

        $arrayArgs = new PhpArgumentCollection();
        if (($count = count($collection)) > 0) {
            foreach ($ctx->popFromVariableStack($count) as $itemName) {
                $arrayArgs[] = new PhpArgument(new PhpVariable($itemName));
            }
        }

        try {
            $access->writeVariable($valueArrayVarName);
            $access->writeEquals($ctx->mustFormatOutput());
            $access->writeFunctionCall('array', $arrayArgs);
            $access->writeSemicolon($ctx->mustFormatOutput());

            $collectionVarName = $ctx->generateVariableName($collection);
            $access->writeVariable($collectionVarName);
            $access->writeEquals($ctx->mustFormatOutput());
            $collectionArgs = new PhpArgumentCollection(array(new PhpArgument(new PhpVariable($valueArrayVarName))));
            $access->writeInstantiation(get_class($collection), $collectionArgs);
            $access->writeSemicolon($ctx->mustFormatOutput());

            $ctx->pushOnVariableStack($collectionVarName);
        } catch (StreamAccessException $e) {
            $msg = "An error occured while marshalling a collection into PHP source code.";
            throw new PhpMarshallingException($msg, PhpMarshallingException::STREAM, $e);
        }
    }
762344
public function marshall()
    {
        $ctx = $this->getContext();
        $streamAccess = $ctx->getStreamAccess();

        try {
            $scalar = $this->getToMarshall();
            $varName = $this->getContext()->generateVariableName($scalar);

            $streamAccess->writeVariable($varName);
            $streamAccess->writeEquals($ctx->mustFormatOutput());
            $streamAccess->writeScalar($scalar);
            $streamAccess->writeSemicolon($ctx->mustFormatOutput());

            $ctx->pushOnVariableStack($varName);
        } catch (StreamAccessException $e) {
            $msg = "An error occured while marshalling the scalar value '${scalar}'.";
            throw new PhpMarshallingException($msg, PhpMarshallingException::STREAM, $e);
        }
    }
1299020
public Object unmarshal(HierarchicalStreamReader reader,
			UnmarshallingContext context) {
		XAttributeMap map = null;
		// restore correct type of attribute map, i.e., check for buffered
		// implementation, and correctly restore lazy implementation if
		// this had been used for serialization.
		boolean lazy = reader.getAttribute("lazy").equals("true");
		boolean buffered = reader.getAttribute("buffered").equals("true");
		if (lazy) {
			if (buffered) {
				map = new XAttributeMapLazyImpl<XAttributeMapBufferedImpl>(
						XAttributeMapBufferedImpl.class);
			} else {
				map = new XAttributeMapLazyImpl<XAttributeMapImpl>(
						XAttributeMapImpl.class);
			}
		} else if (buffered) {
			map = new XAttributeMapBufferedImpl();
		} else {
			map = new XAttributeMapImpl();
		}
		while (reader.hasMoreChildren()) {
			reader.moveDown();
			XAttribute attribute = (XAttribute) context.convertAnother(map,
					XAttribute.class, XesXStreamPersistency.attributeConverter);
			map.put(attribute.getKey(), attribute);
			reader.moveUp();
		}
		return map;
	}
1122282
@Override
    public void marshal(Object graph, Result result) throws IOException, XmlMappingException {
        @SuppressWarnings("unchecked")
        final Tuple<String, Element> data = (Tuple<String, Element>) graph;

        final Transformer transformer;
        try {
            transformer = this.xmlUtilities.getIdentityTransformer();
        } catch (TransformerConfigurationException e) {
            throw new RuntimeException("Failed to load identity Transformer", e);
        }

        // Setup the transformer to pretty-print the output
        transformer.setOutputProperty(OutputKeys.INDENT, "yes");
        transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");

        try {
            transformer.transform(new DocumentSource(data.second), result);
        } catch (TransformerException e) {
            throw new RuntimeException("Failed to write Element to Result for: " + data.first, e);
        }
    }
770000
@Override
    public void marshal(final Object object, final HierarchicalStreamWriter writer, final MarshallingContext context) {
        final CallDetailRecordList list = (CallDetailRecordList) object;

        writer.startNode("Calls");
        writer.addAttribute("page", String.valueOf(page));
        writer.addAttribute("numpages", String.valueOf(getTotalPages()));
        writer.addAttribute("pagesize", String.valueOf(pageSize));
        writer.addAttribute("total", String.valueOf(getTotalPages()));
        writer.addAttribute("start", getFirstIndex());
        writer.addAttribute("end", getLastIndex(list));
        writer.addAttribute("uri", pathUri);
        writer.addAttribute("firstpageuri", getFirstPageUri());
        writer.addAttribute("previouspageuri", getPreviousPageUri());
        writer.addAttribute("nextpageuri", getNextPageUri(list));
        writer.addAttribute("lastpageuri", getLastPageUri());

        for (final CallDetailRecord cdr : list.getCallDetailRecords()) {
            context.convertAnother(cdr);
        }
        writer.endNode();
    }
76235
@Override
    public String marshal(EUI48 val) throws Exception {
        return val == null ? null : val.toString();
    }
923022
public void marshalling(Xdr xdr) {
        super.marshalling(xdr);
        xdr.putLong(_cookie);
        xdr.putLong(_cookieverf);
        xdr.putUnsignedInt(_count);
    }
1309669
protected static Map<Class<?>, FieldMarshaller> createMarshallers ()
    {
        Map<Class<?>, FieldMarshaller> marshallers = Maps.newHashMap();

        // create a generic marshaller for streamable instances
        FieldMarshaller gmarsh = new FieldMarshaller("Generic") {
            @Override
            public void readField (Field field, Object target, ObjectInputStream in)
                throws Exception {
                field.set(target, in.readObject());
            }
            @Override
            public void writeField (Field field, Object source, ObjectOutputStream out)
                throws Exception {
                out.writeObject(field.get(source));
            }
        };
        marshallers.put(Streamable.class, gmarsh);

        // use the same generic marshaller for fields declared as Object with the expectation that
        // they will contain only primitive types or Streamables; the runtime will fail
        // informatively if we attempt to store non-Streamable objects in that field
        marshallers.put(Object.class, gmarsh);

        // create marshallers for the primitive types
        marshallers.put(Boolean.TYPE, new FieldMarshaller("boolean") {
            @Override
            public void readField (Field field, Object target, ObjectInputStream in)
                throws Exception {
                field.setBoolean(target, in.readBoolean());
            }
            @Override
            public void writeField (Field field, Object source, ObjectOutputStream out)
                throws Exception {
                out.writeBoolean(field.getBoolean(source));
            }
        });
        marshallers.put(Byte.TYPE, new FieldMarshaller("byte") {
            @Override
            public void readField (Field field, Object target, ObjectInputStream in)
                throws Exception {
                field.setByte(target, in.readByte());
            }
            @Override
            public void writeField (Field field, Object source, ObjectOutputStream out)
                throws Exception {
                out.writeByte(field.getByte(source));
            }
        });
        marshallers.put(Character.TYPE, new FieldMarshaller("char") {
            @Override
            public void readField (Field field, Object target, ObjectInputStream in)
                throws Exception {
                field.setChar(target, in.readChar());
            }
            @Override
            public void writeField (Field field, Object source, ObjectOutputStream out)
                throws Exception {
                out.writeChar(field.getChar(source));
            }
        });
        marshallers.put(Short.TYPE, new FieldMarshaller("short") {
            @Override
            public void readField (Field field, Object target, ObjectInputStream in)
                throws Exception {
                field.setShort(target, in.readShort());
            }
            @Override
            public void writeField (Field field, Object source, ObjectOutputStream out)
                throws Exception {
                out.writeShort(field.getShort(source));
            }
        });
        marshallers.put(Integer.TYPE, new FieldMarshaller("int") {
            @Override
            public void readField (Field field, Object target, ObjectInputStream in)
                throws Exception {
                field.setInt(target, in.readInt());
            }
            @Override
            public void writeField (Field field, Object source, ObjectOutputStream out)
                throws Exception {
                out.writeInt(field.getInt(source));
            }
        });
        marshallers.put(Long.TYPE, new FieldMarshaller("long") {
            @Override
            public void readField (Field field, Object target, ObjectInputStream in)
                throws Exception {
                field.setLong(target, in.readLong());
            }
            @Override
            public void writeField (Field field, Object source, ObjectOutputStream out)
                throws Exception {
                out.writeLong(field.getLong(source));
            }
        });
        marshallers.put(Float.TYPE, new FieldMarshaller("float") {
            @Override
            public void readField (Field field, Object target, ObjectInputStream in)
                throws Exception {
                field.setFloat(target, in.readFloat());
            }
            @Override
            public void writeField (Field field, Object source, ObjectOutputStream out)
                throws Exception {
                out.writeFloat(field.getFloat(source));
            }
        });
        marshallers.put(Double.TYPE, new FieldMarshaller("double") {
            @Override
            public void readField (Field field, Object target, ObjectInputStream in)
                throws Exception {
                field.setDouble(target, in.readDouble());
            }
            @Override
            public void writeField (Field field, Object source, ObjectOutputStream out)
                throws Exception {
                out.writeDouble(field.getDouble(source));
            }
        });
        marshallers.put(Date.class, new FieldMarshaller("Date") {
            @Override
            public void readField (Field field, Object target, ObjectInputStream in)
                throws Exception {
                field.set(target, new Date(in.readLong()));
            }
            @Override
            public void writeField (Field field, Object source, ObjectOutputStream out)
                throws Exception {
                out.writeLong(((Date)field.get(source)).getTime());
            }
        });

        // create field marshallers for all of the basic types
        for (Map.Entry<Class<?>,Streamer> entry : BasicStreamers.BSTREAMERS.entrySet()) {
            marshallers.put(entry.getKey(), new StreamerMarshaller(entry.getValue()));
        }

        // create the field marshaller for pooled strings
        _internMarshaller = new FieldMarshaller("intern") {
            @Override
            public void readField (Field field, Object target, ObjectInputStream in)
                throws Exception {
                field.set(target, in.readIntern());
            }
            @Override
            public void writeField (Field field, Object source, ObjectOutputStream out)
                throws Exception {
                out.writeIntern((String)field.get(source));
            }
        };

        return marshallers;
    }
891828
public static <T> void marshal(T obj, Writer wr) throws JAXBException {
    JAXBContext ctx = JAXBContext.newInstance(obj.getClass());
    Marshaller m = ctx.createMarshaller();
    m.marshal(obj, wr);
  }
93070
public void marshal(File file, final List<RouteDefinition> routeDefinitionList) throws Exception {
        marshal(file, new Model2Model() {
            @Override
            public XmlModel transform(XmlModel model) {
                copyRoutesToElement(routeDefinitionList, model.getContextElement());
                return model;
            }
        });
    }
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);
        }
    }