protected DataFormat getDataFormat(String name, CamelContext context) { LOG.trace("Finding DataFormat: {}", name); try { ServiceReference<?>[] refs = bundleContext.getServiceReferences(DataFormatResolver.class.getName(), "(dataformat=" + name + ")"); if (refs != null) { for (ServiceReference<?> ref : refs) { Object service = bundleContext.getService(ref); if (DataFormatResolver.class.isAssignableFrom(service.getClass())) { DataFormatResolver resolver = (DataFormatResolver) service; return resolver.resolveDataFormat(name, context); } } } return null; } catch (InvalidSyntaxException e) { throw ObjectHelper.wrapRuntimeCamelException(e); } }
@Override public DataFormat resolveDataFormat(String name, CamelContext context) { try { Object bean = context.getRegistry().lookupByName(".camelBlueprint.dataformatResolver." + name); if (bean instanceof DataFormatResolver) { LOG.debug("Found dataformat resolver: {} in registry: {}", name, bean); return ((DataFormatResolver) bean).resolveDataFormat(name, context); } } catch (Exception e) { LOG.trace("Ignored error looking up bean: " + name + " due: " + e.getMessage(), e); } return super.resolveDataFormat(name, context); }
private static ComponentMetadata getDataformatResolverReference(ParserContext context, String dataformat) { // we cannot resolve dataformat names using property placeholders at this point in time if (dataformat.startsWith(PropertiesComponent.DEFAULT_PREFIX_TOKEN)) { return null; } ComponentDefinitionRegistry componentDefinitionRegistry = context.getComponentDefinitionRegistry(); ComponentMetadata cm = componentDefinitionRegistry.getComponentDefinition(".camelBlueprint.dataformatResolver." + dataformat); if (cm == null) { MutableReferenceMetadata svc = context.createMetadata(MutableReferenceMetadata.class); svc.setId(".camelBlueprint.dataformatResolver." + dataformat); svc.setFilter("(dataformat=" + dataformat + ")"); svc.setAvailability(componentDefinitionRegistry.containsComponentDefinition(dataformat) ? 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, DataFormatResolver.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(DataFormatResolver.class.getName()) != DataFormatResolver.class) { throw new UnsupportedOperationException(); } svc.setInterface(DataFormatResolver.class.getName()); } catch (Throwable t2) { throw new UnsupportedOperationException(); } } componentDefinitionRegistry.registerComponentDefinition(svc); cm = svc; } return cm; }
public DataFormatResolver getDataFormatResolver() { return dataFormatResolver; }
public void setDataFormatResolver(DataFormatResolver dataFormatResolver) { this.dataFormatResolver = dataFormatResolver; }
public void register() { doRegister(DataFormatResolver.class, "dataformat", dataformats.keySet()); }
@Override public DataFormatResolver getDataFormatResolver() { return context.getDataFormatResolver(); }
@Override public void setDataFormatResolver(DataFormatResolver dataFormatResolver) { context.setDataFormatResolver(dataFormatResolver); }
/** * Gets the current data format resolver * * @return the resolver */ DataFormatResolver getDataFormatResolver();
/** * Sets a custom data format resolver * * @param dataFormatResolver the resolver */ void setDataFormatResolver(DataFormatResolver dataFormatResolver);