com.github.dynamicextensionsalfresco.blueprint.OsgiAutowireBeanFactory Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of blueprint-integration Show documentation
Show all versions of blueprint-integration Show documentation
Adds an OSGi container to alfresco repository supporting dynamic code reloading, classpath isolation and a bunch of other useful features
package com.github.dynamicextensionsalfresco.blueprint;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import com.github.dynamicextensionsalfresco.osgi.spring.AutowireBeanFactory;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.config.DependencyDescriptor;
/**
* Resolves dependencies on OSGi services or the {@link BundleContext}.
*
* @author Laurens Fridael
*
*/
class OsgiAutowireBeanFactory extends AutowireBeanFactory {
private final BundleContext bundleContext;
OsgiAutowireBeanFactory(final BeanFactory parentBeanFactory, final BundleContext bundleContext) {
super(parentBeanFactory);
this.bundleContext = bundleContext;
}
/* Main operations */
@Override
@SuppressWarnings({ "rawtypes", "unchecked" })
protected Map findAutowireCandidates(final String beanName, final Class requiredType,
final DependencyDescriptor descriptor) {
Map candidateBeansByName = Collections.emptyMap();
if (BundleContext.class.isAssignableFrom(requiredType)) {
candidateBeansByName = new HashMap(1);
candidateBeansByName.put(requiredType.getName(), bundleContext);
} else {
final ServiceReference serviceReference = bundleContext.getServiceReference(requiredType);
if (serviceReference != null) {
candidateBeansByName = new HashMap(1);
candidateBeansByName.put(requiredType.getName(), bundleContext.getService(serviceReference));
}
}
if (candidateBeansByName.isEmpty()) {
candidateBeansByName = super.findAutowireCandidates(beanName, requiredType, descriptor);
}
return candidateBeansByName;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy