/**
*
*/
//package org.alldroid.forum.xml;
import java.net.URL;
import java.util.LinkedList;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.FactoryConfigurationError;
import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.xml.sax.SAXException;
import android.net.Uri;
import android.util.Log;
/**
* @author trr4rac
*
*/
public class XmlSerializer {
private static final String TAG = XmlSerializer.class.getSimpleName ( );
private DocumentBuilder builder;
private Document document;
/**
*
*/
public XmlSerializer ( Uri url ) {
try {
builder = DocumentBuilderFactory.newInstance ( ).newDocumentBuilder ( );
document = builder.parse(new URL(url.toString ( )).openStream ( ));
} catch ( Exception e ) {
Log.e(TAG,e.toString ( ));
}
}
public T deserialize ( Class cls ) throws SAXException {
T result;
if ( document == null ) {
throw new SAXException("Document not available.");
}
Element ele = document.getDocumentElement ( );
try {
result = cls.newInstance ( );
} catch ( Exception e ) {
Log.e(TAG,e.toString ( ));
return null;
}
result.deserialize ( ele );
return result;
}
}
interface IXmlSerializable {
public abstract void deserialize ( Element ele );
}