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 UnMarshaller<E> {

	private static final String MAPPING = "com/tandbergtv/watchpoint/pmm/entities/bind/mapping.xml";
	
	/**
	 * Unmarshals the specified DOM equivalent of a schedule into the corresponding object
	 * 
	 * @param node
	 * @return
	 */
	public E unmarshal(Node node) {
		InputStream stream = getClass().getClassLoader().getResourceAsStream(MAPPING);
		
		if (stream == null)
			throw new NullPointerException();
		
		Mapping mapping = new Mapping();
		
		mapping.loadMapping(new InputSource(stream));
		
		EntityUnmarshaller<E> unmarshaller = EntityUnmarshaller.newInstance(); 
		return unmarshaller.unmarshal(node, mapping);
	}
}
