public BaseTypeConverterRegistry(PackageScanClassResolver resolver, Injector injector, FactoryFinder factoryFinder) { this.resolver = resolver; this.injector = injector; this.factoryFinder = factoryFinder; this.typeConverterLoaders.add(new AnnotationTypeConverterLoader(resolver)); // add to string first as it will then be last in the last as to string can nearly // always convert something to a string so we want it only as the last resort // ToStringTypeConverter should NOT allow to be promoted addFallbackTypeConverter(new ToStringTypeConverter(), false); // enum is okay to be promoted addFallbackTypeConverter(new EnumTypeConverter(), true); // arrays is okay to be promoted addFallbackTypeConverter(new ArrayTypeConverter(), true); // and future should also not allowed to be promoted addFallbackTypeConverter(new FutureTypeConverter(this), false); // add sync processor to async processor converter is to be promoted addFallbackTypeConverter(new AsyncProcessorTypeConverter(), true); }
/** * Associates camel context with given service domain. * * @param domain Domain to associate. */ public void setServiceDomain(ServiceDomain domain) { _domain = domain; for (EventNotifier notifier : getManagementStrategy().getEventNotifiers()) { if (notifier instanceof CamelEventBridge) { ((CamelEventBridge) notifier).setEventPublisher(domain.getEventPublisher()); } } PackageScanClassResolver packageScanClassResolver = findPackageScanClassResolver(); if (packageScanClassResolver != null) { setPackageScanClassResolver(packageScanClassResolver); } _domain.setProperty(CAMEL_CONTEXT_PROPERTY, this); }
public PackageScanRouteBuilderFinder(BlueprintCamelContext camelContext, String[] packages, ClassLoader classLoader, PackageScanClassResolver resolver) { this.camelContext = camelContext; this.blueprintContainer = camelContext.getBlueprintContainer(); this.packages = packages; this.resolver = resolver; // add our provided loader as well resolver.addClassLoader(classLoader); }
public AnnotationModelLoader(PackageScanClassResolver resolver) { this.resolver = resolver; annotations = new LinkedHashSet<Class<? extends Annotation>>(); annotations.add(CsvRecord.class); annotations.add(Link.class); annotations.add(Message.class); annotations.add(Section.class); annotations.add(FixedLengthRecord.class); }
public PackageScanRouteBuilderFinder(SpringCamelContext camelContext, String[] packages, ClassLoader classLoader, BeanPostProcessor postProcessor, PackageScanClassResolver resolver) { this.camelContext = camelContext; this.applicationContext = camelContext.getApplicationContext(); this.packages = packages; this.beanPostProcessor = postProcessor; this.resolver = resolver; // add our provided loader as well resolver.addClassLoader(classLoader); }
/** * Get the first PackageScanClassResolver Service found on the classpath. * * @return The first PackageScanClassResolver Service found on the classpath. */ public PackageScanClassResolver findPackageScanClassResolver() { final ServiceLoader<PackageScanClassResolver> resolverLoaders = ServiceLoader.load(PackageScanClassResolver.class); for (PackageScanClassResolver packageScanClassResolver : resolverLoaders) { return packageScanClassResolver; } return null; }
public AnnotationTypeConverterLoader(PackageScanClassResolver resolver) { this.resolver = resolver; }
/** * Filters the given list of packages and returns an array of <b>only</b> package names. * <p/> * This implementation will check the given list of packages, and if it contains a class name, * that class will be loaded directly and added to the list of classes. This optimizes the * type converter to avoid excessive file scanning for .class files. * * @param resolver the class resolver * @param packageNames the package names * @param classes to add loaded @Converter classes * @return the filtered package names */ protected String[] filterPackageNamesOnly(PackageScanClassResolver resolver, String[] packageNames, Set<Class<?>> classes) { if (packageNames == null || packageNames.length == 0) { return packageNames; } // optimize for CorePackageScanClassResolver if (resolver.getClassLoaders().isEmpty()) { return packageNames; } // the filtered packages to return List<String> packages = new ArrayList<String>(); // try to load it as a class first for (String name : packageNames) { // must be a FQN class name by having an upper case letter if (StringHelper.isClassName(name)) { Class<?> clazz = null; for (ClassLoader loader : resolver.getClassLoaders()) { try { clazz = ObjectHelper.loadClass(name, loader); LOG.trace("Loaded {} as class {}", name, clazz); classes.add(clazz); // class founder, so no need to load it with another class loader break; } catch (Throwable e) { // do nothing here } } if (clazz == null) { // ignore as its not a class (will be package scan afterwards) packages.add(name); } } else { // ignore as its not a class (will be package scan afterwards) packages.add(name); } } // return the packages which is not FQN classes return packages.toArray(new String[packages.size()]); }
public LazyLoadingTypeConverter(PackageScanClassResolver resolver, Injector injector, FactoryFinder factoryFinder) { super(resolver, injector, factoryFinder); }
public DefaultTypeConverter(PackageScanClassResolver resolver, Injector injector, FactoryFinder factoryFinder) { super(resolver, injector, factoryFinder); }
public PackageScanClassResolver getPackageScanClassResolver() { return packageScanClassResolver; }
public void setPackageScanClassResolver(PackageScanClassResolver packageScanClassResolver) { this.packageScanClassResolver = packageScanClassResolver; }
private Set<Class<?>> discoverJaxbClasses() { PackageScanClassResolver resolver = new DefaultPackageScanClassResolver(); String[] packages = Constants.JAXB_CONTEXT_PACKAGES.split(":"); return resolver.findAnnotated(XmlAccessorType.class, packages); }
PackageScanRouteBuilderFinder(CamelContext camelContext, String[] packages, ClassLoader classLoader, PackageScanClassResolver resolver) { this.camelContext = camelContext; this.packages = packages; this.resolver = resolver; resolver.addClassLoader(classLoader); }
public AnnotationModelLoader(PackageScanClassResolver resolver, PackageScanFilter filter) { this(resolver); this.filter = filter; }
@Override public PackageScanClassResolver getPackageScanClassResolver() { return context.getPackageScanClassResolver(); }
@Override public void setPackageScanClassResolver(PackageScanClassResolver resolver) { context.setPackageScanClassResolver(resolver); }
@Test public void setCustomClassPathResolver() { final PackageScanClassResolver p = _camelContext.getPackageScanClassResolver(); assertThat(p, is(instanceOf(CustomPackageScanResolver.class))); }
@Override public void setup(CamelContext camelctx) { PackageScanClassResolver resolver = new PackageScanClassResolverImpl(moduleClassLoader); camelctx.setPackageScanClassResolver(resolver); }
/** * Returns the package scanning class resolver * * @return the resolver */ PackageScanClassResolver getPackageScanClassResolver();
/** * Sets the package scanning class resolver to use * * @param resolver the resolver */ void setPackageScanClassResolver(PackageScanClassResolver resolver);