Skip to content

Commit aac2910

Browse files
committed
Refactor
1 parent 7e589d7 commit aac2910

File tree

11 files changed

+142
-18
lines changed

11 files changed

+142
-18
lines changed

projects/stage-1/middleware-frameworks/my-cdi/src/main/java/org/geektimes/enterprise/inject/standard/beans/AbstractBeanAttributes.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
*/
1717
package org.geektimes.enterprise.inject.standard.beans;
1818

19-
import org.geektimes.enterprise.inject.standard.annotation.ReflectiveAnnotatedType;
2019
import org.geektimes.enterprise.inject.util.Qualifiers;
2120

2221
import javax.enterprise.inject.Alternative;
@@ -68,7 +67,7 @@ public abstract class AbstractBeanAttributes<A extends AnnotatedElement, T> impl
6867
public AbstractBeanAttributes(A annotatedElement, AnnotatedType<T> beanType) {
6968
requireNonNull(annotatedElement, "The 'annotatedElement' argument must not be null!");
7069
requireNonNull(beanType, "The 'beanType' argument must not be null!");
71-
validateAnnotatedElement(annotatedElement);
70+
validate(annotatedElement);
7271
this.annotatedElement = annotatedElement;
7372
this.beanClass = beanType.getJavaClass();
7473
this.beanTypes = getBeanTypes(beanClass);
@@ -157,7 +156,7 @@ public final boolean isVetoed() {
157156
// Abstract methods
158157
protected abstract String getBeanName(A annotatedElement);
159158

160-
protected abstract void validateAnnotatedElement(A annotatedElement);
159+
protected abstract void validate(A annotatedElement);
161160

162161
public abstract Annotated getAnnotated();
163162

projects/stage-1/middleware-frameworks/my-cdi/src/main/java/org/geektimes/enterprise/inject/standard/beans/GenericBean.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ protected String getBeanName(Class<T> annotatedElement) {
6565
}
6666

6767
@Override
68-
protected void validateAnnotatedElement(Class<T> annotatedElement) {
68+
protected void validate(Class<T> annotatedElement) {
6969
// DO NOTHING
7070
}
7171

projects/stage-1/middleware-frameworks/my-cdi/src/main/java/org/geektimes/enterprise/inject/standard/beans/GenericBeanAttributes.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ protected String getBeanName(Class beanClass) {
4141
}
4242

4343
@Override
44-
protected void validateAnnotatedElement(Class beanClass) {
44+
protected void validate(Class beanClass) {
4545
// DO NOTING
4646
}
4747

projects/stage-1/middleware-frameworks/my-cdi/src/main/java/org/geektimes/enterprise/inject/standard/beans/ManagedBean.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ protected ManagedBean(Class<?> beanClass, BeanManager beanManager) {
6262
}
6363

6464
@Override
65-
protected void validateAnnotatedElement(Class beanClass) {
65+
protected void validate(Class<T> beanClass) {
6666
validateManagedBeanType(beanClass);
6767
validateManagedBeanSpecializes(beanClass);
6868
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.geektimes.enterprise.inject.standard.beans.decorator;
18+
19+
import org.geektimes.enterprise.inject.standard.beans.ManagedBean;
20+
21+
import javax.enterprise.context.spi.CreationalContext;
22+
import javax.enterprise.inject.spi.AnnotatedType;
23+
import javax.enterprise.inject.spi.Bean;
24+
import javax.enterprise.inject.spi.BeanManager;
25+
import javax.enterprise.inject.spi.Decorator;
26+
import java.lang.annotation.Annotation;
27+
import java.lang.reflect.Type;
28+
import java.util.Set;
29+
30+
/**
31+
* {@link Decorator} {@link Bean}
32+
* <p>
33+
* A decorator is a managed bean. The set of decorated types of a decorator includes
34+
* all bean types of the managed bean which are Java interfaces, except for java.io.Serializable.
35+
* The decorator bean class and its superclasses are not decorated types of the decorator.
36+
* The decorator class may be abstract.
37+
* <p>
38+
* A decorator may be an abstract Java class, and is not required to implement every method of
39+
* every decorated type. Whenever the decorator does not implement a method of the decorated type,
40+
* the container will provide an implicit implementation that calls the method on the delegate.
41+
* <p>
42+
* The decorator intercepts every method which is declared by a decorated type of the decorator
43+
* and is implemented by the bean class of the decorator.
44+
* <p>
45+
* Decorators are called after interceptors. Decorators enabled using @Priority are called
46+
* before decorators enabled using beans.xml.
47+
*
48+
* @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
49+
* @since 1.0.0
50+
*/
51+
public class DecoratorBean<T> extends ManagedBean<T> implements Decorator<T> {
52+
53+
public DecoratorBean(AnnotatedType<T> decoratorType, BeanManager beanManager) {
54+
super(decoratorType, beanManager);
55+
}
56+
57+
@Override
58+
public Type getDelegateType() {
59+
return null;
60+
}
61+
62+
@Override
63+
public Set<Annotation> getDelegateQualifiers() {
64+
return null;
65+
}
66+
67+
/**
68+
* @return
69+
*/
70+
@Override
71+
public Set<Type> getDecoratedTypes() {
72+
return null;
73+
}
74+
75+
@Override
76+
protected void validate(Class<T> annotatedElement) {
77+
super.validate(annotatedElement);
78+
79+
// If the set of decorated types of a decorator is empty,
80+
// the container automatically detects the problem and treats it as a definition error.
81+
82+
// If a decorator declares any scope other than @Dependent,
83+
// the container automatically detects the problem and treats it as a definition error.
84+
85+
// If the delegate type does not implement or extend a decorated type of the decorator
86+
// (or specifies different type parameters),
87+
// the container automatically detects the problem and treats it as a definition error.
88+
89+
90+
// validate the injection points
91+
92+
// If a decorator has more than one delegate injection point, or does not have a delegate injection point,
93+
// the container automatically detects the problem and treats it as a definition error.
94+
95+
// The delegate injection point must be an injected field, initializer method parameter or
96+
// bean constructor method parameter. If an injection point that is not an injected field,
97+
// initializer method parameter or bean constructor method parameter is annotated @Delegate,
98+
// the container automatically detects the problem and treats it as a definition error.
99+
100+
// If a bean class that is not a decorator has an injection point annotated @Delegate,
101+
// the container automatically detects the problem and treats it as a definition error.
102+
103+
104+
// validate methods
105+
106+
// If a decorator has abstract methods that are not declared by a decorated type,
107+
// the container automatically detects the problem and treats it as a definition error.
108+
}
109+
110+
@Override
111+
public T create(CreationalContext<T> creationalContext) {
112+
// TODO
113+
return super.create(creationalContext);
114+
}
115+
116+
@Override
117+
public void destroy(T instance, CreationalContext<T> creationalContext) {
118+
// TODO
119+
super.destroy(instance, creationalContext);
120+
}
121+
}

projects/stage-1/middleware-frameworks/my-cdi/src/main/java/org/geektimes/enterprise/inject/standard/beans/interceptor/InterceptorBean.java

+1-7
Original file line numberDiff line numberDiff line change
@@ -120,13 +120,7 @@ public void destroy(T instance, CreationalContext<T> creationalContext) {
120120
}
121121

122122
@Override
123-
protected String getBeanName(Class interceptorClass) {
124-
// TODO
125-
return null;
126-
}
127-
128-
@Override
129-
protected void validateAnnotatedElement(Class interceptorClass) {
123+
protected void validate(Class interceptorClass) {
130124
this.interceptorManager.validateInterceptorClass(interceptorClass);
131125
}
132126

projects/stage-1/middleware-frameworks/my-cdi/src/main/java/org/geektimes/enterprise/inject/standard/beans/manager/StandardBeanManager.java

+11-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import org.geektimes.enterprise.inject.standard.beans.GenericBeanAttributes;
2727
import org.geektimes.enterprise.inject.standard.beans.InjectionTargetBean;
2828
import org.geektimes.enterprise.inject.standard.beans.ManagedBean;
29+
import org.geektimes.enterprise.inject.standard.beans.decorator.DecoratorBean;
2930
import org.geektimes.enterprise.inject.standard.beans.interceptor.InterceptorBean;
3031
import org.geektimes.enterprise.inject.standard.beans.producer.ProducerBean;
3132
import org.geektimes.enterprise.inject.standard.beans.producer.ProducerFieldBean;
@@ -707,7 +708,16 @@ private void determineDecoratorBeans() {
707708
}
708709

709710
private void determineDecoratorBean(AnnotatedType<?> decoratorType) {
710-
// TODO
711+
DecoratorBean<?> decoratorBean = new DecoratorBean(decoratorType,this);
712+
fireProcessBeanAttributesEvent(decoratorType, decoratorBean);
713+
if (!decoratorBean.isVetoed()) { // vetoed if ProcessBeanAttributes.veto() method was invoked
714+
fireProcessBeanEvent(decoratorType, decoratorBean);
715+
registerDecoratorBean(decoratorBean);
716+
}
717+
}
718+
719+
private void registerDecoratorBean(DecoratorBean<?> decoratorBean) {
720+
this.decoratorBeans.add(decoratorBean);
711721
}
712722

713723
private void registerBeans() {

projects/stage-1/middleware-frameworks/my-cdi/src/main/java/org/geektimes/enterprise/inject/standard/beans/producer/ProducerFieldBean.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public ProducerFieldBean(AnnotatedField producerField) {
4646
}
4747

4848
@Override
49-
protected void validateAnnotatedElement(Field producerField) {
49+
protected void validate(Field producerField) {
5050
validateProducerField(producerField);
5151
}
5252

projects/stage-1/middleware-frameworks/my-cdi/src/main/java/org/geektimes/enterprise/inject/standard/beans/producer/ProducerMethodBean.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public ProducerMethodBean(AnnotatedMethod<T> method) {
4848
}
4949

5050
@Override
51-
protected void validateAnnotatedElement(Method producerMethod) {
51+
protected void validate(Method producerMethod) {
5252
validateProducerMethod(producerMethod);
5353
}
5454

projects/stage-1/middleware-frameworks/my-cdi/src/main/java/org/geektimes/enterprise/inject/standard/producer/ProducerFieldBeanAttributes.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ protected String getBeanName(Field producerField) {
4747
}
4848

4949
@Override
50-
protected void validateAnnotatedElement(Field producerField) {
50+
protected void validate(Field producerField) {
5151
Producers.validateProducerField(producerField);
5252
}
5353

projects/stage-1/middleware-frameworks/my-cdi/src/main/java/org/geektimes/enterprise/inject/standard/producer/ProducerMethodBeanAttributes.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ protected String getBeanName(Method producerMethod) {
4747
}
4848

4949
@Override
50-
protected void validateAnnotatedElement(Method producerMethod) {
50+
protected void validate(Method producerMethod) {
5151
Producers.validateProducerMethod(producerMethod);
5252
}
5353

0 commit comments

Comments
 (0)