@@ -117,12 +117,20 @@ public class StandardBeanManager implements BeanManager, Instance<Object> {
117
117
118
118
private final Map <String , AnnotatedType <?>> syntheticTypes ;
119
119
120
+
120
121
private final List <ManagedBean <?>> managedBeans ;
121
122
122
123
private final List <Interceptor <?>> interceptorBeans ;
123
124
124
125
private final List <Decorator <?>> decoratorBeans ;
125
126
127
+ private final List <Bean <?>> genericBeans ;
128
+
129
+
130
+ private Set <Throwable > definitionErrors ;
131
+
132
+ private Set <Throwable > deploymentProblems ;
133
+
126
134
public StandardBeanManager () {
127
135
this .classLoader = ClassLoaderUtils .getClassLoader (getClass ());
128
136
@@ -142,6 +150,10 @@ public StandardBeanManager() {
142
150
this .managedBeans = new LinkedList <>();
143
151
this .interceptorBeans = new LinkedList <>();
144
152
this .decoratorBeans = new LinkedList <>();
153
+ this .genericBeans = new LinkedList <>();
154
+
155
+ this .definitionErrors = new LinkedHashSet <>();
156
+ this .deploymentProblems = new LinkedHashSet <>();
145
157
}
146
158
147
159
@ Override
@@ -474,6 +486,19 @@ public void initialize() {
474
486
// TODO
475
487
}
476
488
489
+ public void addDefinitionError (Throwable t ) {
490
+ this .definitionErrors .add (t );
491
+ }
492
+
493
+ /**
494
+ * Registers a deployment problem with the container, causing the container to abort deployment
495
+ * after all observers have been notified.
496
+ * @param t {@link Throwable}
497
+ */
498
+ public void addDeploymentProblem (Throwable t ) {
499
+ this .deploymentProblems .add (t );
500
+ }
501
+
477
502
private void initializeBeanArchiveManager () {
478
503
beanArchiveManager .setClassLoader (classLoader );
479
504
beanArchiveManager .enableScanImplicit (isScanImplicitEnabled ());
@@ -548,11 +573,6 @@ private void performBeanDiscovery() {
548
573
determineAlternativeBeans ();
549
574
determineInterceptorBeans ();
550
575
determineDecoratorBeans ();
551
-
552
- // register the instances of enabled Beans, Interceptors and Decorator
553
- registerBeans ();
554
- registerInterceptorBeans ();
555
- registerDecoratorBeans ();
556
576
}
557
577
558
578
private void determineManagedBeans () {
@@ -687,12 +707,24 @@ private void determineInterceptorBean(AnnotatedType<?> interceptorType) {
687
707
fireProcessBeanAttributesEvent (interceptorType , interceptorBean );
688
708
if (!interceptorBean .isVetoed ()) {
689
709
fireProcessBeanEvent (interceptorType , interceptorBean );
690
- registerInterceptorBean (interceptorType , interceptorBean );
710
+ registerInterceptorClass (interceptorType );
711
+ registerInterceptorBean (interceptorBean );
691
712
}
692
713
}
693
714
694
- private void registerInterceptorBean (AnnotatedType <?> interceptorType , Interceptor <?> interceptorBean ) {
695
- registerInterceptorClass (interceptorType );
715
+ public void registerBean (Bean <?> bean ) {
716
+ if (bean instanceof Interceptor ) {
717
+ registerInterceptorBean ((Interceptor ) bean );
718
+ } else if (bean instanceof Decorator ) {
719
+ registerDecoratorBean ((Decorator ) bean );
720
+ } else if (bean instanceof ManagedBean ){
721
+ registerManagedBean ((ManagedBean ) bean );
722
+ } else {
723
+ genericBeans .add (bean );
724
+ }
725
+ }
726
+
727
+ private void registerInterceptorBean (Interceptor <?> interceptorBean ) {
696
728
this .interceptorBeans .add (interceptorBean );
697
729
}
698
730
@@ -708,15 +740,15 @@ private void determineDecoratorBeans() {
708
740
}
709
741
710
742
private void determineDecoratorBean (AnnotatedType <?> decoratorType ) {
711
- DecoratorBean <?> decoratorBean = new DecoratorBean (decoratorType ,this );
743
+ DecoratorBean <?> decoratorBean = new DecoratorBean (decoratorType , this );
712
744
fireProcessBeanAttributesEvent (decoratorType , decoratorBean );
713
745
if (!decoratorBean .isVetoed ()) { // vetoed if ProcessBeanAttributes.veto() method was invoked
714
746
fireProcessBeanEvent (decoratorType , decoratorBean );
715
747
registerDecoratorBean (decoratorBean );
716
748
}
717
749
}
718
750
719
- private void registerDecoratorBean (DecoratorBean <?> decoratorBean ) {
751
+ private void registerDecoratorBean (Decorator <?> decoratorBean ) {
720
752
this .decoratorBeans .add (decoratorBean );
721
753
}
722
754
@@ -737,7 +769,7 @@ private void registerDecoratorBeans() {
737
769
* initialization of the application if any observer registers a definition error.
738
770
*/
739
771
private void performAfterBeanDiscovery () {
740
- // TODO
772
+ fireAfterBeanDiscoveryEvent ();
741
773
}
742
774
743
775
/**
@@ -754,7 +786,7 @@ private void performDeploymentValidation() {
754
786
* and abort initialization of the application if any observer registers a deployment problem.
755
787
*/
756
788
private void performAfterDeploymentValidation () {
757
- // TODO
789
+ fireAfterDeploymentValidationEvent ();
758
790
}
759
791
760
792
private StandardBeanManager discoverExtensions () {
@@ -833,6 +865,24 @@ private void fireProcessProducerEvent(AnnotatedMember annotatedMember, Producer
833
865
fireEvent (new ProcessProducerEvent (annotatedMember , producer , this ));
834
866
}
835
867
868
+ /**
869
+ * Fire fire an event when it has fully completed the bean discovery process, validated that there are
870
+ * no definition errors relating to the discovered beans, and registered Bean and ObserverMethod objects
871
+ * for the discovered beans.
872
+ */
873
+ private void fireAfterBeanDiscoveryEvent () {
874
+ fireEvent (new AfterBeanDiscoveryEvent (this ));
875
+ }
876
+
877
+
878
+ /**
879
+ * Fire an event after it has validated that there are no deployment problems and before creating contexts
880
+ * or processing requests.
881
+ */
882
+ private void fireAfterDeploymentValidationEvent () {
883
+ fireEvent (new AfterDeploymentValidationEvent (this ));
884
+ }
885
+
836
886
private void fireEvent (Object event ) {
837
887
observerMethodsManager .fire (event );
838
888
}
@@ -908,6 +958,10 @@ private void registerObserverMethods(Object beanInstance) {
908
958
observerMethodsManager .registerObserverMethods (beanInstance );
909
959
}
910
960
961
+ public void registerObserverMethod (ObserverMethod <?> observerMethod ){
962
+ observerMethodsManager .registerObserverMethod (observerMethod );
963
+ }
964
+
911
965
public StandardBeanManager extensions (Extension ... extensions ) {
912
966
iterate (extensions , this ::addExtension );
913
967
return this ;
@@ -959,10 +1013,6 @@ public BeanArchiveManager getBeanArchiveManager() {
959
1013
return beanArchiveManager ;
960
1014
}
961
1015
962
- public void addBeanDiscoveryDefinitionError (Throwable t ) {
963
- // TODO
964
- }
965
-
966
1016
public Boolean getScanImplicitProperty () {
967
1017
Boolean value = (Boolean ) properties .get (SCAN_IMPLICIT_PROPERTY_NAME );
968
1018
if (value == null ) {
@@ -1003,4 +1053,5 @@ private Set<AnnotatedType<?>> createAnnotatedTypes(Iterable<Class<?>> classes) {
1003
1053
}
1004
1054
return annotatedTypes ;
1005
1055
}
1056
+
1006
1057
}
0 commit comments