Search in sources :

Example 6 with ArchiveEntry

use of org.hibernate.boot.archive.spi.ArchiveEntry in project hibernate-orm by hibernate.

the class OsgiArchiveDescriptor method visitArchive.

@Override
public void visitArchive(ArchiveContext context) {
    final Collection<String> resources = bundleWiring.listResources("/", "*", BundleWiring.LISTRESOURCES_RECURSE);
    for (final String resource : resources) {
        // TODO: Is there a better way to check this?  Karaf is including directories.
        if (!resource.endsWith("/")) {
            try {
                // TODO: Is using resource as the names correct?
                final InputStreamAccess inputStreamAccess = new InputStreamAccess() {

                    @Override
                    public String getStreamName() {
                        return resource;
                    }

                    @Override
                    public InputStream accessInputStream() {
                        return openInputStream();
                    }

                    private InputStream openInputStream() {
                        try {
                            return persistenceBundle.getResource(resource).openStream();
                        } catch (IOException e) {
                            throw new PersistenceException("Unable to open an InputStream on the OSGi Bundle resource!", e);
                        }
                    }
                };
                final ArchiveEntry entry = new ArchiveEntry() {

                    @Override
                    public String getName() {
                        return resource;
                    }

                    @Override
                    public String getNameWithinArchive() {
                        return resource;
                    }

                    @Override
                    public InputStreamAccess getStreamAccess() {
                        return inputStreamAccess;
                    }
                };
                context.obtainArchiveEntryHandler(entry).handleEntry(entry, context);
            } catch (Exception e) {
                LOG.unableToLoadScannedClassOrResource(e);
            }
        }
    }
}
Also used : InputStreamAccess(org.hibernate.boot.archive.spi.InputStreamAccess) PersistenceException(javax.persistence.PersistenceException) ArchiveEntry(org.hibernate.boot.archive.spi.ArchiveEntry) IOException(java.io.IOException) PersistenceException(javax.persistence.PersistenceException) IOException(java.io.IOException)

Aggregations

ArchiveEntry (org.hibernate.boot.archive.spi.ArchiveEntry)6 InputStreamAccess (org.hibernate.boot.archive.spi.InputStreamAccess)6 IOException (java.io.IOException)4 JarFile (java.util.jar.JarFile)3 ZipEntry (java.util.zip.ZipEntry)3 ArchiveException (org.hibernate.boot.archive.spi.ArchiveException)3 JarInputStream (java.util.jar.JarInputStream)2 BufferedInputStream (java.io.BufferedInputStream)1 File (java.io.File)1 InputStream (java.io.InputStream)1 URISyntaxException (java.net.URISyntaxException)1 JarEntry (java.util.jar.JarEntry)1 PersistenceException (javax.persistence.PersistenceException)1 ArchiveEntryHandler (org.hibernate.boot.archive.spi.ArchiveEntryHandler)1 VirtualFile (org.jboss.vfs.VirtualFile)1