Java Code Examples for com.thoughtworks.xstream.io.HierarchicalStreamWriter#setValue()

The following examples show how to use com.thoughtworks.xstream.io.HierarchicalStreamWriter#setValue() . 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 File: HierarchicalStreamCopier.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
public void copy(HierarchicalStreamReader source, HierarchicalStreamWriter destination) {
    destination.startNode(source.getNodeName());
    int attributeCount = source.getAttributeCount();
    for (int i = 0; i < attributeCount; i++) {
        destination.addAttribute(source.getAttributeName(i), source.getAttribute(i));
    }
    String value = source.getValue();
    if (value != null && value.length() > 0) {
        destination.setValue(value);
    }
    while (source.hasMoreChildren()) {
        source.moveDown();
        copy(source, destination);
        source.moveUp();
    }
    destination.endNode();
}
 
Example 2
Source File: DateTimeConverterImpl.java    From yes-cart with Apache License 2.0 6 votes vote down vote up
@Override
public void marshal(final Object source, final HierarchicalStreamWriter writer, final MarshallingContext context) {
    if (source == null) {
        writer.setValue("");
    } else if (source instanceof LocalDate) {
        writer.setValue(((LocalDate) source).atStartOfDay().format(DateTimeFormatter.ISO_DATE_TIME));
    } else if (source instanceof LocalDateTime) {
        writer.setValue(((LocalDateTime) source).format(DateTimeFormatter.ISO_DATE_TIME));
    } else if (source instanceof ZonedDateTime) {
        writer.setValue(((ZonedDateTime) source).format(DateTimeFormatter.ISO_DATE_TIME));
    } else if (source instanceof Instant) {
        writer.setValue(ZonedDateTime.ofInstant((Instant) source, DateUtils.zone()).format(DateTimeFormatter.ISO_DATE_TIME));
    } else {
        writer.setValue(source.toString());
    }
}
 
Example 3
Source File: BitSetConverter.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) {
    BitSet bitSet = (BitSet) source;
    StringBuffer buffer = new StringBuffer();
    boolean seenFirst = false;
    for (int i = 0; i < bitSet.length(); i++) {
        if (bitSet.get(i)) {
            if (seenFirst) {
                buffer.append(',');
            } else {
                seenFirst = true;
            }
            buffer.append(i);
        }
    }
    writer.setValue(buffer.toString());
}
 
Example 4
Source File: GamaShapeFileConverter.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void marshal(final Object arg0, final HierarchicalStreamWriter writer, final MarshallingContext context) {
	System.out.println("ConvertAnother : GamaShapeFileConverter " + arg0.getClass());

	final GamaShapeFile shpFile = (GamaShapeFile) arg0;
	writer.startNode(TAG);
	writer.setValue(shpFile.getFile(scope.scope).getAbsolutePath());
	writer.endNode();
//	System.out.println("===========END ConvertAnother : GamaShapeFile");
	DEBUG.OUT("===========END ConvertAnother : GamaShapeFile");
}
 
Example 5
Source File: ReportCategoryXMLConverter.java    From ET_Redux with 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>reportSettings</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>reportSettings</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 ) {

    ReportCategory reportCategory = (ReportCategory) value;

    writer.startNode( "displayName" );
    writer.setValue( reportCategory.getDisplayName() );
    writer.endNode();

    writer.startNode( "positionIndex" );
    writer.setValue( Integer.toString( reportCategory.getPositionIndex() ) );
    writer.endNode();

    writer.startNode( "categoryColumns" );
    context.convertAnother( reportCategory.getCategoryColumns() );
    writer.endNode();

    writer.startNode( "categoryColor" );
    writer.setValue(  Integer.toString(reportCategory.getCategoryColor().getRGB() ));
    writer.endNode();

    writer.startNode( "visible" );
    writer.setValue( Boolean.toString( reportCategory.isVisible() ) );
    writer.endNode();

    writer.startNode( "legacyData" );
    writer.setValue( Boolean.toString( reportCategory.isLegacyData() ) );
    writer.endNode();


}
 
Example 6
Source File: AttributeConverter.java    From pentaho-aggdesigner with GNU General Public License v2.0 5 votes vote down vote up
public void marshal(Object object, HierarchicalStreamWriter writer, MarshallingContext context) {
  Attribute attribute = (Attribute)object;
  writer.startNode("label");
  writer.setValue(attribute.getLabel());
  writer.endNode();
  writer.startNode("table");
  writer.setValue(attribute.getTable().getLabel());
  writer.endNode();
}
 
Example 7
Source File: GamaBasicTypeConverter.java    From gama with 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 8
Source File: GamaScopeConverter.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void marshal(final Object arg0, final HierarchicalStreamWriter writer, final MarshallingContext context) {
	final IScope scope = (IScope) arg0;
	writer.startNode("IScope");
	writer.setValue(scope.getName().toString());
	writer.endNode();

	// The experiment ???

	writer.startNode("Simulations");
	final ExperimentAgent expAgt = (ExperimentAgent) scope.getExperiment();
	// The model / global
	// IModel model = expAgt.getModel();
	// Collection<IVariable> vars = model.getVars();

	// SimulationPopulation simPop = expAgt.getSimulationPopulation();

	for (final IAgent agt : expAgt.getSimulationPopulation()) {
		// Each simulation
		// SimulationAgent simAgt = (SimulationAgent) agt;
		// System.out.println("ConvertAnother : ScopeConverter " + agt.getClass());
		DEBUG.OUT("ConvertAnother : ScopeConverter " + agt.getClass());
		context.convertAnother(agt);
	}

	writer.endNode();
}
 
Example 9
Source File: Resources.java    From Digital with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Marshals the given object
 *
 * @param value   the value to matshal
 * @param writer  the writer to write the xml to
 * @param context the context of the marshaler
 */
public void marshal(Object value, HierarchicalStreamWriter writer, MarshallingContext context) {
    Map map = (Map) value;
    for (Object obj : map.entrySet()) {
        Map.Entry entry = (Map.Entry) obj;
        writer.startNode(keyName);
        writer.addAttribute("name", entry.getKey().toString());
        writer.setValue(entry.getValue().toString());
        writer.endNode();
    }
}
 
Example 10
Source File: MapCustomConverter.java    From sdb-mall with 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 11
Source File: VersionedXmlDoc.java    From onedev with MIT License 5 votes vote down vote up
private void marshallElement(HierarchicalStreamWriter writer, Element element) {
	writer.startNode(element.getName());
	for (Attribute attribute: (List<Attribute>)element.attributes())
		writer.addAttribute(attribute.getName(), attribute.getValue());
	if (element.getText().trim().length() != 0)
		writer.setValue(element.getText().trim());
	for (Element child: (List<Element>)element.elements())
		marshallElement(writer, child);
	writer.endNode();
}
 
Example 12
Source File: XmlUtilsTest.java    From onetwo with 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 13
Source File: XmlXstreamTest.java    From amforeas with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void marshal (Object o, HierarchicalStreamWriter writer, MarshallingContext mc) {
    Map<String, Object> map = (Map<String, Object>) o;
    for (String key : map.keySet()) {
        Object val = map.get(key);
        writer.startNode(key.toLowerCase());
        if (val != null) {
            writer.setValue(val.toString());
        } else {
            writer.setValue("");
        }

        writer.endNode();
    }
}
 
Example 14
Source File: IeeeAddressConverter.java    From com.zsmartsystems.zigbee with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public void marshal(Object value, HierarchicalStreamWriter writer, MarshallingContext context) {
    IeeeAddress address = (IeeeAddress) value;
    writer.setValue(address.toString());
}
 
Example 15
Source File: ColorConverter.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
private void write(String fieldName, int value, HierarchicalStreamWriter writer) {
    ExtendedHierarchicalStreamWriterHelper.startNode(writer, fieldName, int.class);
    writer.setValue(String.valueOf(value));
    writer.endNode();
}
 
Example 16
Source File: XStreamZonedDateTimeConverter.java    From bearchoke with Apache License 2.0 4 votes vote down vote up
@Override
public void marshal(Object value, HierarchicalStreamWriter writer, MarshallingContext context) {
    ZonedDateTime zdt = (ZonedDateTime) value;
    writer.setValue(zdt.format(DateTimeFormatter.ISO_ZONED_DATE_TIME));
}
 
Example 17
Source File: PbBlankICModelXMLConverter.java    From ET_Redux with Apache License 2.0 4 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
 */
@Override
public void marshal ( Object value, HierarchicalStreamWriter writer,
        MarshallingContext context ) {

    AbstractRatiosDataModel pbBlankICModel = (PbBlankICModel) value;

    writer.startNode( "modelName" );
    writer.setValue( pbBlankICModel.getModelName() );
    writer.endNode();

    writer.startNode( "versionNumber" );
    writer.setValue( Integer.toString( pbBlankICModel.getVersionNumber() ) );
    writer.endNode();

    writer.startNode( "minorVersionNumber" );
    writer.setValue( Integer.toString( pbBlankICModel.getMinorVersionNumber() ) );
    writer.endNode();

    writer.startNode( "labName" );
    writer.setValue( pbBlankICModel.getLabName() );
    writer.endNode();

    writer.startNode( "dateCertified" );
    writer.setValue( pbBlankICModel.getDateCertified() );
    writer.endNode();

    writer.startNode( "reference" );
    writer.setValue( pbBlankICModel.getReference() );
    writer.endNode();

    writer.startNode( "comment" );
    writer.setValue( pbBlankICModel.getComment() );
    writer.endNode();

    writer.startNode( "ratios" );
    context.convertAnother( pbBlankICModel.getData() );
    writer.endNode();

    writer.startNode( "rhos" );
    context.convertAnother( pbBlankICModel.getRhosVarUnctForXMLSerialization() );
    writer.endNode();


}
 
Example 18
Source File: MyDateConverter.java    From tutorials with MIT License 4 votes vote down vote up
@Override
public void marshal(Object value, HierarchicalStreamWriter writer, MarshallingContext arg2) {
    Date date = (Date) value;
    writer.setValue(formatter.format(date));
}
 
Example 19
Source File: JodaDateTimeConverter.java    From projectforge-webapp with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void marshal(final Object source, final HierarchicalStreamWriter writer, final MarshallingContext context)
{
  writer.setValue(toString(source));
}
 
Example 20
Source File: DatabaseMetaConverter.java    From pentaho-aggdesigner with GNU General Public License v2.0 4 votes vote down vote up
public void marshal(Object arg0, HierarchicalStreamWriter writer, MarshallingContext arg2) {
  DatabaseMeta obj = (DatabaseMeta)arg0;
  writer.setValue(obj.getXML());
}