Search in sources :

Example 1 with ErrorLogger

use of org.hibernate.internal.util.xml.ErrorLogger in project hibernate-orm by hibernate.

the class JPAOverriddenAnnotationReaderTest method buildContext.

private XMLContext buildContext(String ormfile) throws SAXException, DocumentException, IOException {
    XMLHelper xmlHelper = new XMLHelper(ClassLoaderServiceTestingImpl.INSTANCE);
    InputStream is = ClassLoaderServiceTestingImpl.INSTANCE.locateResourceStream(ormfile);
    assertNotNull("ORM.xml not found: " + ormfile, is);
    XMLContext context = new XMLContext(ClassLoaderAccessTestingImpl.INSTANCE);
    ErrorLogger errorLogger = new ErrorLogger();
    SAXReader saxReader = xmlHelper.createSAXReader(errorLogger, EJB3DTDEntityResolver.INSTANCE);
    //saxReader.setValidation( false );
    try {
        saxReader.setFeature("http://apache.org/xml/features/validation/schema", true);
    } catch (SAXNotSupportedException e) {
        saxReader.setValidation(false);
    }
    org.dom4j.Document doc;
    try {
        doc = saxReader.read(new InputSource(new BufferedInputStream(is)));
    } finally {
        is.close();
    }
    if (errorLogger.hasErrors()) {
        System.out.println(errorLogger.getErrors().get(0));
    }
    assertFalse(errorLogger.hasErrors());
    context.addDocument(doc);
    return context;
}
Also used : InputSource(org.xml.sax.InputSource) SAXNotSupportedException(org.xml.sax.SAXNotSupportedException) XMLContext(org.hibernate.cfg.annotations.reflection.XMLContext) BufferedInputStream(java.io.BufferedInputStream) BufferedInputStream(java.io.BufferedInputStream) InputStream(java.io.InputStream) SAXReader(org.dom4j.io.SAXReader) XMLHelper(org.hibernate.internal.util.xml.XMLHelper) ErrorLogger(org.hibernate.internal.util.xml.ErrorLogger)

Example 2 with ErrorLogger

use of org.hibernate.internal.util.xml.ErrorLogger in project hibernate-orm by hibernate.

the class XMLContextTest method testAll.

@Test
public void testAll() throws Exception {
    final XMLHelper xmlHelper = new XMLHelper(ClassLoaderServiceTestingImpl.INSTANCE);
    final XMLContext context = new XMLContext(ClassLoaderAccessTestingImpl.INSTANCE);
    InputStream is = ClassLoaderServiceTestingImpl.INSTANCE.locateResourceStream("org/hibernate/test/annotations/reflection/orm.xml");
    Assert.assertNotNull("ORM.xml not found", is);
    final ErrorLogger errorLogger = new ErrorLogger();
    final SAXReader saxReader = xmlHelper.createSAXReader(errorLogger, EJB3DTDEntityResolver.INSTANCE);
    try {
        saxReader.setFeature("http://apache.org/xml/features/validation/schema", true);
    } catch (SAXNotSupportedException e) {
        saxReader.setValidation(false);
    }
    org.dom4j.Document doc;
    try {
        doc = saxReader.read(new InputSource(new BufferedInputStream(is)));
    } finally {
        try {
            is.close();
        } catch (IOException ioe) {
        //log.warn( "Could not close input stream", ioe );
        }
    }
    Assert.assertFalse(errorLogger.hasErrors());
    context.addDocument(doc);
}
Also used : InputSource(org.xml.sax.InputSource) SAXNotSupportedException(org.xml.sax.SAXNotSupportedException) XMLContext(org.hibernate.cfg.annotations.reflection.XMLContext) BufferedInputStream(java.io.BufferedInputStream) BufferedInputStream(java.io.BufferedInputStream) InputStream(java.io.InputStream) SAXReader(org.dom4j.io.SAXReader) IOException(java.io.IOException) XMLHelper(org.hibernate.internal.util.xml.XMLHelper) ErrorLogger(org.hibernate.internal.util.xml.ErrorLogger) Test(org.junit.Test)

Aggregations

BufferedInputStream (java.io.BufferedInputStream)2 InputStream (java.io.InputStream)2 SAXReader (org.dom4j.io.SAXReader)2 XMLContext (org.hibernate.cfg.annotations.reflection.XMLContext)2 ErrorLogger (org.hibernate.internal.util.xml.ErrorLogger)2 XMLHelper (org.hibernate.internal.util.xml.XMLHelper)2 InputSource (org.xml.sax.InputSource)2 SAXNotSupportedException (org.xml.sax.SAXNotSupportedException)2 IOException (java.io.IOException)1 Test (org.junit.Test)1