/** * Creates a {@link RedisKeyValueAdapterBean}, requires a {@link RedisOperations} bean with the same qualifiers. * * @param qualifiers the qualifiers to be applied to the bean. * @param beanManager the BeanManager instance. * @return */ private RedisKeyValueAdapterBean createRedisKeyValueAdapterBean(Set<Annotation> qualifiers, BeanManager beanManager) { // Determine the RedisOperations bean which matches the qualifiers of the repository. Bean<RedisOperations<?, ?>> redisOperationsBean = this.redisOperations.get(qualifiers); if (redisOperationsBean == null) { throw new UnsatisfiedResolutionException(String.format("Unable to resolve a bean for '%s' with qualifiers %s.", RedisOperations.class.getName(), qualifiers)); } // Construct and return the repository bean. return new RedisKeyValueAdapterBean(redisOperationsBean, qualifiers, beanManager); }
@Override public final UnsatisfiedResolutionException unableToResolveBean(final Object param1, final Object param2) { final UnsatisfiedResolutionException result = new UnsatisfiedResolutionException(java.text.MessageFormat.format(unableToResolveBean$str(), param1, param2)); final StackTraceElement[] st = result.getStackTrace(); result.setStackTrace(Arrays.copyOfRange(st, 1, st.length)); return result; } private static final String jandexIndexNotCreated = "WELD-ENV-000019: Jandex index is null in the constructor of class: {0}";
protected Bean<?> bind(String location, Class<?> type, Annotation ...qualifiers) { try { InjectManager injectManager = getManager(); Set<Bean<?>> beans = null; beans = injectManager.getBeans(type, qualifiers); if (beans != null) { Bean<?> bean = injectManager.resolve(beans); if (bean != null) return bean; } throw injectManager.unsatisfiedException(type, qualifiers); } catch (UnsatisfiedResolutionException e) { throw new UnsatisfiedResolutionException(location + e.getMessage(), e); } catch (AmbiguousResolutionException e) { throw new AmbiguousResolutionException(location + e.getMessage(), e); } catch (InjectionException e) { throw new InjectionException(location + e.getMessage(), e); } }
@PostConstruct public void init() { try { this.metricRegistry = CDI.current().select( MetricRegistry.class).get(); } catch ( UnsatisfiedResolutionException e ) { logger.info( e.getMessage() ); } }
@Override public final UnsatisfiedResolutionException unableToResolveBean(final Object param1, final Object param2) { final UnsatisfiedResolutionException result = new UnsatisfiedResolutionException(java.text.MessageFormat.format(unableToResolveBean$str(), param1, param2)); final StackTraceElement[] st = result.getStackTrace(); result.setStackTrace(Arrays.copyOfRange(st, 1, st.length)); return result; } private static final String jandexIndexNotCreated = "WELD-ENV-000019: Jandex index is null in the constructor of class: {0}";
e); } catch (UnsatisfiedResolutionException e) { throw new UnsatisfiedResolutionException(L.l("{0}.{1}: {2}", ij.getMember().getDeclaringClass().getName(), ij.getMember().getName(), e.getMessage()), e); } catch (IllegalProductException e) {
/** * Creates a {@link RedisKeyValueTemplateBean}, requires a {@link RedisKeyValueAdapter} bean with the same qualifiers. * * @param qualifiers the qualifiers to be applied to the bean. * @param beanManager the BeanManager instance. * @return */ private RedisKeyValueTemplateBean createRedisKeyValueTemplateBean(Set<Annotation> qualifiers, BeanManager beanManager) { // Determine the RedisKeyValueAdapter bean which matches the qualifiers of the repository. Bean<RedisKeyValueAdapter> redisKeyValueAdapterBean = this.redisKeyValueAdapters.get(qualifiers); if (redisKeyValueAdapterBean == null) { throw new UnsatisfiedResolutionException(String.format("Unable to resolve a bean for '%s' with qualifiers %s.", RedisKeyValueAdapter.class.getName(), qualifiers)); } // Construct and return the repository bean. return new RedisKeyValueTemplateBean(redisKeyValueAdapterBean, qualifiers, beanManager); }
@Override public final UnsatisfiedResolutionException unableToResolveBean(final Object param1, final Object param2) { final UnsatisfiedResolutionException result = new UnsatisfiedResolutionException(java.text.MessageFormat.format(unableToResolveBean$str(), param1, param2)); final StackTraceElement[] st = result.getStackTrace(); result.setStackTrace(Arrays.copyOfRange(st, 1, st.length)); return result; } private static final String jandexIndexNotCreated = "WELD-ENV-000019: Jandex index is null in the constructor of class: {0}";
/** * Creates a {@link Bean}. * * @param <T> The type of the repository. * @param repositoryType The class representing the repository. * @param beanManager The BeanManager instance. * @return The bean. */ private <T> CdiRepositoryBean<T> createRepositoryBean(Class<T> repositoryType, Set<Annotation> qualifiers, BeanManager beanManager) { // Determine the entity manager bean which matches the qualifiers of the repository. Bean<EntityManager> entityManagerBean = entityManagers.get(qualifiers); if (entityManagerBean == null) { throw new UnsatisfiedResolutionException(String.format("Unable to resolve a bean for '%s' with qualifiers %s.", EntityManager.class.getName(), qualifiers)); } // Construct and return the repository bean. return new JpaRepositoryBean<T>(beanManager, entityManagerBean, qualifiers, repositoryType, Optional.of(getCustomImplementationDetector())); } }
@Override public final UnsatisfiedResolutionException unableToResolveBean(final Object param1, final Object param2) { final UnsatisfiedResolutionException result = new UnsatisfiedResolutionException(java.text.MessageFormat.format(unableToResolveBean$str(), param1, param2)); final StackTraceElement[] st = result.getStackTrace(); result.setStackTrace(Arrays.copyOfRange(st, 1, st.length)); return result; } private static final String jandexIndexNotCreated = "WELD-ENV-000019: Jandex index is null in the constructor of class: {0}";
/** * Creates a {@link CdiRepositoryBean} for the repository of the given type, requires a {@link KeyValueOperations} * bean with the same qualifiers. * * @param <T> the type of the repository. * @param repositoryType the class representing the repository. * @param qualifiers the qualifiers to be applied to the bean. * @param beanManager the BeanManager instance. * @return */ private <T> CdiRepositoryBean<T> createRepositoryBean(Class<T> repositoryType, Set<Annotation> qualifiers, BeanManager beanManager) { // Determine the KeyValueOperations bean which matches the qualifiers of the repository. Bean<KeyValueOperations> redisKeyValueTemplate = this.redisKeyValueTemplates.get(qualifiers); if (redisKeyValueTemplate == null) { throw new UnsatisfiedResolutionException(String.format("Unable to resolve a bean for '%s' with qualifiers %s.", RedisKeyValueTemplate.class.getName(), qualifiers)); } // Construct and return the repository bean. return new RedisRepositoryBean<>(redisKeyValueTemplate, qualifiers, repositoryType, beanManager, getCustomImplementationDetector()); }
@Override public final UnsatisfiedResolutionException unableToResolveBean(final Object param1, final Object param2) { final UnsatisfiedResolutionException result = new UnsatisfiedResolutionException(java.text.MessageFormat.format(unableToResolveBean$str(), param1, param2)); final StackTraceElement[] st = result.getStackTrace(); result.setStackTrace(Arrays.copyOfRange(st, 1, st.length)); return result; } private static final String jandexIndexNotCreated = "WELD-ENV-000019: Jandex index is null in the constructor of class: {0}";
/** * Creates a {@link CdiRepositoryBean} for the repository of the given type. * * @param <T> the type of the repository. * @param repositoryType the class representing the repository. * @param qualifiers the qualifiers to be applied to the bean. * @param beanManager the BeanManager instance. * @return */ private <T> CdiRepositoryBean<T> createRepositoryBean(Class<T> repositoryType, Set<Annotation> qualifiers, BeanManager beanManager) { // Determine the MongoOperations bean which matches the qualifiers of the repository. Bean<MongoOperations> mongoOperations = this.mongoOperations.get(qualifiers); if (mongoOperations == null) { throw new UnsatisfiedResolutionException(String.format("Unable to resolve a bean for '%s' with qualifiers %s.", MongoOperations.class.getName(), qualifiers)); } // Construct and return the repository bean. return new MongoRepositoryBean<T>(mongoOperations, qualifiers, repositoryType, beanManager, Optional.of(getCustomImplementationDetector())); } }
@Override public final UnsatisfiedResolutionException unableToResolveBean(final Object param1, final Object param2) { final UnsatisfiedResolutionException result = new UnsatisfiedResolutionException(java.text.MessageFormat.format(unableToResolveBean$str(), param1, param2)); final StackTraceElement[] st = result.getStackTrace(); result.setStackTrace(Arrays.copyOfRange(st, 1, st.length)); return result; } private static final String jandexIndexNotCreated = "WELD-ENV-000019: Jandex index is null in the constructor of class: {0}";
/** * Creates a {@link Bean}. * * @param <T> The type of the repository. * @param repositoryType The class representing the repository. * @param beanManager The BeanManager instance. * @return The bean. */ private <T> CdiRepositoryBean<T> createRepositoryBean(Class<T> repositoryType, Set<Annotation> qualifiers, BeanManager beanManager) { Bean<Session> sessionBean = this.sessions.get(qualifiers); if (sessionBean == null) { throw new UnsatisfiedResolutionException( String.format("Unable to resolve a bean for '%s' with qualifiers %s.", Session.class.getName(), qualifiers)); } return new Neo4jCdiRepositoryBean<T>(sessionBean, qualifiers, repositoryType, beanManager, Optional.of(getCustomImplementationDetector())); } }
@Override public final UnsatisfiedResolutionException unableToResolveBean(final Object param1, final Object param2) { final UnsatisfiedResolutionException result = new UnsatisfiedResolutionException(java.text.MessageFormat.format(unableToResolveBean$str(), param1, param2)); final StackTraceElement[] st = result.getStackTrace(); result.setStackTrace(Arrays.copyOfRange(st, 1, st.length)); return result; } private static final String jandexIndexNotCreated = "WELD-ENV-000019: Jandex index is null in the constructor of class: {0}";
/** * Creates a {@link CdiRepositoryBean} for the repository of the given type. * * @param <T> the type of the repository. * @param repositoryType the class representing the repository. * @param qualifiers the qualifiers to be applied to the bean. * @param beanManager the BeanManager instance. * @return */ private <T> CdiRepositoryBean<T> createRepositoryBean(Class<T> repositoryType, Set<Annotation> qualifiers, BeanManager beanManager) { // Determine the MongoOperations bean which matches the qualifiers of the repository. Bean<MongoOperations> mongoOperations = this.mongoOperations.get(qualifiers); if (mongoOperations == null) { throw new UnsatisfiedResolutionException(String.format("Unable to resolve a bean for '%s' with qualifiers %s.", MongoOperations.class.getName(), qualifiers)); } // Construct and return the repository bean. return new MongoRepositoryBean<T>(mongoOperations, qualifiers, repositoryType, beanManager, Optional.of(getCustomImplementationDetector())); } }
/** * Load a {@link Class} using the CDI {@link ClassLoader}. * * @param className * @return * @throws UnsatisfiedResolutionException if the class cannot be found. */ Class<?> loadClass(String className) { try { return ClassUtils.forName(className, classLoader); } catch (ClassNotFoundException e) { throw new UnsatisfiedResolutionException(String.format("Unable to resolve class for '%s'", className), e); } }
private static Set<Bean<?>> getBeans(BeanManager beanManager, Type beanType, Annotation... qualifiers) { Set<Bean<?>> beans = beanManager.getBeans(beanType, qualifiers); if (beans == null || beans.isEmpty()) { throw new UnsatisfiedResolutionException(String.format( "No bean matches required type %s and required qualifiers %s", beanType, Arrays.toString(qualifiers))); } return beans; }
protected static <T> T getInstanceByType(BeanManager manager, Class<T> type, Annotation... bindings) { final Bean<?> bean = manager.resolve(manager.getBeans(type, bindings)); if (bean == null) { throw new UnsatisfiedResolutionException("Unable to resolve a bean for " + type + " with bindings " + Arrays.asList(bindings)); } CreationalContext<?> cc = manager.createCreationalContext(null); return type.cast(manager.getReference(bean, type, cc)); }