package net.woodyfolsom.cs6601.p2;

import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.converters.collections.CollectionConverter;
import com.thoughtworks.xstream.io.xml.DomDriver;
import com.thoughtworks.xstream.mapper.ClassAliasingMapper;

public class XStreamFactory {
	
	public static XStream getInstance() {
		XStream xstream = new XStream(new DomDriver());
		
		///RecipeBook
		xstream.processAnnotations(RecipeBook.class);
		
		xstream.processAnnotations(Recipe.class);
		xstream.omitField(Recipe.class, "directions");
		
		xstream.processAnnotations(RecipeHead.class);
		
		ClassAliasingMapper mapper = new ClassAliasingMapper(xstream.getMapper());
		mapper.addClassAlias("cat", String.class);
		xstream.registerLocalConverter(
		    RecipeHead.class,
		    "categories",
		    new CollectionConverter(mapper)
		);
		
		xstream.omitField(RecipeHead.class, "yield");
		xstream.omitField(RecipeHead.class, "preptime");
		
		xstream.omitField(Ingredient.class, "amt");
		xstream.omitField(Ingredient.class, "prep");
		
		///Survey
		xstream.processAnnotations(Survey.class);
		xstream.processAnnotations(Diner.class);
		
		return xstream;
	}
}
