View Javadoc
1 package com.thoughtworks.xstream.converters.collections; 2 3 import com.thoughtworks.xstream.alias.ClassMapper; 4 import com.thoughtworks.xstream.converters.ConverterLookup; 5 import com.thoughtworks.xstream.objecttree.ObjectTree; 6 import com.thoughtworks.xstream.xml.XMLReader; 7 import com.thoughtworks.xstream.xml.XMLWriter; 8 9 import java.util.Collection; 10 import java.util.Iterator; 11 12 public class CollectionConverter extends AbstractCollectionConverter { 13 14 public CollectionConverter(ClassMapper classMapper) { 15 super(classMapper); 16 } 17 18 public boolean canConvert(Class type) { 19 return Collection.class.isAssignableFrom(type); 20 } 21 22 public void toXML(ObjectTree objectGraph, XMLWriter xmlWriter, ConverterLookup converterLookup) { 23 Collection collection = (Collection) objectGraph.get(); 24 for (Iterator iterator = collection.iterator(); iterator.hasNext();) { 25 Object item = iterator.next(); 26 writeItem(item, xmlWriter, converterLookup, objectGraph); 27 } 28 } 29 30 public void fromXML(ObjectTree objectGraph, XMLReader xmlReader, ConverterLookup converterLookup, Class requiredType) { 31 Collection collection = (Collection) createCollection(requiredType); 32 int childCount = xmlReader.childCount(); 33 for (int i = 0; i < childCount; i++) { 34 Object item = readItem(xmlReader, i, objectGraph, converterLookup); 35 collection.add(item); 36 } 37 objectGraph.set(collection); 38 } 39 40 }

This page was automatically generated by Maven