private static NamespaceHandlerResolver tryFindNamespaceHandler(ApplicationContext ctx) { try { SpringBeanLocator sbl = new SpringBeanLocator(ctx); List<NamespaceHandlerResolver> r = sbl.getOSGiServices(NamespaceHandlerResolver.class); if (r != null && !r.isEmpty()) { return r.get(0); } } catch (Throwable t) { //ignore } return null; }
private void loadOSGIContext(Bus b) { bundleContext = findBundleContext(context, b); if (bundleContext == null) { osgi = false; } }
private Class<?> findContextClass(Class<?> cls) { for (Class<?> c : cls.getInterfaces()) { if ("org.osgi.framework.BundleContext".equals(c.getName())) { return c; } } for (Class<?> c : cls.getInterfaces()) { Class<?> c2 = findContextClass(c); if (c2 != null) { return c2; } } Class<?> c2 = findContextClass(cls.getSuperclass()); if (c2 != null) { return c2; } return cls; }
private Object findBundleContext(ApplicationContext applicationContext, Bus b) { Object answer = null; ApplicationContext aContext = applicationContext; // try to find out the bundleContext by going through the parent context while (aContext != null && answer == null) { answer = getBundleContext(aContext, b); aContext = aContext.getParent(); } return answer; }
public SpringBeanLocator(ApplicationContext ctx, Bus bus) { context = ctx; if (bus != null) { orig = bus.getExtension(ConfiguredBeanLocator.class); if (orig instanceof ExtensionManagerImpl) { List<String> names = new ArrayList<>(); for (String s : ctx.getBeanDefinitionNames()) { names.add(s); for (String s2 : ctx.getAliases(s)) { names.add(s2); } } ((ExtensionManagerImpl)orig).removeBeansOfNames(names); } } loadOSGIContext(bus); }
/** {@inheritDoc}*/ public <T> Collection<? extends T> getBeansOfType(Class<T> type) { Set<String> s = new LinkedHashSet<>(Arrays.asList(context.getBeanNamesForType(type, false, false))); s.removeAll(passThroughs); List<T> lst = new LinkedList<>(); for (String n : s) { lst.add(type.cast(context.getBean(n, type))); } lst.addAll(orig.getBeansOfType(type)); if (lst.isEmpty()) { tryOSGI(lst, type); } return lst; } private <T> void tryOSGI(Collection<T> lst, Class<T> type) {
ConfiguredBeanLocator loc = getExtension(ConfiguredBeanLocator.class); if (!(loc instanceof SpringBeanLocator)) { setExtension(new SpringBeanLocator(applicationContext, this), ConfiguredBeanLocator.class);
private Object findBundleContext(ApplicationContext applicationContext, Bus b) { Object answer = null; ApplicationContext aContext = applicationContext; // try to find out the bundleContext by going through the parent context while (aContext != null && answer == null) { answer = getBundleContext(aContext, b); aContext = aContext.getParent(); } return answer; }
public SpringBeanLocator(ApplicationContext ctx, Bus bus) { context = ctx; if (bus != null) { orig = bus.getExtension(ConfiguredBeanLocator.class); if (orig instanceof ExtensionManagerImpl) { List<String> names = new ArrayList<String>(); for (String s : ctx.getBeanDefinitionNames()) { ConfigurableApplicationContext ctxt = (ConfigurableApplicationContext)context; BeanDefinition def = ctxt.getBeanFactory().getBeanDefinition(s); String cn = def.getBeanClassName(); if (OldSpringSupport.class.getName().equals(cn)) { passThroughs.add(s); for (String s2 : ctx.getAliases(s)) { passThroughs.add(s2); } } else { names.add(s); for (String s2 : ctx.getAliases(s)) { names.add(s2); } } } ((ExtensionManagerImpl)orig).removeBeansOfNames(names); } } loadOSGIContext(bus); }
/** {@inheritDoc}*/ public <T> Collection<? extends T> getBeansOfType(Class<T> type) { Set<String> s = new LinkedHashSet<>(Arrays.asList(context.getBeanNamesForType(type, false, false))); s.removeAll(passThroughs); List<T> lst = new LinkedList<>(); for (String n : s) { lst.add(type.cast(context.getBean(n, type))); } lst.addAll(orig.getBeansOfType(type)); if (lst.isEmpty()) { tryOSGI(lst, type); } return lst; } private <T> void tryOSGI(Collection<T> lst, Class<T> type) {
ConfiguredBeanLocator loc = getExtension(ConfiguredBeanLocator.class); if (!(loc instanceof SpringBeanLocator)) { setExtension(new SpringBeanLocator(applicationContext, this), ConfiguredBeanLocator.class);
private static NamespaceHandlerResolver tryFindNamespaceHandler(ApplicationContext ctx) { try { SpringBeanLocator sbl = new SpringBeanLocator(ctx); List<NamespaceHandlerResolver> r = sbl.getOSGiServices(NamespaceHandlerResolver.class); if (r != null && !r.isEmpty()) { return r.get(0); } } catch (Exception t) { LOG.log(Level.FINEST, "Could not find NamespaceHandlerResolver", t); } return null; }
private Class<?> findContextClass(Class<?> cls) { for (Class<?> c : cls.getInterfaces()) { if (c.getName().equals("org.osgi.framework.BundleContext")) { return c; } } for (Class<?> c : cls.getInterfaces()) { Class<?> c2 = findContextClass(c); if (c2 != null) { return c2; } } Class<?> c2 = findContextClass(cls.getSuperclass()); if (c2 != null) { return c2; } return cls; }
private Object findBundleContext(ApplicationContext applicationContext, Bus b) { Object answer = null; ApplicationContext aContext = applicationContext; // try to find out the bundleContext by going through the parent context while (aContext != null && answer == null) { answer = getBundleContext(aContext, b); aContext = aContext.getParent(); } return answer; }
private void loadOSGIContext(Bus b) { bundleContext = findBundleContext(context, b); if (bundleContext == null) { osgi = false; } }
public SpringBeanLocator(ApplicationContext ctx, Bus bus) { context = ctx; if (bus != null) { orig = bus.getExtension(ConfiguredBeanLocator.class); if (orig instanceof ExtensionManagerImpl) { List<String> names = new ArrayList<>(); for (String s : ctx.getBeanDefinitionNames()) { names.add(s); for (String s2 : ctx.getAliases(s)) { names.add(s2); } } ((ExtensionManagerImpl)orig).removeBeansOfNames(names); } } loadOSGIContext(bus); }
/** {@inheritDoc}*/ public <T> Collection<? extends T> getBeansOfType(Class<T> type) { Set<String> s = new LinkedHashSet<String>(Arrays.asList(context.getBeanNamesForType(type, false, false))); s.removeAll(passThroughs); List<T> lst = new LinkedList<T>(); for (String n : s) { lst.add(type.cast(context.getBean(n, type))); } lst.addAll(orig.getBeansOfType(type)); if (lst.isEmpty()) { tryOSGI(lst, type); } return lst; } private <T> void tryOSGI(Collection<T> lst, Class<T> type) {
ConfiguredBeanLocator loc = getExtension(ConfiguredBeanLocator.class); if (!(loc instanceof SpringBeanLocator)) { setExtension(new SpringBeanLocator(applicationContext, this), ConfiguredBeanLocator.class);
private static NamespaceHandlerResolver tryFindNamespaceHandler(ApplicationContext ctx) { try { SpringBeanLocator sbl = new SpringBeanLocator(ctx); List<NamespaceHandlerResolver> r = sbl.getOSGiServices(NamespaceHandlerResolver.class); if (r != null && !r.isEmpty()) { return r.get(0); } } catch (Throwable t) { //ignore } return null; }
private Class<?> findContextClass(Class<?> cls) { for (Class<?> c : cls.getInterfaces()) { if ("org.osgi.framework.BundleContext".equals(c.getName())) { return c; } } for (Class<?> c : cls.getInterfaces()) { Class<?> c2 = findContextClass(c); if (c2 != null) { return c2; } } Class<?> c2 = findContextClass(cls.getSuperclass()); if (c2 != null) { return c2; } return cls; }