protected Component getComponent(String name, CamelContext context) throws Exception { LOG.trace("Finding Component: {}", name); try { ServiceReference<?>[] refs = bundleContext.getServiceReferences(ComponentResolver.class.getName(), "(component=" + name + ")"); if (refs != null) { for (ServiceReference<?> ref : refs) { Object service = bundleContext.getService(ref); if (ComponentResolver.class.isAssignableFrom(service.getClass())) { ComponentResolver resolver = (ComponentResolver) service; return resolver.resolveComponent(name, context); } } } return null; } catch (InvalidSyntaxException e) { throw ObjectHelper.wrapRuntimeCamelException(e); } }
private static ComponentMetadata getComponentResolverReference(ParserContext context, String component) { // we cannot resolve component names using property placeholders at this point in time if (component.startsWith(PropertiesComponent.DEFAULT_PREFIX_TOKEN)) { return null; } ComponentDefinitionRegistry componentDefinitionRegistry = context.getComponentDefinitionRegistry(); ComponentMetadata cm = componentDefinitionRegistry.getComponentDefinition(".camelBlueprint.componentResolver." + component); if (cm == null) { MutableReferenceMetadata svc = context.createMetadata(MutableReferenceMetadata.class); svc.setId(".camelBlueprint.componentResolver." + component); svc.setFilter("(component=" + component + ")"); svc.setAvailability(componentDefinitionRegistry.containsComponentDefinition(component) ? AVAILABILITY_OPTIONAL : AVAILABILITY_MANDATORY); try { // Try to set the runtime interface (only with aries blueprint > 0.1 svc.getClass().getMethod("setRuntimeInterface", Class.class).invoke(svc, ComponentResolver.class); } catch (Throwable t) { // Check if the bundle can see the class try { PassThroughMetadata ptm = (PassThroughMetadata) componentDefinitionRegistry.getComponentDefinition("blueprintBundle"); Bundle b = (Bundle) ptm.getObject(); if (b.loadClass(ComponentResolver.class.getName()) != ComponentResolver.class) { throw new UnsupportedOperationException(); } svc.setInterface(ComponentResolver.class.getName()); } catch (Throwable t2) { throw new UnsupportedOperationException(); } } componentDefinitionRegistry.registerComponentDefinition(svc); cm = svc; } return cm; }
@Override @SuppressWarnings("rawtypes") protected void addServicesOnStartup(List<KeyValueHolder<String, KeyValueHolder<Object, Dictionary>>> services) { Dictionary<String, String> dict1 = new Hashtable<String, String>(); dict1.put("component", "fakeservice1"); Dictionary<String, String> dict2 = new Hashtable<String, String>(); dict2.put("component", "fakeservice2"); services.add(asKeyValueService(ComponentResolver.class.getName(), mockComponentOne, dict1)); services.add(asKeyValueService(ComponentResolver.class.getName(), mockComponentTwo, dict2)); }
@Override public void setup(final CamelContext camelctx) { if (camelctx instanceof DefaultCamelContext) { DefaultCamelContext defaultctx = (DefaultCamelContext) camelctx; ComponentResolver delegate = defaultctx.getComponentResolver(); defaultctx.setComponentResolver(new WildFlyComponentResolver(delegate)); } }
public ComponentResolver getComponentResolver() { if (componentResolver == null) { componentResolver = createComponentResolver(); } return componentResolver; }
public void setComponentResolver(ComponentResolver componentResolver) { this.componentResolver = componentResolver; }
/** * Lazily create a default implementation */ protected ComponentResolver createComponentResolver() { return new DefaultComponentResolver(); }
public void register() { doRegister(ComponentResolver.class, "component", components.keySet()); }
@Override protected void addServicesOnStartup(Map<String, KeyValueHolder<Object, Dictionary>> services) { ComponentResolver testResolver = new DefaultComponentResolver(); services.put(ComponentResolver.class.getName(), asService(testResolver, "component", "mllp")); }
@Override @Inject(optional = true) public void setComponentResolver(ComponentResolver componentResolver) { super.setComponentResolver(componentResolver); }
WildFlyComponentResolver(ComponentResolver delegate) { this.delegate = delegate; }