public static ProcessAnnotatedTypeEventResolvable of(ProcessAnnotatedTypeImpl<?> event, RequiredAnnotationDiscovery discovery) { if (event instanceof ProcessSyntheticAnnotatedType) { return forProcessSyntheticAnnotatedType(event.getOriginalAnnotatedType(), discovery); } else { return forProcessAnnotatedType(event.getOriginalAnnotatedType(), discovery); } }
@Override public void setAnnotatedType(AnnotatedType<X> type) { if (configurator != null) { throw BootstrapLogger.LOG.configuratorAndSetMethodBothCalled(ProcessAnnotatedType.class.getSimpleName(), getReceiver()); } checkWithinObserverNotification(); if (type == null) { throw BootstrapLogger.LOG.annotationTypeNull(this); } replaceAnnotatedType(type); annotatedTypeSet = true; BootstrapLogger.LOG.setAnnotatedTypeCalled(getReceiver(), annotatedType, type); }
public void processAnnotatedTypes() { Set<SlimAnnotatedTypeContext<?>> classesToBeAdded = new HashSet<SlimAnnotatedTypeContext<?>>(); Set<SlimAnnotatedTypeContext<?>> classesToBeRemoved = new HashSet<SlimAnnotatedTypeContext<?>>(); for (SlimAnnotatedTypeContext<?> annotatedTypeContext : getEnvironment().getAnnotatedTypes()) { SlimAnnotatedType<?> annotatedType = annotatedTypeContext.getAnnotatedType(); final ProcessAnnotatedTypeImpl<?> event = containerLifecycleEvents.fireProcessAnnotatedType(getManager(), annotatedTypeContext); // process the result if (event != null) { if (event.isVeto()) { getEnvironment().vetoJavaClass(annotatedType.getJavaClass()); classesToBeRemoved.add(annotatedTypeContext); } else { boolean dirty = event.isDirty(); if (dirty) { classesToBeRemoved.add(annotatedTypeContext); // remove the original class classesToBeAdded.add(SlimAnnotatedTypeContext.of(event.getResultingAnnotatedType(), annotatedTypeContext.getExtension())); } processPriority(event.getResultingAnnotatedType()); } } else { processPriority(annotatedType); } } getEnvironment().removeAnnotatedTypes(classesToBeRemoved); getEnvironment().addAnnotatedTypes(classesToBeAdded); }
@Override public void veto() { checkWithinObserverNotification(); this.veto = true; BootstrapLogger.LOG.annotatedTypeVetoed(getReceiver(), annotatedType); }
@Override public AnnotatedTypeConfigurator<X> configureAnnotatedType() { if (annotatedTypeSet) { throw BootstrapLogger.LOG.configuratorAndSetMethodBothCalled(ProcessAnnotatedType.class.getSimpleName(), getReceiver()); } checkWithinObserverNotification(); if (configurator == null) { configurator = new AnnotatedTypeConfiguratorImpl<>(annotatedType); } BootstrapLogger.LOG.configureAnnotatedTypeCalled(getReceiver(), annotatedType); return configurator; }
public <T> ProcessAnnotatedTypeImpl<T> fireProcessAnnotatedType(BeanManagerImpl beanManager, SlimAnnotatedTypeContext<T> annotatedTypeContext) { if (!isProcessAnnotatedTypeObserved()) { return null; } final Set<ExtensionObserverMethodImpl<?, ?>> observers = annotatedTypeContext.getResolvedProcessAnnotatedTypeObservers(); final SlimAnnotatedType<T> annotatedType = annotatedTypeContext.getAnnotatedType(); // if the fast resolver resolved an empty set of observer methods, skip this event if (observers != null && observers.isEmpty()) { BootstrapLogger.LOG.patSkipped(annotatedType); return null; } ProcessAnnotatedTypeImpl<T> event = null; if (annotatedTypeContext.getExtension() == null) { event = new ProcessAnnotatedTypeImpl<T>(beanManager, annotatedType); } else { event = new ProcessSyntheticAnnotatedTypeImpl<T>(beanManager, annotatedTypeContext); } if (observers == null) { BootstrapLogger.LOG.patDefaultResolver(annotatedType); fireProcessAnnotatedType(event, beanManager); } else { BootstrapLogger.LOG.patFastResolver(annotatedType); fireProcessAnnotatedType(event, annotatedTypeContext.getResolvedProcessAnnotatedTypeObservers()); } return event; }
@Override protected void storeSyntheticAnnotatedType(BeanDeployment deployment, AnnotatedType<?> type, String id) { SlimAnnotatedType<?> annotatedType = transformer.getUnbackedAnnotatedType(type, getBeanManager().getId(), id); Extension extension = getReceiver(); SlimAnnotatedTypeContext<?> annotatedTypeContext = SlimAnnotatedTypeContext.of(annotatedType, extension); ProcessAnnotatedTypeImpl<?> event = events.fireProcessAnnotatedType(getBeanManager(), annotatedTypeContext); if (event == null) { deployment.getBeanDeployer().getEnvironment().addAnnotatedType(annotatedTypeContext); store.put(annotatedType); } else if (event.isVeto()) { return; } else { annotatedType = event.getResultingAnnotatedType(); deployment.getBeanDeployer().getEnvironment().addSyntheticAnnotatedType(annotatedType, extension); store.put(annotatedType); } } }
@Override public void setAnnotatedType(AnnotatedType<X> type) { checkWithinObserverNotification(); if (type == null) { throw BootstrapLogger.LOG.annotationTypeNull(this); } if (!this.originalAnnotatedType.getJavaClass().equals(type.getJavaClass())) { throw BootstrapLogger.LOG.annotatedTypeJavaClassMismatch(this.annotatedType.getJavaClass(), type.getJavaClass()); } AnnotatedTypeValidator.validateAnnotatedType(type); BootstrapLogger.LOG.setAnnotatedTypeCalled(getReceiver(), annotatedType, type); this.annotatedType = type; }
private <T> void addContainerLifecycleEvent(T event, Object info, BeanManagerImpl beanManagerImpl) { ResolvedObservers<?> resolvedObservers = null; Type eventType = null; if (event instanceof AbstractContainerEvent) { AbstractContainerEvent containerEvent = (AbstractContainerEvent) event; eventType = containerEvent.getEventType(); resolvedObservers = beanManagerImpl.getGlobalLenientObserverNotifier().resolveObserverMethods(eventType); } else if (event instanceof ProcessAnnotatedTypeImpl) { ProcessAnnotatedTypeImpl<?> processAnnotatedTypeEvent = (ProcessAnnotatedTypeImpl<?>) event; eventType = ProcessAnnotatedType.class; info = Formats.formatType(processAnnotatedTypeEvent.getOriginalAnnotatedType().getBaseType(), false); resolvedObservers = beanManagerImpl.getGlobalLenientObserverNotifier().resolveObserverMethods( ProcessAnnotatedTypeEventResolvable.of(processAnnotatedTypeEvent, beanManagerImpl.getServices().get(RequiredAnnotationDiscovery.class))); } if (resolvedObservers != null && eventType != null) { probe.addEvent(new EventInfo(eventType, Collections.emptySet(), info, null, Reflections.cast(resolvedObservers.getAllObservers()), true, System.currentTimeMillis(), false)); } }
/** * Fires a {@link ProcessAnnotatedType}. Instead of using the default event dispatching mechanism, this method directly notifies * extension observers resolved by FastProcessAnnotatedTypeResolver. */ @SuppressWarnings({ "rawtypes", "unchecked" }) private void fireProcessAnnotatedType(ProcessAnnotatedTypeImpl<?> event, Set<ContainerLifecycleEventObserverMethod<?>> observers, BeanManagerImpl beanManager) { List<Throwable> errors = new LinkedList<Throwable>(); for (ContainerLifecycleEventObserverMethod observer : observers) { // FastProcessAnnotatedTypeResolver does not consider special scope inheritance rules (see CDI - section 4.1) if (checkScopeInheritanceRules(event.getOriginalAnnotatedType(), observer, beanManager)) { try { observer.notify(event); } catch (Throwable e) { errors.add(e); } } } if (!errors.isEmpty()) { throw new DefinitionException(errors); } }
/** * Call this method after all observer methods of this event have been invoked to get the final value of this {@link AnnotatedType}. * * @return the resulting annotated type */ public SlimAnnotatedType<X> getResultingAnnotatedType() { if (isDirty()) { return ClassTransformer.instance(manager).getUnbackedAnnotatedType(originalAnnotatedType, annotatedType); } else { return originalAnnotatedType; } }
@Override public AnnotatedType<X> getAnnotatedType() { checkWithinObserverNotification(); return annotatedType; }
@Override public void postNotify(Extension extension) { super.postNotify(extension); if (configurator != null) { replaceAnnotatedType(configurator.complete()); configurator = null; } annotatedTypeSet = false; }
public <T> ProcessAnnotatedTypeImpl<T> fireProcessAnnotatedType(BeanManagerImpl beanManager, SlimAnnotatedTypeContext<T> annotatedTypeContext) { if (!isProcessAnnotatedTypeObserved()) { return null; } final Set<ContainerLifecycleEventObserverMethod<?>> observers = annotatedTypeContext.getResolvedProcessAnnotatedTypeObservers(); final SlimAnnotatedType<T> annotatedType = annotatedTypeContext.getAnnotatedType(); // if the fast resolver resolved an empty set of observer methods, skip this event if (observers != null && observers.isEmpty()) { BootstrapLogger.LOG.patSkipped(annotatedType); return null; } ProcessAnnotatedTypeImpl<T> event = null; if (annotatedTypeContext.getExtension() == null) { event = new ProcessAnnotatedTypeImpl<T>(beanManager, annotatedType); } else { event = new ProcessSyntheticAnnotatedTypeImpl<T>(beanManager, annotatedTypeContext); } if (observers == null) { BootstrapLogger.LOG.patDefaultResolver(annotatedType); fireProcessAnnotatedType(event, beanManager); } else { BootstrapLogger.LOG.patFastResolver(annotatedType); fireProcessAnnotatedType(event, annotatedTypeContext.getResolvedProcessAnnotatedTypeObservers(), beanManager); } return event; }
@Override protected void storeSyntheticAnnotatedType(BeanDeployment deployment, AnnotatedType<?> type, String id) { SlimAnnotatedType<?> annotatedType = transformer.getUnbackedAnnotatedType(type, getBeanManager().getId(), id); Extension extension = getReceiver(); SlimAnnotatedTypeContext<?> annotatedTypeContext = SlimAnnotatedTypeContext.of(annotatedType, extension); ProcessAnnotatedTypeImpl<?> event = events.fireProcessAnnotatedType(getBeanManager(), annotatedTypeContext); if (event == null) { deployment.getBeanDeployer().getEnvironment().addAnnotatedType(annotatedTypeContext); store.put(annotatedType); } else if (event.isVeto()) { return; } else { annotatedType = event.getResultingAnnotatedType(); deployment.getBeanDeployer().getEnvironment().addSyntheticAnnotatedType(annotatedType, extension); store.put(annotatedType); } } }
@Override public AnnotatedTypeConfigurator<X> configureAnnotatedType() { if (annotatedTypeSet) { throw BootstrapLogger.LOG.configuratorAndSetMethodBothCalled(ProcessAnnotatedType.class.getSimpleName(), getReceiver()); } checkWithinObserverNotification(); if (configurator == null) { configurator = new AnnotatedTypeConfiguratorImpl<>(annotatedType); } BootstrapLogger.LOG.configureAnnotatedTypeCalled(getReceiver(), annotatedType); return configurator; }
@Override public void veto() { checkWithinObserverNotification(); this.veto = true; BootstrapLogger.LOG.annotatedTypeVetoed(getReceiver(), annotatedType); }
private <T> void addContainerLifecycleEvent(T event, Object info, BeanManagerImpl beanManagerImpl) { ResolvedObservers<?> resolvedObservers = null; Type eventType = null; if (event instanceof AbstractContainerEvent) { AbstractContainerEvent containerEvent = (AbstractContainerEvent) event; eventType = containerEvent.getEventType(); resolvedObservers = beanManagerImpl.getGlobalLenientObserverNotifier().resolveObserverMethods(eventType); } else if (event instanceof ProcessAnnotatedTypeImpl) { ProcessAnnotatedTypeImpl<?> processAnnotatedTypeEvent = (ProcessAnnotatedTypeImpl<?>) event; eventType = ProcessAnnotatedType.class; info = Formats.formatType(processAnnotatedTypeEvent.getOriginalAnnotatedType().getBaseType(), false); resolvedObservers = beanManagerImpl.getGlobalLenientObserverNotifier().resolveObserverMethods( ProcessAnnotatedTypeEventResolvable.of(processAnnotatedTypeEvent, beanManagerImpl.getServices().get(RequiredAnnotationDiscovery.class))); } if (resolvedObservers != null && eventType != null) { probe.addEvent(new EventInfo(eventType, Collections.emptySet(), info, null, Reflections.cast(resolvedObservers.getAllObservers()), true, System.currentTimeMillis(), false)); } }
/** * Fires a {@link ProcessAnnotatedType}. Instead of using the default event dispatching mechanism, this method directly notifies * extension observers resolved by FastProcessAnnotatedTypeResolver. */ @SuppressWarnings({ "rawtypes", "unchecked" }) private void fireProcessAnnotatedType(ProcessAnnotatedTypeImpl<?> event, Set<ContainerLifecycleEventObserverMethod<?>> observers, BeanManagerImpl beanManager) { List<Throwable> errors = new LinkedList<Throwable>(); for (ContainerLifecycleEventObserverMethod observer : observers) { // FastProcessAnnotatedTypeResolver does not consider special scope inheritance rules (see CDI - section 4.1) if (checkScopeInheritanceRules(event.getOriginalAnnotatedType(), observer, beanManager)) { try { observer.notify(event); } catch (Throwable e) { errors.add(e); } } } if (!errors.isEmpty()) { throw new DefinitionException(errors); } }
/** * Call this method after all observer methods of this event have been invoked to get the final value of this {@link AnnotatedType}. * * @return the resulting annotated type */ public SlimAnnotatedType<X> getResultingAnnotatedType() { if (isDirty()) { return ClassTransformer.instance(manager).getUnbackedAnnotatedType(originalAnnotatedType, annotatedType); } else { return originalAnnotatedType; } }