Search in sources :

Example 1 with XMLHelper

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

the class EnversServiceImpl method initialize.

@Override
public void initialize(final MetadataImplementor metadata, final MappingCollector mappingCollector) {
    if (initialized) {
        throw new UnsupportedOperationException("EnversService#initialize should be called only once");
    }
    initialized = true;
    this.serviceRegistry = metadata.getMetadataBuildingOptions().getServiceRegistry();
    this.classLoaderService = serviceRegistry.getService(ClassLoaderService.class);
    this.xmlHelper = new XMLHelper(classLoaderService);
    doInitialize(metadata, mappingCollector, serviceRegistry);
}
Also used : XMLHelper(org.hibernate.internal.util.xml.XMLHelper) ClassLoaderService(org.hibernate.boot.registry.classloading.spi.ClassLoaderService)

Example 2 with XMLHelper

use of org.hibernate.internal.util.xml.XMLHelper 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 3 with XMLHelper

use of org.hibernate.internal.util.xml.XMLHelper 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

XMLHelper (org.hibernate.internal.util.xml.XMLHelper)3 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 InputSource (org.xml.sax.InputSource)2 SAXNotSupportedException (org.xml.sax.SAXNotSupportedException)2 IOException (java.io.IOException)1 ClassLoaderService (org.hibernate.boot.registry.classloading.spi.ClassLoaderService)1 Test (org.junit.Test)1