private static void checkContainerState(Container container) { ContainerState state = container.getState(); if (state.equals(ContainerState.STOPPED) || state.equals(ContainerState.SHUTDOWN)) { throw BeanManagerLogger.LOG.beanManagerNotAvailable(); } }
public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable<?, ?> environment) throws Exception { if (Container.available(contextId)) { for (Entry<BeanDeploymentArchive, BeanManagerImpl> entry : Container.instance(contextId).beanDeploymentArchives().entrySet()) { BeanDeploymentArchive bda = entry.getKey(); if (bda.getId().equals(FLAT_BEAN_DEPLOYMENT_ID) || bda.getId().contains(WEB_INF_CLASSES_FILE_PATH) || bda.getId().contains(WEB_INF_CLASSES)) { return entry.getValue(); } } throw BeanManagerLogger.LOG.cannotLocateBeanManager(); } else { throw BeanManagerLogger.LOG.cannotLocateBeanManager(); } }
public <X> BeanAttributes<?> internalCreateBeanAttributes(AnnotatedMember<X> member) { EnhancedAnnotatedMember<?, X, Member> weldMember = null; if (member instanceof AnnotatedField<?> || member instanceof AnnotatedMethod<?>) { weldMember = services.get(MemberTransformer.class).loadEnhancedMember(member, getId()); } else { throw BeanManagerLogger.LOG.cannotCreateBeanAttributesForIncorrectAnnotatedMember(member); } return BeanAttributesFactory.forBean(weldMember, this); }
@Override public BeanManagerProxy getBeanManager() { ContainerState state = container.getState(); if (state.equals(ContainerState.STOPPED) || state.equals(ContainerState.SHUTDOWN)) { throw BeanManagerLogger.LOG.beanManagerNotAvailable(); } return beanManagers.getValue(getCallingClassName()); }
@Override protected void checkQualifier(Annotation qualifier, QualifierInstance qualifierInstance, Class<? extends Annotation> annotationType) { if (!getMetaAnnotationStore().getInterceptorBindingModel(annotationType).isValid()) { throw BeanManagerLogger.LOG.interceptorResolutionWithNonbindingType(qualifier); } if (annotationTypes.contains(annotationType)) { throw BeanManagerLogger.LOG.duplicateInterceptorBinding(qualifier); } }
/** * Extracts a flat set of interception bindings from a given set of interceptor bindings. * * @param addTopLevelInterceptorBindings add top level interceptor bindings to the result set. * @param addInheritedInterceptorBindings add inherited level interceptor bindings to the result set. * @return */ public static Set<Annotation> flattenInterceptorBindings(BeanManagerImpl beanManager, Collection<Annotation> annotations, boolean addTopLevelInterceptorBindings, boolean addInheritedInterceptorBindings) { Set<Annotation> flattenInterceptorBindings = new InterceptorBindingSet(beanManager); if (addTopLevelInterceptorBindings) { for (Annotation annotation : annotations) { boolean added = flattenInterceptorBindings.add(annotation); if (!added) { throw BeanManagerLogger.LOG.duplicateInterceptorBinding(annotations); } } } if (addInheritedInterceptorBindings) { for (Annotation annotation : annotations) { addInheritedInterceptorBindings(annotation.annotationType(), beanManager.getServices().get(MetaAnnotationStore.class), flattenInterceptorBindings); } } return flattenInterceptorBindings; }
private static void addInterceptorBindings(EnhancedAnnotatedType<?> clazz, Collection<Annotation> interceptorBindings, Set<Annotation> flattenInterceptorBindings, MetaAnnotationStore metaAnnotationStore) { for (Annotation annotation : interceptorBindings) { Class<? extends Annotation> annotationType = annotation.annotationType(); if (!annotation.annotationType().isAnnotationPresent(Repeatable.class)) { for (Annotation binding : flattenInterceptorBindings) { if (binding.annotationType().equals(annotationType) && !metaAnnotationStore.getInterceptorBindingModel(annotationType).isEqual(annotation, binding, false)) { if (clazz != null) { throw new DefinitionException(BeanLogger.LOG.conflictingInterceptorBindings(clazz)); } else { throw BeanManagerLogger.LOG.duplicateInterceptorBinding(annotation); } } } } flattenInterceptorBindings.add(annotation); } }
@SuppressWarnings("unchecked") private void initWithWorker(Type requiredType, Annotation[] qualifiers, Vertx vertx, BeanManager beanManager) { vertx.<Object> executeBlocking((f -> { WeldInstance<Object> asyncInstance = instance.select(requiredType, qualifiers); if (asyncInstance.isUnsatisfied()) { f.fail(BeanManagerLogger.LOG.injectionPointHasUnsatisfiedDependencies(Arrays.toString(qualifiers), requiredType, "")); return; } else if (asyncInstance.isAmbiguous()) { f.fail(BeanManagerLogger.LOG.injectionPointHasAmbiguousDependencies(Arrays.toString(qualifiers), requiredType, "")); return; } Handler<Object> handler = asyncInstance.getHandler(); Object beanInstance = handler.get(); if (beanManager.isNormalScope(handler.getBean().getScope()) && beanInstance instanceof TargetInstanceProxy) { // Initialize normal scoped bean instance eagerly ((TargetInstanceProxy<?>) beanInstance).getTargetInstance(); } f.complete(beanInstance); }), (r) -> { if (r.succeeded()) { sucess((T) r.result()); } else { failure(r.cause()); } }); }
/** * Gets an active context of the given scope. Throws an exception if there are no active contexts found or if there are too many matches * * @throws IllegalStateException if there are multiple active scopes for a given context * @param scopeType The scope to match * @return A single active context of the given scope * @see javax.enterprise.inject.spi.BeanManager#getContext(java.lang.Class) */ @Override public Context getContext(Class<? extends Annotation> scopeType) { Context activeContext = internalGetContext(scopeType); if (activeContext == null) { throw BeanManagerLogger.LOG.contextNotActive(scopeType.getName()); } return activeContext; }
/** * Callback that allows to override the behavior when class that invoked CDI.current() is placed in multiple bean archives. */ protected BeanManagerImpl ambiguousBeanManager(String callerClassName, Set<BeanManagerImpl> managers) { throw BeanManagerLogger.LOG.ambiguousBeanManager(callerClassName); }
@Override public <X> Bean<? extends X> resolve(Set<Bean<? extends X>> beans) { if (beans == null || beans.isEmpty()) { return null; } Set<Bean<? extends X>> resolvedBeans = beanResolver.resolve(beans); if (resolvedBeans.size() == 1) { return resolvedBeans.iterator().next(); } else if (resolvedBeans.size() == 0) { return null; } else { throw BeanManagerLogger.LOG.ambiguousBeansForDependency(WeldCollections.toMultiRowString(beans)); } }
private Context internalGetContext(Class<? extends Annotation> scopeType) { Context activeContext = null; final List<Context> ctx = contexts.get(scopeType); if (ctx == null) { return null; } for (Context context : ctx) { if (context.isActive()) { if (activeContext == null) { activeContext = context; } else { throw BeanManagerLogger.LOG.duplicateActiveContexts(scopeType.getName()); } } } return activeContext; }
@Override public void deactivate() throws ContextNotActiveException { if (!isRequestContextActive()) { throw BeanManagerLogger.LOG.contextNotActive(RequestScoped.class); } if (isActivator.compareAndSet(true, false)) { try { requestBeforeDestroyedEvent.fire(toString()); requestContext.invalidate(); requestContext.deactivate(); } finally { requestDestroyedEvent.fire(toString()); } } }
@SuppressWarnings("unchecked") private void initWithWorker(InjectionPoint injectionPoint, Vertx vertx, BeanManager beanManager, Type requiredType) { vertx.<T> executeBlocking((f -> { Set<Bean<?>> beans = beanManager.getBeans(requiredType, injectionPoint.getQualifiers().toArray(new Annotation[] {})); if (beans.isEmpty()) { f.fail(BeanManagerLogger.LOG.injectionPointHasUnsatisfiedDependencies(injectionPoint.getQualifiers(), requiredType, "")); return; } Bean<T> bean = (Bean<T>) beanManager.resolve(beans); T beanInstance = (T) beanManager.getReference(bean, requiredType, creationalContext); if (beanManager.isNormalScope(bean.getScope()) && beanInstance instanceof TargetInstanceProxy) { // Initialize normal scoped bean instance eagerly ((TargetInstanceProxy<?>) beanInstance).getTargetInstance(); } f.complete(beanInstance); }), (r) -> { if (r.succeeded()) { sucess(r.result()); } else { failure(r.cause()); } }); }
public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable<?, ?> environment) throws Exception { if (Container.available(contextId)) { for (Entry<BeanDeploymentArchive, BeanManagerImpl> entry : Container.instance(contextId).beanDeploymentArchives().entrySet()) { BeanDeploymentArchive bda = entry.getKey(); if (bda.getId().equals(FLAT_BEAN_DEPLOYMENT_ID) || bda.getId().contains(WEB_INF_CLASSES_FILE_PATH) || bda.getId().contains(WEB_INF_CLASSES)) { return entry.getValue(); } } throw BeanManagerLogger.LOG.cannotLocateBeanManager(); } else { throw BeanManagerLogger.LOG.cannotLocateBeanManager(); } }
public <X> BeanAttributes<?> internalCreateBeanAttributes(AnnotatedMember<X> member) { EnhancedAnnotatedMember<?, X, Member> weldMember = null; if (member instanceof AnnotatedField<?> || member instanceof AnnotatedMethod<?>) { weldMember = services.get(MemberTransformer.class).loadEnhancedMember(member, getId()); } else { throw BeanManagerLogger.LOG.cannotCreateBeanAttributesForIncorrectAnnotatedMember(member); } return BeanAttributesFactory.forBean(weldMember, this); }
@Override public BeanManagerProxy getBeanManager() { ContainerState state = container.getState(); if (state.equals(ContainerState.STOPPED) || state.equals(ContainerState.SHUTDOWN)) { throw BeanManagerLogger.LOG.beanManagerNotAvailable(); } return beanManagers.getValue(getCallingClassName()); }
@Override protected void checkQualifier(Annotation qualifier,final QualifierInstance qualifierInstance, Class<? extends Annotation> annotationType) { if (!getMetaAnnotationStore().getInterceptorBindingModel(annotationType).isValid()) { throw BeanManagerLogger.LOG.interceptorResolutionWithNonbindingType(qualifier); } if (qualifierInstances.contains(qualifierInstance)) { throw BeanManagerLogger.LOG.duplicateInterceptorBinding(qualifierInstance); } }
private static void addInterceptorBindings(EnhancedAnnotatedType<?> clazz, Collection<Annotation> interceptorBindings, Set<Annotation> flattenInterceptorBindings, MetaAnnotationStore metaAnnotationStore) { for (Annotation annotation : interceptorBindings) { Class<? extends Annotation> annotationType = annotation.annotationType(); if (!annotation.annotationType().isAnnotationPresent(Repeatable.class)) { for (Annotation binding : flattenInterceptorBindings) { if (binding.annotationType().equals(annotationType) && !metaAnnotationStore.getInterceptorBindingModel(annotationType).isEqual(annotation, binding, false)) { if (clazz != null) { throw new DefinitionException(BeanLogger.LOG.conflictingInterceptorBindings(clazz)); } else { throw BeanManagerLogger.LOG.duplicateInterceptorBinding(annotation); } } } } flattenInterceptorBindings.add(annotation); } }
private void checkBeanResolved() { if (bean != null) { return; } else if (isUnsatisfied()) { throw BeanManagerLogger.LOG.injectionPointHasUnsatisfiedDependencies(Formats.formatAnnotations(ip.getQualifiers()), Formats.formatInjectionPointType(ip.getType()), InjectionPoints.getUnsatisfiedDependenciesAdditionalInfo(ip, getBeanManager())); } else { throw BeanManagerLogger.LOG.injectionPointHasAmbiguousDependencies(Formats.formatAnnotations(ip.getQualifiers()), Formats.formatInjectionPointType(ip.getType()), WeldCollections.toMultiRowString(allBeans())); } }