HHH-10346 cleanup
This commit is contained in:
parent
0af33132a4
commit
94214f3488
|
@ -23,11 +23,6 @@
|
||||||
*/
|
*/
|
||||||
package org.hibernate.osgi;
|
package org.hibernate.osgi;
|
||||||
|
|
||||||
import java.util.Dictionary;
|
|
||||||
import java.util.Hashtable;
|
|
||||||
|
|
||||||
import javax.persistence.spi.PersistenceProvider;
|
|
||||||
|
|
||||||
import org.hibernate.Session;
|
import org.hibernate.Session;
|
||||||
import org.hibernate.SessionFactory;
|
import org.hibernate.SessionFactory;
|
||||||
import org.hibernate.internal.util.ClassLoaderHelper;
|
import org.hibernate.internal.util.ClassLoaderHelper;
|
||||||
|
@ -39,6 +34,10 @@ import org.osgi.framework.BundleListener;
|
||||||
import org.osgi.framework.FrameworkUtil;
|
import org.osgi.framework.FrameworkUtil;
|
||||||
import org.osgi.framework.ServiceRegistration;
|
import org.osgi.framework.ServiceRegistration;
|
||||||
|
|
||||||
|
import javax.persistence.spi.PersistenceProvider;
|
||||||
|
import java.util.Dictionary;
|
||||||
|
import java.util.Hashtable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This BundleActivator provides three different uses of Hibernate in OSGi
|
* This BundleActivator provides three different uses of Hibernate in OSGi
|
||||||
* environments:
|
* environments:
|
||||||
|
|
|
@ -23,6 +23,11 @@
|
||||||
*/
|
*/
|
||||||
package org.hibernate.osgi;
|
package org.hibernate.osgi;
|
||||||
|
|
||||||
|
import org.hibernate.service.spi.Stoppable;
|
||||||
|
import org.osgi.framework.Bundle;
|
||||||
|
import org.osgi.framework.BundleReference;
|
||||||
|
import org.osgi.framework.wiring.BundleWiring;
|
||||||
|
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Enumeration;
|
import java.util.Enumeration;
|
||||||
|
@ -32,12 +37,6 @@ import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.NoSuchElementException;
|
import java.util.NoSuchElementException;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.hibernate.service.spi.Stoppable;
|
|
||||||
import org.osgi.framework.Bundle;
|
|
||||||
import org.osgi.framework.BundleReference;
|
|
||||||
import org.osgi.framework.wiring.BundleWiring;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Custom OSGI ClassLoader helper which knows all the "interesting"
|
* Custom OSGI ClassLoader helper which knows all the "interesting"
|
||||||
* class loaders and bundles. Encapsulates the OSGi related CL capabilities.
|
* class loaders and bundles. Encapsulates the OSGi related CL capabilities.
|
||||||
|
@ -49,7 +48,6 @@ public class OsgiClassLoader extends ClassLoader implements Stoppable {
|
||||||
// Leave these as Sets -- addClassLoader or addBundle may be called more
|
// Leave these as Sets -- addClassLoader or addBundle may be called more
|
||||||
// than once if a SF or EMF is closed and re-created.
|
// than once if a SF or EMF is closed and re-created.
|
||||||
private Set<ClassLoader> classLoaders = new LinkedHashSet<ClassLoader>();
|
private Set<ClassLoader> classLoaders = new LinkedHashSet<ClassLoader>();
|
||||||
private Set<Bundle> bundles = new LinkedHashSet<Bundle>();
|
|
||||||
|
|
||||||
private Map<String, Class<?>> classCache = new HashMap<String, Class<?>>();
|
private Map<String, Class<?>> classCache = new HashMap<String, Class<?>>();
|
||||||
private Map<String, URL> resourceCache = new HashMap<String, URL>();
|
private Map<String, URL> resourceCache = new HashMap<String, URL>();
|
||||||
|
@ -74,18 +72,6 @@ public class OsgiClassLoader extends ClassLoader implements Stoppable {
|
||||||
return classCache.get( name );
|
return classCache.get( name );
|
||||||
}
|
}
|
||||||
|
|
||||||
for ( Bundle bundle : bundles ) {
|
|
||||||
try {
|
|
||||||
final Class clazz = bundle.loadClass( name );
|
|
||||||
if ( clazz != null ) {
|
|
||||||
classCache.put( name, clazz );
|
|
||||||
return clazz;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch ( Exception ignore ) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for ( ClassLoader classLoader : classLoaders ) {
|
for ( ClassLoader classLoader : classLoaders ) {
|
||||||
try {
|
try {
|
||||||
final Class clazz = classLoader.loadClass( name );
|
final Class clazz = classLoader.loadClass( name );
|
||||||
|
@ -113,18 +99,6 @@ public class OsgiClassLoader extends ClassLoader implements Stoppable {
|
||||||
return resourceCache.get( name );
|
return resourceCache.get( name );
|
||||||
}
|
}
|
||||||
|
|
||||||
for ( Bundle bundle : bundles ) {
|
|
||||||
try {
|
|
||||||
final URL resource = bundle.getResource( name );
|
|
||||||
if ( resource != null ) {
|
|
||||||
resourceCache.put( name, resource );
|
|
||||||
return resource;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch ( Exception ignore ) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for ( ClassLoader classLoader : classLoaders ) {
|
for ( ClassLoader classLoader : classLoaders ) {
|
||||||
try {
|
try {
|
||||||
final URL resource = classLoader.getResource( name );
|
final URL resource = classLoader.getResource( name );
|
||||||
|
@ -154,17 +128,6 @@ public class OsgiClassLoader extends ClassLoader implements Stoppable {
|
||||||
protected Enumeration<URL> findResources(String name) {
|
protected Enumeration<URL> findResources(String name) {
|
||||||
final List<Enumeration<URL>> enumerations = new ArrayList<Enumeration<URL>>();
|
final List<Enumeration<URL>> enumerations = new ArrayList<Enumeration<URL>>();
|
||||||
|
|
||||||
for ( Bundle bundle : bundles ) {
|
|
||||||
try {
|
|
||||||
final Enumeration<URL> resources = bundle.getResources( name );
|
|
||||||
if ( resources != null ) {
|
|
||||||
enumerations.add( resources );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch ( Exception ignore ) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for ( ClassLoader classLoader : classLoaders ) {
|
for ( ClassLoader classLoader : classLoaders ) {
|
||||||
try {
|
try {
|
||||||
final Enumeration<URL> resources = classLoader.getResources( name );
|
final Enumeration<URL> resources = classLoader.getResources( name );
|
||||||
|
@ -216,13 +179,12 @@ public class OsgiClassLoader extends ClassLoader implements Stoppable {
|
||||||
* @param bundle The Bundle to add
|
* @param bundle The Bundle to add
|
||||||
*/
|
*/
|
||||||
public void addBundle( Bundle bundle ) {
|
public void addBundle( Bundle bundle ) {
|
||||||
addClassLoader( bundle.adapt(BundleWiring.class).getClassLoader() );
|
addClassLoader( bundle.adapt( BundleWiring.class ).getClassLoader() );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void stop() {
|
public void stop() {
|
||||||
classLoaders.clear();
|
classLoaders.clear();
|
||||||
bundles.clear();
|
|
||||||
classCache.clear();
|
classCache.clear();
|
||||||
resourceCache.clear();
|
resourceCache.clear();
|
||||||
}
|
}
|
||||||
|
@ -237,8 +199,6 @@ public class OsgiClassLoader extends ClassLoader implements Stoppable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (classLoaders.removeAll(toRemove)) {
|
classLoaders.removeAll(toRemove);
|
||||||
clear();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue