org.hibernate.osgi.OSGiClassLoaderServiceImpl Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of hibernate-osgi Show documentation
Show all versions of hibernate-osgi Show documentation
Support for running Hibernate O/RM in OSGi environments
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or .
*/
package org.hibernate.osgi;
import java.util.LinkedHashSet;
import org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl;
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
/**
* The ClassLoaderService that should be used when running in OSGi;
* this helps for example to load the Services correctly.
*
* @author Sanne Grinovero
*/
public class OSGiClassLoaderServiceImpl extends ClassLoaderServiceImpl implements ClassLoaderService {
private final OsgiServiceUtil osgiServiceUtil;
private final OsgiClassLoader osgiClassLoader;
public OSGiClassLoaderServiceImpl(OsgiClassLoader osgiClassLoader, OsgiServiceUtil osgiServiceUtil) {
super( osgiClassLoader );
this.osgiClassLoader = osgiClassLoader;
this.osgiServiceUtil = osgiServiceUtil;
}
@Override
public LinkedHashSet loadJavaServices(Class serviceContract) {
Iterable parentDiscoveredServices = super.loadJavaServices( serviceContract );
S[] serviceImpls = osgiServiceUtil.getServiceImpls(serviceContract);
LinkedHashSet composite = new LinkedHashSet();
for ( S service : parentDiscoveredServices ) {
composite.add( service );
}
for ( S service : serviceImpls ) {
composite.add( service );
}
return composite;
}
@Override
public void stop() {
super.stop();
osgiClassLoader.stop();
osgiServiceUtil.stop();
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy