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

The following examples show how to use com.thoughtworks.xstream.io.HierarchicalStreamWriter#endNode() . 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: ModelSerializer.java    From mql-editor with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void marshal( Object value, HierarchicalStreamWriter writer, MarshallingContext context ) {
  Condition condition = (Condition) value;

  writer.startNode( "condition" );
  writer.addAttribute( "combinationType", condition.getCombinationType() != null ? condition.getCombinationType()
      .toString() : "" );
  writer.addAttribute( "defaultValue", condition.getDefaultValue() );
  writer.addAttribute( "operator", condition.getOperator().toString() );
  writer.addAttribute( "selectedAggType", condition.getSelectedAggType() != null ? condition.getSelectedAggType()
      .toString() : "" );
  writer.addAttribute( "value", condition.getValue() );
  writer.startNode( "column" );
  context.convertAnother( condition.getColumn() );
  writer.endNode();
  writer.endNode();
}
 
Example 2
Source File: GamaAgentConverter.java    From gama with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void marshal(final Object arg0, final HierarchicalStreamWriter writer, final MarshallingContext context) {
	// MinimalAgent agt = (MinimalAgent) arg0;
	final AbstractAgent agt = (AbstractAgent) arg0;

	writer.startNode("agentReference");
	DEBUG.OUT("ConvertAnother : AgentConverter " + agt.getClass());
	// System.out.println("ConvertAnother : AgentConverter " + agt.getClass());

	// ReferenceSavedAgent refAft = new ReferenceSavedAgent(agt, null, (ReferenceToAgent) null);
	final ReferenceAgent refAft = new ReferenceAgent(null, null, agt);
	context.convertAnother(refAft);

	// writer.setValue(agt.getName());
	DEBUG.OUT("===========END ConvertAnother : GamaAgent");
	// System.out.println("===========END ConvertAnother : GamaAgent");

	writer.endNode();
}
 
Example 3
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 4
Source File: BeanDefinitionWriterServiceImpl.java    From geomajas-project-server with GNU Affero General Public License v3.0 6 votes vote down vote up
public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) {
	ManagedMap<?, ?> map = (ManagedMap<?, ?>) source;
	for (Map.Entry<?, ?> entry : map.entrySet()) {
		writer.startNode("entry");
		writer.startNode("key");
		if (entry.getKey().getClass().equals(TypedStringValue.class)) {
			writer.startNode("value");
			writer.setValue(((TypedStringValue) entry.getKey()).getValue());
			writer.endNode();
		} else {
			writeItem(entry.getKey(), context, writer);
		}
		writer.endNode();
		if (entry.getValue().getClass().equals(TypedStringValue.class)) {
			writer.startNode("value");
			writer.setValue(((TypedStringValue) entry.getValue()).getValue());
			writer.endNode();
		} else {
			writeItem(entry.getValue(), context, writer);
		}
		writer.endNode();
	}
}
 
Example 5
Source File: EdgeReferenceConverter.java    From depan with Apache License 2.0 5 votes vote down vote up
@Override
public void marshal(Object source, HierarchicalStreamWriter writer,
    MarshallingContext context) {
  GraphEdge edge = (GraphEdge) source;

  Relation relation = edge.getRelation();
  writer.startNode(RELATION_TAG);

  Class<?> actualType = relation.getClass();
  Class<?> defaultType = mapper.defaultImplementationOf(BasicEdge.class);
  if (!actualType.equals(defaultType)) {
      writer.addAttribute(
          mapper.aliasForAttribute("class"),
          mapper.serializedClass(actualType));
  }

  context.convertAnother(relation);
  writer.endNode();

  writer.startNode(HEAD_TAG);
  context.convertAnother(edge.getHead().getId());
  writer.endNode();

  writer.startNode(TAIL_TAG);
  context.convertAnother(edge.getTail().getId());
  writer.endNode();
}
 
Example 6
Source File: MeasureConverter.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) {
  Measure measure = (Measure)object;
  writer.startNode("label");
  writer.setValue(measure.getLabel());
  writer.endNode();
  writer.startNode("table");
  writer.setValue(measure.getTable().getLabel());
  writer.endNode();
}
 
Example 7
Source File: GamaSpeciesConverter.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 : ConvertGamaSpecies " + arg0.getClass());
	DEBUG.OUT("ConvertAnother : ConvertGamaSpecies " + arg0.getClass());
	final AbstractSpecies spec = (AbstractSpecies) arg0;
	final GamaPopulation<? extends IAgent> pop =
			(GamaPopulation<? extends IAgent>) spec.getPopulation(convertScope.getScope());

	writer.startNode("agentSetFromPopulation");
	context.convertAnother(pop.getAgents(convertScope.getScope()));
	writer.endNode();

	// System.out.println("===========END ConvertAnother : ConvertGamaSpecies");
	DEBUG.OUT("===========END ConvertAnother : ConvertGamaSpecies");
}
 
Example 8
Source File: BeanDefinitionWriterServiceImpl.java    From geomajas-project-server with GNU Affero General Public License v3.0 5 votes vote down vote up
public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) {
	BeanDefinition definition = (BeanDefinition) source;
	writer.addAttribute("class", definition.getBeanClassName());
	for (PropertyValue property : definition.getPropertyValues().getPropertyValueList()) {
		writer.startNode("property");
		writer.addAttribute("name", property.getName());
		if (property.getValue().getClass().equals(TypedStringValue.class)) {
			context.convertAnother(property.getValue());
		} else {
			writeItem(property.getValue(), context, writer);
		}
		writer.endNode();
	}

}
 
Example 9
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 10
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 11
Source File: QualifierModelImpl.java    From kogito-runtimes with Apache License 2.0 5 votes vote down vote up
public void marshal(Object value, HierarchicalStreamWriter writer, MarshallingContext context) {
    QualifierModelImpl qualifier = (QualifierModelImpl) value;
    writer.addAttribute("type", qualifier.getType());
    if (qualifier.getValue() != null) {
        writer.addAttribute("value", qualifier.getValue());
    } else {
        for (Map.Entry<String, String> entry : qualifier.getArguments().entrySet()) {
            writer.startNode("arg");
            writer.addAttribute("key", entry.getKey());
            writer.addAttribute("value", entry.getValue());
            writer.endNode();
        }
    }
}
 
Example 12
Source File: MapConverter.java    From PoseidonX with 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 13
Source File: AggListConverter.java    From pentaho-aggdesigner with GNU General Public License v2.0 5 votes vote down vote up
public void marshal(Object arg0, HierarchicalStreamWriter writer, MarshallingContext context) {
  AggList impl = (AggList)arg0;
  for (int i = 0; i < impl.getSize(); i++) {
    writer.startNode("aggregation");
    context.convertAnother(impl.getAgg(i));
    writer.endNode();
  }
}
 
Example 14
Source File: MapEntryConverter.java    From ZenQuery with Apache License 2.0 5 votes vote down vote up
public void marshal(Object value, HierarchicalStreamWriter writer, MarshallingContext context) {
    AbstractMap map = (AbstractMap) value;
    for (Object obj : map.entrySet()) {
        Map.Entry entry = (Map.Entry) obj;
        writer.startNode(entry.getKey().toString());
        writer.setValue(entry.getValue() != null ? entry.getValue().toString() : "");
        writer.endNode();
    }
}
 
Example 15
Source File: WSRequestCodec.java    From SI with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void marshal(Object value, HierarchicalStreamWriter writer, MarshallingContext context) {

            AbstractMap map = (AbstractMap) value;
            for (Object obj : map.entrySet()) {
                Map.Entry entry = (Map.Entry) obj;
                writer.startNode(entry.getKey().toString());
                Object val = entry.getValue();
                if ( null != val ) {
                    writer.setValue(val.toString());
                }
                writer.endNode();
            }

        }
 
Example 16
Source File: SubjectConverter.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
protected void marshalPrincipals(Set principals, HierarchicalStreamWriter writer, MarshallingContext context) {
    writer.startNode("principals");
    for (final Iterator iter = principals.iterator(); iter.hasNext();) {
        final Object principal = iter.next(); // pre jdk 1.4 a Principal was also in javax.security
        writeCompleteItem(principal, context, writer);
    }
    writer.endNode();
}
 
Example 17
Source File: AnalysisImageXMLConverter.java    From ET_Redux with 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) {
    
    AnalysisImage analysisImage = (AnalysisImage) value;
    
    writer.startNode("imageType");
    writer.setValue(analysisImage.getImageType().getName());
    writer.endNode();
    
    writer.startNode("imageURL");
    writer.setValue(analysisImage.getImageURL());
    writer.endNode();
}
 
Example 18
Source File: AbstractXStreamConverter.java    From kogito-runtimes with Apache License 2.0 5 votes vote down vote up
protected void writeString(HierarchicalStreamWriter writer, String name, String value) {
    if (value != null) {
        writer.startNode(name);
        writer.setValue(value);
        writer.endNode();
    }
}
 
Example 19
Source File: DetritalUThModelXMLConverter.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 detritalUraniumAndThoriumModel = (DetritalUraniumAndThoriumModel) value;

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

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

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

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

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

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

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

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

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


}
 
Example 20
Source File: ReportSettingsXMLConverter.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>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) {

    ReportSettings reportSettings = (ReportSettings) value;

    writer.startNode("name");
    writer.setValue(reportSettings.getName());
    writer.endNode();

    writer.startNode("version");
    writer.setValue(Integer.toString(reportSettings.getVersion()));
    writer.endNode();

    writer.startNode("isotopeStyle");
    writer.setValue(reportSettings.getDefaultReportSpecsType());
    writer.endNode();

    writer.startNode("fractionCategory");
    context.convertAnother(reportSettings.getFractionCategory());
    writer.endNode();

    if (reportSettings.isdefaultReportSpecsType_UPb()) {
        writer.startNode("compositionCategory");
        context.convertAnother(reportSettings.getCompositionCategory());
        writer.endNode();

        writer.startNode("isotopicRatiosCategory");
        context.convertAnother(reportSettings.getIsotopicRatiosCategory());
        writer.endNode();

        writer.startNode("isotopicRatiosPbcCorrCategory");
        context.convertAnother(reportSettings.getIsotopicRatiosPbcCorrCategory());
        writer.endNode();

        writer.startNode("datesCategory");
        context.convertAnother(reportSettings.getDatesCategory());
        writer.endNode();

        writer.startNode("datesPbcCorrCategory");
        context.convertAnother(reportSettings.getDatesPbcCorrCategory());
        writer.endNode();

        writer.startNode("rhosCategory");
        context.convertAnother(reportSettings.getRhosCategory());
        writer.endNode();

        writer.startNode("traceElementsCategory");
        context.convertAnother(reportSettings.getTraceElementsCategory());
        writer.endNode();
    } else if (reportSettings.isdefaultReportSpecsType_UTh_Carb()) {
        writer.startNode("concentrationAndActivityCategory");
        context.convertAnother(reportSettings.getConcentrationAndActivityCategory());
        writer.endNode();

        writer.startNode("measuredAtomAndActivityRatiosCategory");
        context.convertAnother(reportSettings.getMeasuredAtomAndActivityRatiosCategory());
        writer.endNode();

        writer.startNode("measuredCorrectedAtomAndActivityRatiosCategory");
        context.convertAnother(reportSettings.getMeasuredCorrectedAtomAndActivityRatiosCategory());
        writer.endNode();

        writer.startNode("datesCategory");
        context.convertAnother(reportSettings.getDatesCategory());
        writer.endNode();
    } else if (reportSettings.isdefaultReportSpecsType_UTh_Ign()) {
        writer.startNode("datesCategory");
        context.convertAnother(reportSettings.getDatesCategory());
        writer.endNode();
    }

    writer.startNode("fractionCategory2");
    context.convertAnother(reportSettings.getFractionCategory2());
    writer.endNode();

    writer.startNode("reportSettingsComment");
    writer.setValue(reportSettings.getReportSettingsComment());
    writer.endNode();

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

}