下面列出了org.hibernate.collection.internal.AbstractPersistentCollection#com.thoughtworks.xstream.converters.MarshallingContext 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* No need to start a node, since the caller ensures we are wrapped correctly.
*/
@Override
public void marshal(Object source, HierarchicalStreamWriter writer,
MarshallingContext context) {
ViewDocument viewInfo = (ViewDocument) source;
Components components = viewInfo.getComponents();
// Save the graph reference.
marshalObject(components.getParentGraph(), writer, context);
// Save all node references.
marshalNodes(components.getViewNodes(), VIEW_NODES, writer, context);
// Save the preferences.
marshalObject(components.getUserPrefs(), writer, context);
}
@Override
public void marshal(Object original, HierarchicalStreamWriter writer, MarshallingContext context) {
super.marshal(original, writer, context);
WxPayOrderNotifyResult obj = (WxPayOrderNotifyResult) original;
List<WxPayOrderNotifyCoupon> list = obj.getCouponList();
if (list == null || list.size() == 0) {
return;
}
for (int i = 0; i < list.size(); i++) {
WxPayOrderNotifyCoupon coupon = list.get(i);
writer.startNode("coupon_id_" + i);
writer.setValue(coupon.getCouponId());
writer.endNode();
writer.startNode("coupon_type_" + i);
writer.setValue(coupon.getCouponType());
writer.endNode();
writer.startNode("coupon_fee_" + i);
writer.setValue(coupon.getCouponFee() + "");
writer.endNode();
}
}
public void marshal(Object original, final HierarchicalStreamWriter writer,
final MarshallingContext context) {
final Object source = serializationMembers.callWriteReplace(original);
if (source != original && context instanceof ReferencingMarshallingContext) {
((ReferencingMarshallingContext)context).replace(original, source);
}
if (source.getClass() != original.getClass()) {
String attributeName = mapper.aliasForSystemAttribute("resolves-to");
if (attributeName != null) {
writer.addAttribute(attributeName, mapper.serializedClass(source.getClass()));
}
context.convertAnother(source);
} else {
doMarshal(source, writer, context);
}
}
@Override
public void marshal(final Object arg0, final HierarchicalStreamWriter writer, final MarshallingContext arg2) {
final IMap mp = (IMap) arg0;
// GamaMapReducer m = new GamaMapReducer(mp);
// writer.startNode("GamaMap");
//
// writer.startNode("KeysType");
// arg2.convertAnother(m.getKeysType());
// writer.endNode();
//
// writer.startNode("ValueType");
// arg2.convertAnother(m.getDataType());
// writer.endNode();
//
// for(GamaPair gm : m.getValues()) {
// arg2.convertAnother(gm);
// }
//
// writer.endNode();
arg2.convertAnother(new GamaMapReducer(mp));
}
public void marshal(final Object source, final HierarchicalStreamWriter writer, final MarshallingContext context) {
final int length = Array.getLength(source);
for (int i = 0; i < length; ++i) {
final Object item = Array.get(source, i);
final Class itemType = item == null
? Mapper.Null.class
: arrayType.getComponentType().isPrimitive()
? Primitives.unbox(item.getClass())
: item.getClass();
ExtendedHierarchicalStreamWriterHelper.startNode(writer, itemName, itemType);
if (!itemType.equals(arrayType.getComponentType())) {
final String attributeName = mapper.aliasForSystemAttribute("class");
if (attributeName != null) {
writer.addAttribute(attributeName, mapper.serializedClass(itemType));
}
}
if (item != null) {
context.convertAnother(item);
}
writer.endNode();
}
}
public void marshal(Object source, HierarchicalStreamWriter writer,
MarshallingContext context) {
Font font = (Font)source;
Map attributes = font.getAttributes();
if (mapper != null) {
String classAlias = mapper.aliasForSystemAttribute("class");
for (Iterator iter = attributes.entrySet().iterator(); iter.hasNext();) {
Map.Entry entry = (Map.Entry)iter.next();
String name = textAttributeConverter.toString(entry.getKey());
Object value = entry.getValue();
Class type = value != null ? value.getClass() : Mapper.Null.class;
ExtendedHierarchicalStreamWriterHelper.startNode(writer, name, type);
writer.addAttribute(classAlias, mapper.serializedClass(type));
if (value != null) {
context.convertAnother(value);
}
writer.endNode();
}
} else {
writer.startNode("attributes"); // <attributes>
context.convertAnother(attributes);
writer.endNode(); // </attributes>
}
}
/**
* writes the argument <code>value</code> to the XML file specified through <code>writer</code>
*
* @pre <code>value</code> is a valid <code>PbBlank</code>, <code>
* writer</code> is a valid <code>HierarchicalStreamWriter</code>,
* and <code>context</code> is a valid <code>MarshallingContext</code>
* @post <code>value</code> is written to the XML file specified via <code>writer</code>
* @param value <code>PbBlank</code> that you wish to write to a file
* @param writer stream to write through
* @param context <code>MarshallingContext</code> used to store generic data
*/
public void marshal(Object value, HierarchicalStreamWriter writer,
MarshallingContext context) {
PbBlank pbBlank = (PbBlank) value;
writer.startNode("name");
writer.setValue(pbBlank.getName());
writer.endNode();
writer.startNode("ratios");
context.convertAnother(pbBlank.getRatios());
writer.endNode();
writer.startNode("rhoCorrelations");
context.convertAnother(pbBlank.getRhoCorrelations());
writer.endNode();
}
/**
*
* @param value
* @param writer
* @param context
*/
@Override
public void marshal ( Object value, HierarchicalStreamWriter writer,
MarshallingContext context ) {
MineralStandardModel mineralStandard = (MineralStandardModel) value;
writer.startNode( "name" );
writer.setValue( mineralStandard.getName() );
writer.endNode();
writer.startNode( "mineralStandardName" );
writer.setValue( mineralStandard.getMineralStandardName() );
writer.endNode();
writer.startNode( "standardMineralName" );
writer.setValue( mineralStandard.getStandardMineralName() );
writer.endNode();
writer.startNode( "trueAge" );
context.convertAnother( mineralStandard.getTrueAge() );
writer.endNode();
writer.startNode( "radiogenicIsotopeRatios" );
context.convertAnother( ValueModel.compressArrayOfValueModels( mineralStandard.getRadiogenicIsotopeRatios() ) );
writer.endNode();
writer.startNode( "measuredAge" );
context.convertAnother( mineralStandard.getMeasuredAge() );
writer.endNode();
writer.startNode( "comment" );
writer.setValue( mineralStandard.getComment() );
writer.endNode();
}
protected void writeItem(String nodeName, Object item, MarshallingContext context, HierarchicalStreamWriter writer) {
// PUBLISHED API METHOD! If changing signature, ensure backwards compatibility.
if (item != null) {
ExtendedHierarchicalStreamWriterHelper.startNode(writer, nodeName, item.getClass());
context.convertAnother(item);
writer.endNode();
}
}
protected void marshalEntry(HierarchicalStreamWriter writer, MarshallingContext context, Map.Entry entry) {
ExtendedHierarchicalStreamWriterHelper.startNode(writer, getEntryNodeName(), Map.Entry.class);
writeItem(entry.getKey(), context, writer);
writeItem(entry.getValue(), context, writer);
writer.endNode();
}
@Override
public void marshal(final Object arg0, final HierarchicalStreamWriter writer, final MarshallingContext arg2) {
final GamaType<?> type = (GamaType<?>) arg0;
DEBUG.OUT("==GamaType " + arg0);
// System.out.println("==GamaType " + arg0);
writer.startNode(TAG);
writer.setValue("" + type.getName());
// writer.setValue(""+arg0.getClass());
writer.endNode();
}
/**
* Simply output the workspace relative name for the referenced GraphModel.
*/
@Override
public void marshal(
Object source, HierarchicalStreamWriter writer,
MarshallingContext context) {
ResourceDocumentReference<?> docRef = (ResourceDocumentReference<?>) source;
ResourceContainer container = docRef.getResourceContainer();
String docPath = PlatformTools.fromPath(container.getPath());
String docName = docRef.getDocument().getName();
writer.startNode(RSRC_DOC_REF_TAG);
writer.addAttribute(DOC_PATH_ATTR, docPath);
writer.addAttribute(DOC_NAME_ATTR, docName);
writer.endNode();
}
public void marshal(Object value, HierarchicalStreamWriter writer, MarshallingContext context) {
RuleTemplateModelImpl rtm = (RuleTemplateModelImpl) value;
writer.addAttribute( "dtable", rtm.getDtable() );
writer.addAttribute( "template", rtm.getTemplate() );
writer.addAttribute( "row", "" + rtm.getRow() );
writer.addAttribute( "col", "" + rtm.getCol() );
}
protected void writeObjectList(HierarchicalStreamWriter writer, MarshallingContext context, String listName, String itemName, Iterable<?> list) {
if (list != null) {
java.util.Iterator<? extends Object> i = list.iterator();
if (i.hasNext()) {
writer.startNode(listName);
while (i.hasNext()) {
writeObject(writer, context, itemName, i.next());
}
writer.endNode();
}
}
}
protected void marshalObject(Object item,
HierarchicalStreamWriter writer, MarshallingContext context) {
String nodeLabel = mapper.serializedClass(item.getClass());
writer.startNode(nodeLabel);
context.convertAnother(item);
writer.endNode();
}
protected void writeMap(HierarchicalStreamWriter writer, MarshallingContext context, String mapName, String itemName, String keyName, String valueName, Map<String, String> map) {
if (map != null && !map.isEmpty()) {
writer.startNode(mapName);
for (Map.Entry<String, String> entry : map.entrySet()) {
writer.startNode(itemName);
writer.addAttribute(keyName, entry.getKey());
writer.addAttribute(valueName, entry.getValue());
writer.endNode();
}
writer.endNode();
}
}
@Override
protected void marshallField(MarshallingContext context, Object newObj, Field field) {
if ("couponList".equals(field.getName())) {
return;
}
super.marshallField(context, newObj, field);
}
@Override
public void marshal(Object source, HierarchicalStreamWriter writer,
MarshallingContext context) {
TestPersonAnnotation p = (TestPersonAnnotation) source;
writer.startNode("name");
writer.setValue(p.getUserName());
writer.endNode();
writer.startNode("age");
writer.setValue(""+p.getAge());
writer.endNode();
writer.startNode("parent");
writer.setValue("");
writer.endNode();
}
@Override
protected void writeCompleteItem(Object item, MarshallingContext context, HierarchicalStreamWriter writer) {
if (item instanceof VersionedXmlDoc)
((VersionedXmlDoc)item).marshall(writer);
else
super.writeCompleteItem(item, context, writer);
}
@Override
protected void marshallField(MarshallingContext context, Object newObj, Field field) {
if (field.getAnnotation(ManyToOne.class) != null)
super.marshallField(context, ((AbstractEntity) newObj).getId(), field);
else
super.marshallField(context, newObj, field);
}
@SuppressWarnings("rawtypes")
public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) {
Map map = (Map) source;
for (Iterator iterator = map.entrySet().iterator(); iterator.hasNext();) {
Entry entry = (Entry) iterator.next();
ExtendedHierarchicalStreamWriterHelper.startNode(writer, entry.getKey().toString(), Entry.class);
writer.setValue(entry.getValue().toString());
writer.endNode();
}
}
/**
* {@inheritDoc}
*/
public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context)
{
TreeMap<String, String> map = (TreeMap)source;
for (Entry<String, String> entry : map.entrySet())
{
ExtendedHierarchicalStreamWriterHelper.startNode(writer, "property", Entry.class);
writer.addAttribute("key", entry.getKey());
writer.addAttribute("value", entry.getValue());
writer.endNode();
}
}
/**
* writes the argument <code>value</code> to the XML file specified through <code>writer</code>
*
* @pre <code>value</code> is a valid <code>ValueModelReferenced</code>,
* <code>writer</code> is a valid <code>HierarchicalStreamWriter</code>,
* and <code>context</code> is a valid <code>MarshallingContext</code>
* @post <code>value</code> is written to the XML file specified via <code>writer</code>
* @param value <code>ValueModelReferenced</code> that you wish to write to a file
* @param writer stream to write through
* @param context <code>MarshallingContext</code> used to store generic data
*/
@Override
public void marshal(Object value, HierarchicalStreamWriter writer,
MarshallingContext context) {
ValueModel valueModel = (MineralStandardUPbRatioModel) value;
writer.startNode("name");
writer.setValue(valueModel.getName());
writer.endNode();
writer.startNode("value");
writer.setValue(valueModel.getValue().toPlainString());
writer.endNode();
writer.startNode("uncertaintyType");
writer.setValue(valueModel.getUncertaintyType().toString());
writer.endNode();
writer.startNode("oneSigma");
writer.setValue(valueModel.getOneSigma().toPlainString());
writer.endNode();
writer.startNode("measured");
writer.setValue(Boolean.toString(((MineralStandardUPbRatioModel)valueModel).isMeasured()));
writer.endNode();
}
public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) {
Date date = (Date) source;
if (date != null){
writer.setValue(DateUtils.formatDateTime(date));
}else{
writer.setValue("");
}
}
@Override
public void marshal(final Object arg0, final HierarchicalStreamWriter writer, final MarshallingContext arg2) {
final GamaGraph graph = (GamaGraph) arg0;
// System.out.println("ConvertAnother : GamaList " + graph.getClass());
DEBUG.OUT("ConvertAnother : GamaList " + graph.getClass());
arg2.convertAnother(new GamaGraphReducer(convertScope.getScope(), graph));
// System.out.println("END --- ConvertAnother : GamaList ");
DEBUG.OUT("END --- ConvertAnother : GamaList ");
}
@Override
public void marshal(final Object source, final HierarchicalStreamWriter writer, final MarshallingContext context) {
final WeekFields weekFields = (WeekFields)source;
ExtendedHierarchicalStreamWriterHelper.startNode(writer, mapper.serializedMember(WeekFields.class,
"minimalDays"), int.class);
writer.setValue(String.valueOf(weekFields.getMinimalDaysInFirstWeek()));
writer.endNode();
ExtendedHierarchicalStreamWriterHelper.startNode(writer, mapper.serializedMember(WeekFields.class,
"firstDayOfWeek"), DayOfWeek.class);
context.convertAnother(weekFields.getFirstDayOfWeek());
writer.endNode();
}
/**
* Marshal a group of nodes for saving. The collection is wrapped
* with an XML element named {@link #nodeLabel}.
*/
protected void marshalNodes(
Collection<GraphNode> nodes, String nodeLabel,
HierarchicalStreamWriter writer, MarshallingContext context) {
writer.startNode(nodeLabel);
try {
for (GraphNode node : nodes) {
marshalObject(node, writer, context);
}
} finally {
writer.endNode();
}
}
/**
* writes the argument <code>value</code> to the XML file specified through <code>writer</code>
*
* @pre <code>value</code> is a valid <code>MeasuredRatioModel</code>,
* <code>writer</code> is a valid <code>HierarchicalStreamWriter</code>,
* and <code>context</code> is a valid <code>MarshallingContext</code>
* @post <code>value</code> is written to the XML file specified via <code>writer</code>
* @param value <code>MeasuredRatioModel</code> that you wish to write to a file
* @param writer stream to write through
* @param context <code>MarshallingContext</code> used to store generic data
*/
public void marshal(Object value, HierarchicalStreamWriter writer,
MarshallingContext context) {
ValueModel measuredRatio = (MeasuredRatioModel) value;
writer.startNode("name");
writer.setValue(measuredRatio.getName());
writer.endNode();
writer.startNode("value");
writer.setValue(measuredRatio.getValue().toPlainString());
writer.endNode();
writer.startNode("uncertaintyType");
writer.setValue(measuredRatio.getUncertaintyType());
writer.endNode();
writer.startNode("oneSigma");
writer.setValue(measuredRatio.getOneSigma().toPlainString());
writer.endNode();
writer.startNode("fracCorr");
writer.setValue(Boolean.toString(((MeasuredRatioModel) measuredRatio).isFracCorr()));
writer.endNode();
writer.startNode("oxideCorr");
writer.setValue(Boolean.toString(((MeasuredRatioModel) measuredRatio).isOxideCorr()));
writer.endNode();
}
/**
* @deprecated As of 1.4.11 use {@link #writeCompleteItem(Object, MarshallingContext, HierarchicalStreamWriter)}
* instead.
*/
protected void writeItem(Object item, MarshallingContext context, HierarchicalStreamWriter writer) {
// PUBLISHED API METHOD! If changing signature, ensure backwards compatibility.
if (item == null) {
// todo: this is duplicated in TreeMarshaller.start()
writeNullItem(context, writer);
} else {
String name = mapper().serializedClass(item.getClass());
ExtendedHierarchicalStreamWriterHelper.startNode(writer, name, item.getClass());
writeBareItem(item, context, writer);
writer.endNode();
}
}
@Override
public void marshal(Object arg0, HierarchicalStreamWriter writer, MarshallingContext arg2) {
GamaPoint pt = (GamaPoint) arg0;
String line=pt.getX()+SEPARATOR+pt.getY()+SEPARATOR+pt.getZ();
writer.startNode(TAG);
writer.setValue(line);
writer.endNode();
}