|
34 | 34 | import org.geektimes.enterprise.inject.standard.context.mananger.ContextManager;
|
35 | 35 | import org.geektimes.enterprise.inject.standard.disposer.DisposerMethodManager;
|
36 | 36 | import org.geektimes.enterprise.inject.standard.event.*;
|
| 37 | +import org.geektimes.enterprise.inject.standard.event.application.*; |
| 38 | +import org.geektimes.enterprise.inject.standard.observer.ObserverMethodManager; |
37 | 39 | import org.geektimes.enterprise.inject.standard.producer.ProducerFieldBeanAttributes;
|
38 | 40 | import org.geektimes.enterprise.inject.standard.producer.ProducerFieldFactory;
|
39 | 41 | import org.geektimes.enterprise.inject.standard.producer.ProducerMethodBeanAttributes;
|
|
50 | 52 | import javax.enterprise.event.Event;
|
51 | 53 | import javax.enterprise.event.Observes;
|
52 | 54 | import javax.enterprise.event.ObservesAsync;
|
53 |
| -import javax.enterprise.inject.Disposes; |
54 |
| -import javax.enterprise.inject.Instance; |
55 |
| -import javax.enterprise.inject.Produces; |
56 |
| -import javax.enterprise.inject.Stereotype; |
| 55 | +import javax.enterprise.inject.*; |
57 | 56 | import javax.enterprise.inject.spi.*;
|
58 | 57 | import javax.enterprise.util.TypeLiteral;
|
59 | 58 | import java.lang.annotation.Annotation;
|
60 | 59 | import java.lang.reflect.Method;
|
61 | 60 | import java.lang.reflect.Type;
|
62 | 61 | import java.lang.reflect.TypeVariable;
|
63 |
| -import java.lang.reflect.WildcardType; |
64 | 62 | import java.util.*;
|
65 | 63 | import java.util.function.Function;
|
66 | 64 |
|
@@ -180,8 +178,8 @@ public Object getReference(Bean<?> bean, Type beanType, CreationalContext<?> ctx
|
180 | 178 | assertAfterDeploymentValidation();
|
181 | 179 | if (!Objects.equals(beanType.getTypeName(), bean.getBeanClass().getTypeName())) {
|
182 | 180 | throw new IllegalArgumentException(format("The given type[%s] is not a bean type[%s] of the given bean!",
|
183 |
| - beanType.getTypeName(), |
184 |
| - bean.getBeanClass())); |
| 181 | + beanType.getTypeName(), |
| 182 | + bean.getBeanClass())); |
185 | 183 | }
|
186 | 184 | Class<? extends Annotation> scope = bean.getScope();
|
187 | 185 | Context context = getContext(scope);
|
@@ -253,12 +251,12 @@ public void validate(InjectionPoint injectionPoint) {
|
253 | 251 | *
|
254 | 252 | * @param injectionPoint {@link InjectionPoint}
|
255 | 253 | * @throws DefinitionException If an injection point type is a type variable, the container automatically
|
256 |
| - * detects the problem and treats it as a definition error. |
| 254 | + * detects the problem and treats it as a definition error. |
257 | 255 | */
|
258 | 256 | private void validateInjectionPointType(InjectionPoint injectionPoint) throws DefinitionException {
|
259 | 257 | Type type = injectionPoint.getType();
|
260 |
| - if(type instanceof TypeVariable){ |
261 |
| - throw newDefinitionException("A type variable[%s] is not a legal injection point[%s] type",type,injectionPoint); |
| 258 | + if (type instanceof TypeVariable) { |
| 259 | + throw newDefinitionException("A type variable[%s] is not a legal injection point[%s] type", type, injectionPoint); |
262 | 260 | }
|
263 | 261 | }
|
264 | 262 |
|
@@ -539,6 +537,26 @@ public void initialize() {
|
539 | 537 | // TODO
|
540 | 538 | }
|
541 | 539 |
|
| 540 | + /** |
| 541 | + * When an application is stopped, the container performs the following steps: |
| 542 | + * <ol> |
| 543 | + * <li>the container must destroy all contexts.</li> |
| 544 | + * <li>the container must fire an event of type {@link BeforeShutdown}</li> |
| 545 | + * </ol> |
| 546 | + */ |
| 547 | + public void shutdown() { |
| 548 | + destroyContexts(); |
| 549 | + fireBeforeShutdownEvent(); |
| 550 | + } |
| 551 | + |
| 552 | + private void destroyContexts() { |
| 553 | + contextManager.destroy(); |
| 554 | + } |
| 555 | + |
| 556 | + private void fireBeforeShutdownEvent() { |
| 557 | + fireEvent(new BeforeShutdownEvent(this)); |
| 558 | + } |
| 559 | + |
542 | 560 |
|
543 | 561 | /**
|
544 | 562 | * Is defining annotation type or not.
|
@@ -937,6 +955,15 @@ private void fireBeforeBeanDiscoveryEvent() {
|
937 | 955 | fireEvent(new BeforeBeanDiscoveryEvent(this));
|
938 | 956 | }
|
939 | 957 |
|
| 958 | + /** |
| 959 | + * The container must fire an event, before it processes a type, for every Java class, interface |
| 960 | + * (excluding annotation type, a special kind of interface type) or enum discovered as defined |
| 961 | + * in Type discovery. |
| 962 | + * An event is not fired for any type annotated with {@link Vetoed @Vetoed}, |
| 963 | + * or in a package annotated with {@link Vetoed @Vetoed} |
| 964 | + * |
| 965 | + * @param annotatedType {@link AnnotatedType} |
| 966 | + */ |
940 | 967 | private void fireProcessAnnotatedTypeEvent(AnnotatedType<?> annotatedType) {
|
941 | 968 | if (!isAnnotatedVetoed(annotatedType.getJavaClass())) {
|
942 | 969 | fireEvent(new ProcessAnnotatedTypeEvent(annotatedType, this));
|
|
0 commit comments