// Path: src/main/java/br/com/soapboxrace/dao/factory/IOwnedCarDao.java
// public interface IOwnedCarDao extends ISoapboxDao {
// 
// 	public OwnedCarEntity findById(Long id);
// 
// 	public List<OwnedCarEntity> findByIdPersona(Long idPersona);
// 
// 	public void del(Long id);
// 
// }
// 
// Path: src/main/java/br/com/soapboxrace/jaxb/util/UnmarshalXML.java
// public class UnmarshalXML {
// 
// 	public static Object unMarshal(String xmlStr, Object obj) {
// 		Object objTmp = null;
// 		try {
// 			StringReader reader = new StringReader(xmlStr);
// 			JAXBContext jaxbContext = JAXBContext.newInstance(obj.getClass());
// 			Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
// 			XMLStreamReader xsr = XMLInputFactory.newFactory().createXMLStreamReader(reader);
// 			XMLReaderWithoutNamespace xr = new XMLReaderWithoutNamespace(xsr);
// 			objTmp = jaxbUnmarshaller.unmarshal(xr);
// 			// objTmp = jaxbUnmarshaller.unmarshal(reader);
// 		} catch (Exception e) {
// 			e.printStackTrace();
// 		}
// 		return objTmp;
// 	}
// }


import java.util.List;
import br.com.soapboxrace.dao.factory.IOwnedCarDao;
import br.com.soapboxrace.jaxb.CarSlotInfoTrans;
import br.com.soapboxrace.jaxb.util.UnmarshalXML;
import br.com.soapboxrace.jpa.OwnedCarEntity;
package br.com.soapboxrace.dao.xml;



public class OwnedCarDao extends SoapboxDao implements IOwnedCarDao {

	@Override
	public OwnedCarEntity findById(Long id) {
		OwnedCarEntity entity = (OwnedCarEntity) super.findById(OwnedCarEntity.class, id);
		return entity;
	}

	public List<OwnedCarEntity> findByIdPersona(Long idPersona) {
		String readXml = readFile("personas/" + idPersona + "/carslots.xml");
		CarSlotInfoTrans carSlotInfoTrans = (CarSlotInfoTrans) UnmarshalXML.unMarshal(readXml, new CarSlotInfoTrans());
		return carSlotInfoTrans.getCarsOwnedByPersonaList().getOwnedCarList();
	}

	public void del(Long id) {
// Path: src/main/java/br/com/soapboxrace/dao/factory/IOwnedCarDao.java
// public interface IOwnedCarDao extends ISoapboxDao {
// 
// 	public OwnedCarEntity findById(Long id);
// 
// 	public List<OwnedCarEntity> findByIdPersona(Long idPersona);
// 
// 	public void del(Long id);
// 
// }
// 
// Path: src/main/java/br/com/soapboxrace/jaxb/util/UnmarshalXML.java
// public class UnmarshalXML {
// 
// 	public static Object unMarshal(String xmlStr, Object obj) {
// 		Object objTmp = null;
// 		try {
// 			StringReader reader = new StringReader(xmlStr);
// 			JAXBContext jaxbContext = JAXBContext.newInstance(obj.getClass());
// 			Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
// 			XMLStreamReader xsr = XMLInputFactory.newFactory().createXMLStreamReader(reader);
// 			XMLReaderWithoutNamespace xr = new XMLReaderWithoutNamespace(xsr);
// 			objTmp = jaxbUnmarshaller.unmarshal(xr);
// 			// objTmp = jaxbUnmarshaller.unmarshal(reader);
// 		} catch (Exception e) {
// 			e.printStackTrace();
// 		}
// 		return objTmp;
// 	}
// }


// Path: src/main/java/br/com/soapboxrace/dao/xml/OwnedCarDao.java
import java.util.List;
import br.com.soapboxrace.dao.factory.IOwnedCarDao;
import br.com.soapboxrace.jaxb.CarSlotInfoTrans;
import br.com.soapboxrace.jaxb.util.UnmarshalXML;
import br.com.soapboxrace.jpa.OwnedCarEntity;

package br.com.soapboxrace.dao.xml;



public class OwnedCarDao extends SoapboxDao implements IOwnedCarDao {

	@Override
	public OwnedCarEntity findById(Long id) {
		OwnedCarEntity entity = (OwnedCarEntity) super.findById(OwnedCarEntity.class, id);
		return entity;
	}

	public List<OwnedCarEntity> findByIdPersona(Long idPersona) {
		String readXml = readFile("personas/" + idPersona + "/carslots.xml");
		CarSlotInfoTrans carSlotInfoTrans = (CarSlotInfoTrans) UnmarshalXML.unMarshal(readXml, new CarSlotInfoTrans());
		return carSlotInfoTrans.getCarsOwnedByPersonaList().getOwnedCarList();
	}

	public void del(Long id) {
		OwnedCarEntity entity = findById(id);