@Override public T produce(CreationalContext<T> ctx) { T context = super.produce(ctx); // Register the context in the OSGi registry BundleContext bundle = BundleContextUtils.getBundleContext(getClass()); context.getManagementStrategy().addEventNotifier(new OsgiCamelContextPublisher(bundle)); if (!(context instanceof DefaultCamelContext)) { // Fail fast for the time being to avoid side effects by some methods get declared on the CamelContext interface throw new InjectionException("Camel CDI requires Camel context [" + context.getName() + "] to be a subtype of DefaultCamelContext"); } DefaultCamelContext adapted = context.adapt(DefaultCamelContext.class); adapted.setRegistry(OsgiCamelContextHelper.wrapRegistry(context, context.getRegistry(), bundle)); CamelContextNameStrategy strategy = context.getNameStrategy(); OsgiCamelContextHelper.osgiUpdate(adapted, bundle); // FIXME: the above call should not override explicit strategies provided by the end user or should decorate them instead of overriding them completely if (!(strategy instanceof DefaultCamelContextNameStrategy)) { context.setNameStrategy(strategy); } return context; }
@Override public T produce(CreationalContext<T> cc) { T context = super.produce(cc); // Register the context in the OSGi registry BundleContext bundle = BundleContextUtils.getBundleContext(getClass()); context.getManagementStrategy().addEventNotifier(new OsgiCamelContextPublisher(bundle)); if (!(context instanceof DefaultCamelContext)) // Fail fast for the time being to avoid side effects by some methods get declared on the CamelContext interface throw new DeploymentException("Camel CDI requires Camel context [" + context.getName() + "] to be a subtype of DefaultCamelContext"); DefaultCamelContext adapted = context.adapt(DefaultCamelContext.class); adapted.setRegistry(OsgiCamelContextHelper.wrapRegistry(context, context.getRegistry(), bundle)); CamelContextNameStrategy strategy = context.getNameStrategy(); OsgiCamelContextHelper.osgiUpdate(adapted, bundle); // FIXME: the above call should not override explicit strategies provided by the end user or should decorate them instead of overriding them completely if (!(strategy instanceof DefaultCamelContextNameStrategy)) context.setNameStrategy(strategy); return context; }
@Override protected TypeConverter createTypeConverter() { // CAMEL-3614: make sure we use a bundle context which imports org.apache.camel.impl.converter package BundleContext ctx = BundleContextUtils.getBundleContext(getClass()); if (ctx == null) { ctx = bundleContext; } FactoryFinder finder = new OsgiFactoryFinderResolver(bundleContext).resolveDefaultFactoryFinder(getClassResolver()); return new OsgiTypeConverter(ctx, this, getInjector(), finder); }
@Override protected TypeConverter createTypeConverter() { // CAMEL-3614: make sure we use a bundle context which imports org.apache.camel.impl.converter package BundleContext ctx = BundleContextUtils.getBundleContext(getClass()); if (ctx == null) { ctx = _bundleContext; } FactoryFinder finder = new OsgiFactoryFinderResolver(_bundleContext).resolveDefaultFactoryFinder(getClassResolver()); return new OsgiTypeConverter(ctx, getInjector(), finder); }
@Override public Map<String, Properties> findComponents() throws LoadPropertiesException, IOException { return BundleContextUtils.findComponents(bundleContext, this); }
@Override public String getComponentDocumentation(String componentName) throws IOException { return BundleContextUtils.getComponentDocumentation(bundleContext, this, componentName); }
private static boolean hasBundleContext(Class clazz) { return BundleContextUtils.getBundleContext(clazz) != null; }