Commit 5db1c2ab446f3b6210a0bb5d4c02be026c5da49a
1 parent
2ca9d1be
Exists in
master
Remoção da classe CustomBean que não é mais utilizada por ninguém
Showing
1 changed file
with
0 additions
and
193 deletions
Show diff stats
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/CustomBean.java
| @@ -1,193 +0,0 @@ | @@ -1,193 +0,0 @@ | ||
| 1 | -/* | ||
| 2 | - * Demoiselle Framework | ||
| 3 | - * Copyright (C) 2010 SERPRO | ||
| 4 | - * ---------------------------------------------------------------------------- | ||
| 5 | - * This file is part of Demoiselle Framework. | ||
| 6 | - * | ||
| 7 | - * Demoiselle Framework is free software; you can redistribute it and/or | ||
| 8 | - * modify it under the terms of the GNU Lesser General Public License version 3 | ||
| 9 | - * as published by the Free Software Foundation. | ||
| 10 | - * | ||
| 11 | - * This program is distributed in the hope that it will be useful, | ||
| 12 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 13 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 14 | - * GNU General Public License for more details. | ||
| 15 | - * | ||
| 16 | - * You should have received a copy of the GNU Lesser General Public License version 3 | ||
| 17 | - * along with this program; if not, see <http://www.gnu.org/licenses/> | ||
| 18 | - * or write to the Free Software Foundation, Inc., 51 Franklin Street, | ||
| 19 | - * Fifth Floor, Boston, MA 02110-1301, USA. | ||
| 20 | - * ---------------------------------------------------------------------------- | ||
| 21 | - * Este arquivo é parte do Framework Demoiselle. | ||
| 22 | - * | ||
| 23 | - * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou | ||
| 24 | - * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação | ||
| 25 | - * do Software Livre (FSF). | ||
| 26 | - * | ||
| 27 | - * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA | ||
| 28 | - * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou | ||
| 29 | - * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português | ||
| 30 | - * para maiores detalhes. | ||
| 31 | - * | ||
| 32 | - * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título | ||
| 33 | - * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> | ||
| 34 | - * ou escreva para a Fundação do Software Livre (FSF) Inc., | ||
| 35 | - * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | ||
| 36 | - */ | ||
| 37 | -package br.gov.frameworkdemoiselle.internal.bootstrap; | ||
| 38 | - | ||
| 39 | -import java.io.Serializable; | ||
| 40 | -import java.lang.annotation.Annotation; | ||
| 41 | -import java.lang.reflect.Type; | ||
| 42 | -import java.util.HashSet; | ||
| 43 | -import java.util.Set; | ||
| 44 | - | ||
| 45 | -import javax.enterprise.context.Dependent; | ||
| 46 | -import javax.enterprise.context.NormalScope; | ||
| 47 | -import javax.enterprise.context.spi.CreationalContext; | ||
| 48 | -import javax.enterprise.inject.Alternative; | ||
| 49 | -import javax.enterprise.inject.Any; | ||
| 50 | -import javax.enterprise.inject.Default; | ||
| 51 | -import javax.enterprise.inject.Stereotype; | ||
| 52 | -import javax.enterprise.inject.spi.AnnotatedType; | ||
| 53 | -import javax.enterprise.inject.spi.Bean; | ||
| 54 | -import javax.enterprise.inject.spi.BeanManager; | ||
| 55 | -import javax.enterprise.inject.spi.InjectionPoint; | ||
| 56 | -import javax.enterprise.inject.spi.InjectionTarget; | ||
| 57 | -import javax.enterprise.util.AnnotationLiteral; | ||
| 58 | -import javax.inject.Named; | ||
| 59 | -import javax.inject.Qualifier; | ||
| 60 | -import javax.inject.Scope; | ||
| 61 | - | ||
| 62 | -import br.gov.frameworkdemoiselle.util.Beans; | ||
| 63 | - | ||
| 64 | -/** | ||
| 65 | - * @see http://docs.jboss.org/weld/reference/latest/en-US/html_single/#d0e5035 | ||
| 66 | - */ | ||
| 67 | -public class CustomBean implements Bean<Object>, Serializable { | ||
| 68 | - | ||
| 69 | - private static final long serialVersionUID = 1L; | ||
| 70 | - | ||
| 71 | - private Class<Object> beanClass; | ||
| 72 | - | ||
| 73 | - private transient InjectionTarget<Object> injectionTarget; | ||
| 74 | - | ||
| 75 | - private transient BeanManager beanManager; | ||
| 76 | - | ||
| 77 | - private InjectionTarget<Object> getInjectionTarget() { | ||
| 78 | - if (this.injectionTarget == null) { | ||
| 79 | - AnnotatedType<Object> annotatedType = getBeanManager().createAnnotatedType(beanClass); | ||
| 80 | - this.injectionTarget = getBeanManager().createInjectionTarget(annotatedType); | ||
| 81 | - } | ||
| 82 | - | ||
| 83 | - return this.injectionTarget; | ||
| 84 | - } | ||
| 85 | - | ||
| 86 | - private BeanManager getBeanManager() { | ||
| 87 | - if (this.beanManager == null) { | ||
| 88 | - this.beanManager = Beans.getBeanManager(); | ||
| 89 | - } | ||
| 90 | - | ||
| 91 | - return this.beanManager; | ||
| 92 | - } | ||
| 93 | - | ||
| 94 | - public CustomBean(Class<Object> beanClass, BeanManager beanManager) { | ||
| 95 | - this.beanClass = beanClass; | ||
| 96 | - this.beanManager = beanManager; | ||
| 97 | - } | ||
| 98 | - | ||
| 99 | - public Object create(CreationalContext<Object> creationalContext) { | ||
| 100 | - Object instance = getInjectionTarget().produce(creationalContext); | ||
| 101 | - getInjectionTarget().inject(instance, creationalContext); | ||
| 102 | - getInjectionTarget().postConstruct(instance); | ||
| 103 | - | ||
| 104 | - return instance; | ||
| 105 | - } | ||
| 106 | - | ||
| 107 | - public void destroy(Object instance, CreationalContext<Object> creationalContext) { | ||
| 108 | - getInjectionTarget().preDestroy(instance); | ||
| 109 | - getInjectionTarget().dispose(instance); | ||
| 110 | - creationalContext.release(); | ||
| 111 | - } | ||
| 112 | - | ||
| 113 | - public Set<Type> getTypes() { | ||
| 114 | - Set<Type> types = new HashSet<Type>(); | ||
| 115 | - types.add(beanClass.getSuperclass()); | ||
| 116 | - types.add(Object.class); | ||
| 117 | - | ||
| 118 | - return types; | ||
| 119 | - } | ||
| 120 | - | ||
| 121 | - @SuppressWarnings("serial") | ||
| 122 | - public Set<Annotation> getQualifiers() { | ||
| 123 | - Set<Annotation> result = new HashSet<Annotation>(); | ||
| 124 | - | ||
| 125 | - result.add(new AnnotationLiteral<Default>() { | ||
| 126 | - }); | ||
| 127 | - result.add(new AnnotationLiteral<Any>() { | ||
| 128 | - }); | ||
| 129 | - | ||
| 130 | - for (Annotation annotation : beanClass.getAnnotations()) { | ||
| 131 | - if (annotation.getClass().isAnnotationPresent(Qualifier.class)) { | ||
| 132 | - result.add(annotation); | ||
| 133 | - } | ||
| 134 | - } | ||
| 135 | - | ||
| 136 | - return result; | ||
| 137 | - } | ||
| 138 | - | ||
| 139 | - public Class<? extends Annotation> getScope() { | ||
| 140 | - Class<? extends Annotation> result = Dependent.class; | ||
| 141 | - | ||
| 142 | - Class<? extends Annotation> annotationClass; | ||
| 143 | - for (Annotation annotation : beanClass.getAnnotations()) { | ||
| 144 | - annotationClass = annotation.getClass(); | ||
| 145 | - | ||
| 146 | - if (annotationClass.isAnnotationPresent(Scope.class) | ||
| 147 | - || annotationClass.isAnnotationPresent(NormalScope.class)) { | ||
| 148 | - result = annotationClass; | ||
| 149 | - break; | ||
| 150 | - } | ||
| 151 | - } | ||
| 152 | - | ||
| 153 | - return result; | ||
| 154 | - } | ||
| 155 | - | ||
| 156 | - public String getName() { | ||
| 157 | - String result = null; | ||
| 158 | - | ||
| 159 | - if (beanClass.isAnnotationPresent(Named.class)) { | ||
| 160 | - result = beanClass.getAnnotation(Named.class).value(); | ||
| 161 | - } | ||
| 162 | - | ||
| 163 | - return result; | ||
| 164 | - } | ||
| 165 | - | ||
| 166 | - public Set<Class<? extends Annotation>> getStereotypes() { | ||
| 167 | - Set<Class<? extends Annotation>> result = new HashSet<Class<? extends Annotation>>(); | ||
| 168 | - | ||
| 169 | - for (Annotation annotation : beanClass.getAnnotations()) { | ||
| 170 | - if (annotation.getClass().isAnnotationPresent(Stereotype.class)) { | ||
| 171 | - result.add(annotation.getClass()); | ||
| 172 | - } | ||
| 173 | - } | ||
| 174 | - | ||
| 175 | - return result; | ||
| 176 | - } | ||
| 177 | - | ||
| 178 | - public Class<Object> getBeanClass() { | ||
| 179 | - return beanClass; | ||
| 180 | - } | ||
| 181 | - | ||
| 182 | - public boolean isAlternative() { | ||
| 183 | - return beanClass.isAnnotationPresent(Alternative.class); | ||
| 184 | - } | ||
| 185 | - | ||
| 186 | - public boolean isNullable() { | ||
| 187 | - return false; | ||
| 188 | - } | ||
| 189 | - | ||
| 190 | - public Set<InjectionPoint> getInjectionPoints() { | ||
| 191 | - return getInjectionTarget().getInjectionPoints(); | ||
| 192 | - } | ||
| 193 | -} |