Skip to content
Permalink
Browse files
[CXF-5568] Optionally disabling the selection of bean services
git-svn-id: https://svn.apache.org/repos/asf/cxf/trunk@1569383 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
Sergey Beryozkin committed Feb 18, 2014
1 parent 8e4f8d8 commit 15bcc140f0b8661ab160cf05e23954c44401829e
Showing 1 changed file with 12 additions and 0 deletions.
@@ -24,18 +24,26 @@
import java.util.logging.Logger;

import org.apache.cxf.common.logging.LogUtils;
import org.apache.cxf.common.util.PropertyUtils;
import org.apache.cxf.configuration.ConfiguredBeanLocator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;

public class OSGiBeanLocator implements ConfiguredBeanLocator {
private static final Logger LOG = LogUtils.getL7dLogger(OSGiBeanLocator.class);
private static final String COMPATIBLE_LOCATOR_PROP = "org.apache.cxf.bus.osgi.locator";
private static final String COMPATIBLE_LOCATOR_PROP_CHECK = COMPATIBLE_LOCATOR_PROP + ".check";

final ConfiguredBeanLocator cbl;
final BundleContext context;
private boolean checkCompatibleLocators;

public OSGiBeanLocator(ConfiguredBeanLocator c, BundleContext ctx) {
cbl = c;
context = ctx;

Object checkProp = context.getProperty(COMPATIBLE_LOCATOR_PROP_CHECK);
checkCompatibleLocators = checkProp == null || PropertyUtils.isTrue(checkProp);
}
public <T> T getBeanOfType(String name, Class<T> type) {
return cbl.getBeanOfType(name, type);
@@ -56,6 +64,10 @@ private <T> List<T> getBeansFromOsgiService(Class<T> type) {
ServiceReference refs[] = context.getServiceReferences(type.getName(), null);
if (refs != null) {
for (ServiceReference r : refs) {
if (checkCompatibleLocators
&& !PropertyUtils.isTrue(r.getProperty(COMPATIBLE_LOCATOR_PROP))) {
continue;
}
list.add(type.cast(context.getService(r)));
}
}

0 comments on commit 15bcc14

Please sign in to comment.