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

The following examples show how to use com.thoughtworks.xstream.io.HierarchicalStreamWriter#startNode() . 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: 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 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: AbstractChronicleMapConverter.java    From Chronicle-Map with Apache License 2.0 6 votes vote down vote up
@Override
public void marshal(Object o, HierarchicalStreamWriter writer, MarshallingContext
        marshallingContext) {

    for (Map.Entry e : (Iterable<Map.Entry>) ((Map) o).entrySet()) {

        writer.startNode("entry");
        {
            final Object key = e.getKey();
            writer.startNode(key.getClass().getName());
            marshallingContext.convertAnother(key);
            writer.endNode();

            Object value = e.getValue();
            writer.startNode(value.getClass().getName());
            marshallingContext.convertAnother(value);
            writer.endNode();
        }
        writer.endNode();
    }
}
 
Example 4
Source File: XmlMementoSerializer.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
@Override
public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) {
    if (source == null) return;
    AbstractBrooklynObjectSpec<?, ?> spec = (AbstractBrooklynObjectSpec<?, ?>) source;
    String catalogItemId = spec.getCatalogItemId();
    if (Strings.isNonBlank(catalogItemId)) {
        // write this field first, so we can peek at it when we read
        writer.startNode("catalogItemId");
        writer.setValue(catalogItemId);
        writer.endNode();
        
        // we're going to write the catalogItemId field twice :( but that's okay.
        // better solution would be to have mark/reset on reader so we can peek for such a field;
        // see comment below
        super.marshal(source, writer, context);
    } else {
        super.marshal(source, writer, context);
    }
}
 
Example 5
Source File: ReferencedGraphDocumentConverter.java    From depan with 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 6
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 7
Source File: AbstractCollectionConverter.java    From depan with Apache License 2.0 5 votes vote down vote up
/**
 * Utility method to write a child object to the output stream.
 */
protected void marshalObject(Object item,
    HierarchicalStreamWriter writer, MarshallingContext context) {
  String nodeLabel = mapper.serializedClass(item.getClass());
  writer.startNode(nodeLabel);
  context.convertAnother(item);
  writer.endNode();
}
 
Example 8
Source File: SavedAgentConverter.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 SavedAgent savedAgt = (SavedAgent) arg0;
	writer.startNode("index");
	writer.setValue("" + savedAgt.getIndex());
	writer.endNode();

	final ArrayList<String> keys = new ArrayList<>();
	final ArrayList<Object> datas = new ArrayList<>();

	for (final String ky : savedAgt.getKeys()) {
		final Object val = savedAgt.get(ky);
		if (!(val instanceof ExperimentAgent) && !(val instanceof SimulationAgent)) {
			keys.add(ky);
			datas.add(val);
		}
	}

	writer.startNode("variables");
	writer.startNode("keys");
	context.convertAnother(keys);
	writer.endNode();
	writer.startNode("data");
	context.convertAnother(datas);
	writer.endNode();
	writer.endNode();

	final Map<String, List<SavedAgent>> inPop = savedAgt.getInnerPopulations();
	if (inPop != null) {
		writer.startNode("innerPopulations");
		context.convertAnother(inPop);
		writer.endNode();
	}
}
 
Example 9
Source File: DynamicProxyConverter.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private void addInterfacesToXml(Object source, HierarchicalStreamWriter writer) {
    Class[] interfaces = source.getClass().getInterfaces();
    for (int i = 0; i < interfaces.length; i++) {
        Class currentInterface = interfaces[i];
        writer.startNode("interface");
        writer.setValue(mapper.serializedClass(currentInterface));
        writer.endNode();
    }
}
 
Example 10
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 11
Source File: TreeMapConverter.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
protected void marshalComparator(Comparator comparator, HierarchicalStreamWriter writer,
    MarshallingContext context) {
    if (comparator != null) {
        writer.startNode("comparator");
        writer.addAttribute(mapper().aliasForSystemAttribute("class"), 
            mapper().serializedClass(comparator.getClass()));
        context.convertAnother(comparator);
        writer.endNode();
    }
}
 
Example 12
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 13
Source File: EdgeConverter.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 14
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 15
Source File: AbstractXStreamConverter.java    From kogito-runtimes with 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 16
Source File: AbstractXStreamConverter.java    From kogito-runtimes with 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 17
Source File: AbstractXStreamConverter.java    From kogito-runtimes with Apache License 2.0 5 votes vote down vote up
protected void writeList(HierarchicalStreamWriter writer, String listName, String itemName, Iterable<String> list) {
    if (list != null) {
        java.util.Iterator<String> i = list.iterator();
        if (i.hasNext()) {
            writer.startNode(listName);
            while (i.hasNext()) {
                writer.startNode(itemName);
                writer.setValue(i.next());
                writer.endNode();
            }
            writer.endNode();
        }

    }
}
 
Example 18
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 19
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 20
Source File: SesarSampleXMLConverter.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>SesarSample</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>SesarSample</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) {

    SesarSample sesarSample = (SesarSample) value;

    // this order is for registering at SESAR
    writer.startNode("user_code");
    writer.setValue(sesarSample.getUser_code());
    writer.endNode();

    writer.startNode("sample_type");
    writer.setValue(sesarSample.getSampleType());
    writer.endNode();

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

    writer.startNode("material");
    writer.setValue(sesarSample.getMaterial());
    writer.endNode();

    writer.startNode("igsn");
    writer.setValue(sesarSample.getIGSN());
    writer.endNode();

    if (sesarSample.getParentIGSN().length() > 0) {
        writer.startNode("parent_igsn");
        writer.setValue(sesarSample.getParentIGSN());
        writer.endNode();
    }

    writer.startNode("latitude");
    writer.setValue(CoordinateSystemConversions.getDecimalCoordinateAsString(sesarSample.getLatitude()));
    writer.endNode();

    writer.startNode("longitude");
    writer.setValue(CoordinateSystemConversions.getDecimalCoordinateAsString(sesarSample.getLongitude()));
    writer.endNode();

}