|
| 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 | +} |
0 commit comments