package util;

import net.sf.hibernate.cfg.Configuration;
import java.io.InputStream;
import java.util.List;
import java.util.ArrayList;
import net.sf.hibernate.MappingException;
import net.sf.hibernate.HibernateException;
import org.xml.sax.InputSource;
import java.io.IOException;

public class MyConfiguration extends Configuration {
  protected Configuration doConfigure(InputStream stream, String resourceName) throws HibernateException {

          org.dom4j.Document doc;
          try {
                  List errors = new ArrayList();
                  String str = "HALOU";
                  byte[] btr = new byte[200];
                  //stream.read(btr, 0, btr.length);
                  //System.out.println(str);
                  doc = MyXMLHelper.createSAXReader(resourceName, errors).read( new InputSource(stream) );
                  if ( errors.size()!=0 ) throw new MappingException( "invalid configuration", (Throwable) errors.get(0) );
          }
          catch (Exception e) {
                  e.printStackTrace();
                  System.err.println("problem parsing configuration" + resourceName+" "+e);
                  throw new HibernateException("problem parsing configuration" + resourceName, e);
          }
          finally {
                  try{
                          stream.close();
                  }
                  catch (IOException ioe){
                          System.err.println("could not close stream on: " + resourceName+" "+ioe);
                  }
          }

          return doConfigure(doc);

  }
}
