com.thoughtworks.xstream.converters.MarshallingContext Java Examples

The following examples show how to use com.thoughtworks.xstream.converters.MarshallingContext. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source Project: depan   Author: google   File: ViewDocumentConverter.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 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);
}
 
Example #2
Source Project: weixin-java-tools   Author: DarLiner   File: WxPayOrderNotifyResultConverter.java    License: Apache License 2.0 6 votes vote down vote up
@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();
  }
}
 
Example #3
Source Project: lams   Author: lamsfoundation   File: AbstractReflectionConverter.java    License: GNU General Public License v2.0 6 votes vote down vote up
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);
    }
}
 
Example #4
Source Project: gama   Author: gama-platform   File: GamaMapConverter.java    License: GNU General Public License v3.0 6 votes vote down vote up
@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));

}
 
Example #5
Source Project: lams   Author: lamsfoundation   File: NamedArrayConverter.java    License: GNU General Public License v2.0 6 votes vote down vote up
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();
    }
}
 
Example #6
Source Project: lams   Author: lamsfoundation   File: FontConverter.java    License: GNU General Public License v2.0 6 votes vote down vote up
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>
    }
}
 
Example #7
Source Project: ET_Redux   Author: CIRDLES   File: PbBlankXMLConverter.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 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();
    
}
 
Example #8
Source Project: ET_Redux   Author: CIRDLES   File: MineralStandardModelXMLConverter.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 
 * @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();

}
 
Example #9
Source Project: yes-cart   Author: inspire-software   File: MapConverter.java    License: Apache License 2.0 5 votes vote down vote up
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();
    }
}
 
Example #10
Source Project: brooklyn-server   Author: apache   File: MapConverter.java    License: Apache License 2.0 5 votes vote down vote up
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();
}
 
Example #11
Source Project: gama   Author: gama-platform   File: GamaBasicTypeConverter.java    License: GNU General Public License v3.0 5 votes vote down vote up
@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();
}
 
Example #12
Source Project: depan   Author: google   File: ResourceDocumentReferenceConverter.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 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();
}
 
Example #13
Source Project: kogito-runtimes   Author: kiegroup   File: RuleTemplateModelImpl.java    License: Apache License 2.0 5 votes vote down vote up
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() );
}
 
Example #14
Source Project: kogito-runtimes   Author: kiegroup   File: AbstractXStreamConverter.java    License: Apache License 2.0 5 votes vote down vote up
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();
        }

    }
}
 
Example #15
Source Project: depan   Author: google   File: GraphModelConverter.java    License: Apache License 2.0 5 votes vote down vote up
protected void marshalObject(Object item,
    HierarchicalStreamWriter writer, MarshallingContext context) {
  String nodeLabel = mapper.serializedClass(item.getClass());
  writer.startNode(nodeLabel);
  context.convertAnother(item);
  writer.endNode();
}
 
Example #16
Source Project: kogito-runtimes   Author: kiegroup   File: AbstractXStreamConverter.java    License: Apache License 2.0 5 votes vote down vote up
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();
    }
}
 
Example #17
Source Project: weixin-java-tools   Author: DarLiner   File: WxPayOrderNotifyResultConverter.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected void marshallField(MarshallingContext context, Object newObj, Field field) {
  if ("couponList".equals(field.getName())) {
    return;
  }

  super.marshallField(context, newObj, field);
}
 
Example #18
Source Project: onetwo   Author: wayshall   File: XmlUtilsTest.java    License: Apache License 2.0 5 votes vote down vote up
@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();
}
 
Example #19
Source Project: onedev   Author: theonedev   File: MapConverter.java    License: MIT License 5 votes vote down vote up
@Override
protected void writeCompleteItem(Object item, MarshallingContext context, HierarchicalStreamWriter writer) {
	if (item instanceof VersionedXmlDoc) 
		((VersionedXmlDoc)item).marshall(writer);
	else 
		super.writeCompleteItem(item, context, writer);
}
 
Example #20
Source Project: onedev   Author: theonedev   File: ReflectionConverter.java    License: MIT License 5 votes vote down vote up
@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);
}
 
Example #21
Source Project: sdb-mall   Author: yjjdick   File: MapCustomConverter.java    License: Apache License 2.0 5 votes vote down vote up
@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();
	}
}
 
Example #22
Source Project: PoseidonX   Author: ucarGroup   File: MapConverter.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * {@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();
    }
}
 
Example #23
Source Project: ET_Redux   Author: CIRDLES   File: MineralStandardUPbRatioModelXMLConverter.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 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();
    
}
 
Example #24
Source Project: Shop-for-JavaWeb   Author: EleTeam   File: DateTimeConverter.java    License: MIT License 5 votes vote down vote up
public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) {
	Date date = (Date) source;
	if (date != null){
		writer.setValue(DateUtils.formatDateTime(date));
	}else{
		writer.setValue("");
	}
}
 
Example #25
Source Project: gama   Author: gama-platform   File: GamaGraphConverter.java    License: GNU General Public License v3.0 5 votes vote down vote up
@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 ");
}
 
Example #26
Source Project: lams   Author: lamsfoundation   File: WeekFieldsConverter.java    License: GNU General Public License v2.0 5 votes vote down vote up
@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();
}
 
Example #27
Source Project: depan   Author: google   File: ReferencedGraphDocumentConverter.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 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();
  }
}
 
Example #28
Source Project: ET_Redux   Author: CIRDLES   File: MeasuredRatioModelXMLConverter.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 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();

}
 
Example #29
Source Project: lams   Author: lamsfoundation   File: AbstractCollectionConverter.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * @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();
    }
}
 
Example #30
Source Project: gama   Author: gama-platform   File: GamaPointConverter.java    License: GNU General Public License v3.0 5 votes vote down vote up
@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();
}