package com.tandbergtv.watchpoint.pmm.entities.bind;

import java.io.InputStream;

import org.exolab.castor.mapping.Mapping;
import org.w3c.dom.Node;
import org.xml.sax.InputSource;

public class Marshaller<E> {
	
	private static final String MAPPING = "com/tandbergtv/watchpoint/pmm/entities/bind/mapping.xml";
	
	/**
	 * Marshals the specified title and returns the DOM node
	 * 
	 * @param title
	 */
	public Node marshal(E entity) {
		InputStream stream = getClass().getClassLoader().getResourceAsStream(MAPPING);
		
		if (stream == null)
			throw new NullPointerException();
		
		Mapping mapping = new Mapping();
		
		mapping.loadMapping(new InputSource(stream));
		
		EntityMarshaller<E> entityMarshaller = EntityMarshaller.newInstance(); 
		
		return entityMarshaller.marshal(entity, mapping);
	}

}
