[weld-commits] Weld SVN: r6203 - in extensions/trunk/src/main/java/org/jboss/weld/extensions: bean and 2 other directories.

weld-commits at lists.jboss.org weld-commits at lists.jboss.org
Thu Apr 29 18:13:30 EDT 2010


Author: pete.muir at jboss.org
Date: 2010-04-29 18:13:29 -0400 (Thu, 29 Apr 2010)
New Revision: 6203

Added:
   extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/BeanBuilder.java
   extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/BeanImpl.java
   extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/BeanLifecycleImpl.java
   extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/InjectionPointImpl.java
   extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/PassivationCapableBeanImpl.java
Removed:
   extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/CustomBean.java
   extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/CustomBeanBuilder.java
   extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/CustomInjectionPoint.java
   extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/PassivationCapableCustomBean.java
   extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/SimpleBeanLifecycle.java
Modified:
   extensions/trunk/src/main/java/org/jboss/weld/extensions/annotated/Annotateds.java
   extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/BeanLifecycle.java
   extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/generic/GenericExtension.java
   extensions/trunk/src/main/java/org/jboss/weld/extensions/core/CoreExtension.java
Log:
cleanup custom bean impl

Modified: extensions/trunk/src/main/java/org/jboss/weld/extensions/annotated/Annotateds.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/annotated/Annotateds.java	2010-04-29 21:51:53 UTC (rev 6202)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/annotated/Annotateds.java	2010-04-29 22:13:29 UTC (rev 6203)
@@ -182,6 +182,8 @@
    }
 
    private static final char SEPERATOR = ';';
+   
+   private Annotateds() {}
 
    /**
     * Generates a unique signature for an annotated type. Members without
@@ -558,8 +560,4 @@
 
    }
 
-   private Annotateds()
-   {
-   }
-
 }

Copied: extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/BeanBuilder.java (from rev 6202, extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/CustomBeanBuilder.java)
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/BeanBuilder.java	                        (rev 0)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/BeanBuilder.java	2010-04-29 22:13:29 UTC (rev 6203)
@@ -0,0 +1,248 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,  
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jboss.weld.extensions.bean;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.enterprise.context.Dependent;
+import javax.enterprise.inject.Alternative;
+import javax.enterprise.inject.spi.AnnotatedType;
+import javax.enterprise.inject.spi.Bean;
+import javax.enterprise.inject.spi.BeanManager;
+import javax.enterprise.inject.spi.InjectionTarget;
+import javax.inject.Named;
+
+import org.jboss.weld.extensions.annotated.Annotateds;
+
+/**
+ * class that can build a bean from an AnnotatedType.
+ * 
+ * @author stuart
+ * 
+ */
+public class BeanBuilder<T>
+{
+
+   private final AnnotatedType<T> type;
+   private final BeanManager beanManager;
+   private InjectionTarget<T> injectionTarget;
+   private String name;
+   private Set<Annotation> qualifiers;
+   private Class<? extends Annotation> scope;
+   private Set<Class<? extends Annotation>> stereotypes;
+   private Set<Type> types = new HashSet<Type>();
+   private boolean alternative = false;
+   private boolean nullable = false;
+   private BeanLifecycle<T> beanLifecycle;
+   boolean passivationCapable;
+   private String id;
+
+   public BeanBuilder(AnnotatedType<T> type, BeanManager beanManager)
+   {
+      this.type = type;
+      this.beanManager = beanManager;
+   }
+   
+   public BeanBuilder<T> defineBeanFromAnnotatedType()
+   {
+      this.injectionTarget = beanManager.createInjectionTarget(type);
+      this.qualifiers = new HashSet<Annotation>();
+      this.stereotypes = new HashSet<Class<? extends Annotation>>();
+      for (Annotation annotation : type.getAnnotations())
+      {
+         if (beanManager.isQualifier(annotation.annotationType()))
+         {
+            this.qualifiers.add(annotation);
+         }
+         else if (beanManager.isScope(annotation.annotationType()))
+         {
+            this.scope = annotation.annotationType();
+         }
+         else if (beanManager.isStereotype(annotation.annotationType()))
+         {
+            this.stereotypes.add(annotation.annotationType());
+         }
+         if (annotation instanceof Named)
+         {
+            this.name = ((Named) annotation).value();
+         }
+         if (annotation instanceof Alternative)
+         {
+            this.alternative = true;
+         }
+      }
+      if (this.scope == null)
+      {
+         this.scope = Dependent.class;
+      }
+      for (Class<?> c = type.getJavaClass(); c != Object.class && c != null; c = c.getSuperclass())
+      {
+         this.types.add(c);
+      }
+      for (Class<?> i : type.getJavaClass().getInterfaces())
+      {
+         this.types.add(i);
+      }
+      this.beanLifecycle = new BeanLifecycleImpl<T>();
+      this.id = BeanImpl.class.getName() + ":" + Annotateds.createTypeId(type);
+      return this;
+   }
+
+   public Bean<T> create()
+   {
+      if (!passivationCapable)
+      {
+         return new BeanImpl<T>(type.getJavaClass(), injectionTarget, name, qualifiers, scope, stereotypes, types, alternative, nullable, beanLifecycle);
+      }
+      return new PassivationCapableBeanImpl<T>(id, type.getJavaClass(), injectionTarget, name, qualifiers, scope, stereotypes, types, alternative, nullable, beanLifecycle);
+
+   }
+
+   public InjectionTarget<T> getInjectionTarget()
+   {
+      return injectionTarget;
+   }
+
+   public BeanBuilder<T> setInjectionTarget(InjectionTarget<T> injectionTarget)
+   {
+      this.injectionTarget = injectionTarget;
+      return this;
+   }
+   public Set<Annotation> getQualifiers()
+   {
+      return qualifiers;
+   }
+
+   public BeanBuilder<T> setQualifiers(Set<Annotation> qualifiers)
+   {
+      this.qualifiers = qualifiers;
+      return this;
+   }
+
+   public Class<? extends Annotation> getScope()
+   {
+      return scope;
+   }
+
+   public BeanBuilder<T> setScope(Class<? extends Annotation> scope)
+   {
+      this.scope = scope;
+      return this;
+   }
+
+   public Set<Class<? extends Annotation>> getStereotypes()
+   {
+      return stereotypes;
+   }
+
+   public BeanBuilder<T> setStereotypes(Set<Class<? extends Annotation>> stereotypes)
+   {
+      this.stereotypes = stereotypes;
+      return this;
+   }
+
+   public Set<Type> getTypes()
+   {
+      return types;
+   }
+
+   public BeanBuilder<T> setTypes(Set<Type> types)
+   {
+      this.types = types;
+      return this;
+   }
+
+   public boolean isAlternative()
+   {
+      return alternative;
+   }
+
+   public BeanBuilder<T> setAlternative(boolean alternative)
+   {
+      this.alternative = alternative;
+      return this;
+   }
+
+   public boolean isNullable()
+   {
+      return nullable;
+   }
+
+   public BeanBuilder<T> setNullable(boolean nullable)
+   {
+      this.nullable = nullable;
+      return this;
+   }
+
+   public BeanLifecycle<T> getBeanLifecycle()
+   {
+      return beanLifecycle;
+   }
+
+   public BeanBuilder<T> setBeanLifecycle(BeanLifecycle<T> beanLifecycle)
+   {
+      this.beanLifecycle = beanLifecycle;
+      return this;
+   }
+
+   public AnnotatedType<T> getType()
+   {
+      return type;
+   }
+
+   public BeanManager getBeanManager()
+   {
+      return beanManager;
+   }
+
+   public String getName()
+   {
+      return name;
+   }
+
+   public BeanBuilder<T> setName(String name)
+   {
+      this.name = name;
+      return this;
+   }
+
+   public boolean isPassivationCapable()
+   {
+      return passivationCapable;
+   }
+
+   public BeanBuilder<T> setPassivationCapable(boolean passivationCapable)
+   {
+      this.passivationCapable = passivationCapable;
+      return this;
+   }
+
+   public String getId()
+   {
+      return id;
+   }
+
+   public BeanBuilder<T> setId(String id)
+   {
+      this.id = id;
+      return this;
+   }
+
+}

Copied: extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/BeanImpl.java (from rev 6200, extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/CustomBean.java)
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/BeanImpl.java	                        (rev 0)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/BeanImpl.java	2010-04-29 22:13:29 UTC (rev 6203)
@@ -0,0 +1,130 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,  
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jboss.weld.extensions.bean;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.enterprise.context.spi.CreationalContext;
+import javax.enterprise.inject.spi.Bean;
+import javax.enterprise.inject.spi.InjectionPoint;
+import javax.enterprise.inject.spi.InjectionTarget;
+
+/**
+ * An immutable bean.
+ * 
+ * @author stuart
+ * 
+ * @param <T>
+ */
+class BeanImpl<T> implements Bean<T>
+{
+   private final Class<?> beanClass;
+   private final InjectionTarget<T> injectionTarget;
+   private final String name;
+   private final Set<Annotation> qualifiers;
+   private final Class<? extends Annotation> scope;
+   private final Set<Class<? extends Annotation>> stereotypes;
+   private final Set<Type> types;
+   private final boolean alternative;
+   private final boolean nullable;
+   private final BeanLifecycle<T> beanLifecycle;
+
+   BeanImpl(Class<?> beanClass, InjectionTarget<T> injectionTarget, String name, Set<Annotation> qualifiers, Class<? extends Annotation> scope, Set<Class<? extends Annotation>> stereotypes, Set<Type> types, boolean alternative, boolean nullable, BeanLifecycle<T> beanLifecycle)
+   {
+      this.beanClass = beanClass;
+      this.injectionTarget = injectionTarget;
+      this.name = name;
+      this.qualifiers = new HashSet<Annotation>(qualifiers);
+      this.scope = scope;
+      this.stereotypes = new HashSet<Class<? extends Annotation>>(stereotypes);
+      this.types = new HashSet<Type>(types);
+      this.alternative = alternative;
+      this.nullable = nullable;
+      this.beanLifecycle = beanLifecycle;
+   }
+
+   public Class<?> getBeanClass()
+   {
+      return beanClass;
+   }
+
+   public Set<InjectionPoint> getInjectionPoints()
+   {
+      return injectionTarget.getInjectionPoints();
+   }
+
+   public InjectionTarget<T> getInjectionTarget()
+   {
+      return injectionTarget;
+   }
+
+   public String getName()
+   {
+      return name;
+   }
+
+   public Set<Annotation> getQualifiers()
+   {
+      return Collections.unmodifiableSet(qualifiers);
+   }
+
+   public Class<? extends Annotation> getScope()
+   {
+      return scope;
+   }
+
+   public Set<Class<? extends Annotation>> getStereotypes()
+   {
+      return Collections.unmodifiableSet(stereotypes);
+   }
+
+   public Set<Type> getTypes()
+   {
+      return Collections.unmodifiableSet(types);
+   }
+
+   public boolean isAlternative()
+   {
+      return alternative;
+   }
+
+   public boolean isNullable()
+   {
+      return nullable;
+   }
+
+   public T create(CreationalContext<T> arg0)
+   {
+      return beanLifecycle.create(this, arg0);
+   }
+
+   public void destroy(T arg0, CreationalContext<T> arg1)
+   {
+      beanLifecycle.destroy(this, arg0, arg1);
+   }
+   
+   @Override
+   public String toString()
+   {
+      return new StringBuilder().append("Custom Bean with bean class ").append(beanClass).append(" and qualifiers ").append(qualifiers).toString();
+   }
+
+}

Modified: extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/BeanLifecycle.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/BeanLifecycle.java	2010-04-29 21:51:53 UTC (rev 6202)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/BeanLifecycle.java	2010-04-29 22:13:29 UTC (rev 6203)
@@ -27,8 +27,8 @@
  */
 public interface BeanLifecycle<T>
 {
-   public T create(CustomBean<T> bean, CreationalContext<T> arg0);
+   public T create(BeanImpl<T> bean, CreationalContext<T> arg0);
 
-   public void destroy(CustomBean<T> bean, T arg0, CreationalContext<T> arg1);
+   public void destroy(BeanImpl<T> bean, T arg0, CreationalContext<T> arg1);
 
 }

Copied: extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/BeanLifecycleImpl.java (from rev 6200, extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/SimpleBeanLifecycle.java)
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/BeanLifecycleImpl.java	                        (rev 0)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/BeanLifecycleImpl.java	2010-04-29 22:13:29 UTC (rev 6203)
@@ -0,0 +1,47 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,  
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jboss.weld.extensions.bean;
+
+import javax.enterprise.context.spi.CreationalContext;
+
+public class BeanLifecycleImpl<T> implements BeanLifecycle<T>
+{
+
+   public BeanLifecycleImpl() {}
+
+   public T create(BeanImpl<T> bean, CreationalContext<T> creationalContext)
+   {
+      T instance = bean.getInjectionTarget().produce(creationalContext);
+      bean.getInjectionTarget().inject(instance, creationalContext);
+      bean.getInjectionTarget().postConstruct(instance);
+      return instance;
+   }
+
+   public void destroy(BeanImpl<T> bean, T instance, CreationalContext<T> creationalContext)
+   {
+      try
+      {
+         bean.getInjectionTarget().preDestroy(instance);
+         creationalContext.release();
+      }
+      catch (Exception e)
+      {
+         throw new RuntimeException(e);
+      }
+   }
+
+}

Deleted: extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/CustomBean.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/CustomBean.java	2010-04-29 21:51:53 UTC (rev 6202)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/CustomBean.java	2010-04-29 22:13:29 UTC (rev 6203)
@@ -1,130 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat, Inc., and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * http://www.apache.org/licenses/LICENSE-2.0
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,  
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.jboss.weld.extensions.bean;
-
-import java.lang.annotation.Annotation;
-import java.lang.reflect.Type;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Set;
-
-import javax.enterprise.context.spi.CreationalContext;
-import javax.enterprise.inject.spi.Bean;
-import javax.enterprise.inject.spi.InjectionPoint;
-import javax.enterprise.inject.spi.InjectionTarget;
-
-/**
- * An immutable bean.
- * 
- * @author stuart
- * 
- * @param <T>
- */
-public class CustomBean<T> implements Bean<T>
-{
-   final Class<?> beanClass;
-   final InjectionTarget<T> injectionTarget;
-   final String name;
-   final Set<Annotation> qualifiers;
-   final Class<? extends Annotation> scope;
-   final Set<Class<? extends Annotation>> stereotypes;
-   final Set<Type> types;
-   final boolean alternative;
-   final boolean nullable;
-   final BeanLifecycle<T> beanLifecycle;
-
-   CustomBean(Class<?> beanClass, InjectionTarget<T> injectionTarget, String name, Set<Annotation> qualifiers, Class<? extends Annotation> scope, Set<Class<? extends Annotation>> stereotypes, Set<Type> types, boolean alternative, boolean nullable, BeanLifecycle<T> beanLifecycle)
-   {
-      this.beanClass = beanClass;
-      this.injectionTarget = injectionTarget;
-      this.name = name;
-      this.qualifiers = new HashSet<Annotation>(qualifiers);
-      this.scope = scope;
-      this.stereotypes = new HashSet<Class<? extends Annotation>>(stereotypes);
-      this.types = new HashSet<Type>(types);
-      this.alternative = alternative;
-      this.nullable = nullable;
-      this.beanLifecycle = beanLifecycle;
-   }
-
-   public Class<?> getBeanClass()
-   {
-      return beanClass;
-   }
-
-   public Set<InjectionPoint> getInjectionPoints()
-   {
-      return injectionTarget.getInjectionPoints();
-   }
-
-   public InjectionTarget<T> getInjectionTarget()
-   {
-      return injectionTarget;
-   }
-
-   public String getName()
-   {
-      return name;
-   }
-
-   public Set<Annotation> getQualifiers()
-   {
-      return Collections.unmodifiableSet(qualifiers);
-   }
-
-   public Class<? extends Annotation> getScope()
-   {
-      return scope;
-   }
-
-   public Set<Class<? extends Annotation>> getStereotypes()
-   {
-      return Collections.unmodifiableSet(stereotypes);
-   }
-
-   public Set<Type> getTypes()
-   {
-      return Collections.unmodifiableSet(types);
-   }
-
-   public boolean isAlternative()
-   {
-      return alternative;
-   }
-
-   public boolean isNullable()
-   {
-      return nullable;
-   }
-
-   public T create(CreationalContext<T> arg0)
-   {
-      return beanLifecycle.create(this, arg0);
-   }
-
-   public void destroy(T arg0, CreationalContext<T> arg1)
-   {
-      beanLifecycle.destroy(this, arg0, arg1);
-   }
-   
-   @Override
-   public String toString()
-   {
-      return new StringBuilder().append("Custom Bean with bean class ").append(beanClass).append(" and qualifiers ").append(qualifiers).toString();
-   }
-
-}

Deleted: extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/CustomBeanBuilder.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/CustomBeanBuilder.java	2010-04-29 21:51:53 UTC (rev 6202)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/CustomBeanBuilder.java	2010-04-29 22:13:29 UTC (rev 6203)
@@ -1,242 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat, Inc., and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * http://www.apache.org/licenses/LICENSE-2.0
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,  
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.jboss.weld.extensions.bean;
-
-import java.lang.annotation.Annotation;
-import java.lang.reflect.Type;
-import java.util.HashSet;
-import java.util.Set;
-
-import javax.enterprise.context.Dependent;
-import javax.enterprise.inject.Alternative;
-import javax.enterprise.inject.spi.AnnotatedType;
-import javax.enterprise.inject.spi.Bean;
-import javax.enterprise.inject.spi.BeanManager;
-import javax.enterprise.inject.spi.InjectionTarget;
-import javax.inject.Named;
-
-import org.jboss.weld.extensions.annotated.Annotateds;
-
-/**
- * class that can build a bean from an AnnotatedType.
- * 
- * @author stuart
- * 
- */
-public class CustomBeanBuilder<T>
-{
-
-   final AnnotatedType<T> type;
-   final BeanManager beanManager;
-   InjectionTarget<T> injectionTarget;
-   String name;
-   Set<Annotation> qualifiers;
-   Class<? extends Annotation> scope;
-   Set<Class<? extends Annotation>> stereotypes;
-   Set<Type> types = new HashSet<Type>();
-   boolean alternative = false;
-   boolean nullable = false;
-   BeanLifecycle<T> beanLifecycle;
-   boolean passivationCapable;
-   String id;
-
-   public CustomBeanBuilder(AnnotatedType<T> type, BeanManager beanManager)
-   {
-      this(type, beanManager, beanManager.createInjectionTarget(type));
-   }
-
-   public CustomBeanBuilder(AnnotatedType<T> type, BeanManager beanManager, InjectionTarget<T> injectionTarget)
-   {
-      this.type = type;
-      this.beanManager = beanManager;
-      this.injectionTarget = injectionTarget;
-      qualifiers = new HashSet<Annotation>();
-      stereotypes = new HashSet<Class<? extends Annotation>>();
-      for (Annotation a : type.getAnnotations())
-      {
-         if (beanManager.isQualifier(a.annotationType()))
-         {
-            qualifiers.add(a);
-         }
-         else if (beanManager.isScope(a.annotationType()))
-         {
-            scope = a.annotationType();
-         }
-         else if (beanManager.isStereotype(a.annotationType()))
-         {
-            stereotypes.add(a.annotationType());
-         }
-         if (a instanceof Named)
-         {
-            Named n = (Named) a;
-            name = n.value();
-         }
-         if (a instanceof Alternative)
-         {
-            alternative = true;
-         }
-      }
-      if (scope == null)
-      {
-         scope = Dependent.class;
-      }
-
-      Class<?> c = type.getJavaClass();
-      do
-      {
-         types.add(c);
-         c = c.getSuperclass();
-      }
-      while (c != null);
-      for (Class<?> i : type.getJavaClass().getInterfaces())
-      {
-         types.add(i);
-      }
-      beanLifecycle = new SimpleBeanLifecycle<T>(type.getJavaClass(), beanManager);
-      id = CustomBean.class.getName() + ":" + Annotateds.createTypeId(type);
-   }
-
-   public Bean<T> build()
-   {
-      if (!passivationCapable)
-      {
-         return new CustomBean<T>(type.getJavaClass(), injectionTarget, name, qualifiers, scope, stereotypes, types, alternative, nullable, beanLifecycle);
-      }
-      return new PassivationCapableCustomBean<T>(id, type.getJavaClass(), injectionTarget, name, qualifiers, scope, stereotypes, types, alternative, nullable, beanLifecycle);
-
-   }
-
-   public InjectionTarget<T> getInjectionTarget()
-   {
-      return injectionTarget;
-   }
-
-   public void setInjectionTarget(InjectionTarget<T> injectionTarget)
-   {
-      this.injectionTarget = injectionTarget;
-   }
-   public Set<Annotation> getQualifiers()
-   {
-      return qualifiers;
-   }
-
-   public void setQualifiers(Set<Annotation> qualifiers)
-   {
-      this.qualifiers = qualifiers;
-   }
-
-   public Class<? extends Annotation> getScope()
-   {
-      return scope;
-   }
-
-   public void setScope(Class<? extends Annotation> scope)
-   {
-      this.scope = scope;
-   }
-
-   public Set<Class<? extends Annotation>> getStereotypes()
-   {
-      return stereotypes;
-   }
-
-   public void setStereotypes(Set<Class<? extends Annotation>> stereotypes)
-   {
-      this.stereotypes = stereotypes;
-   }
-
-   public Set<Type> getTypes()
-   {
-      return types;
-   }
-
-   public void setTypes(Set<Type> types)
-   {
-      this.types = types;
-   }
-
-   public boolean isAlternative()
-   {
-      return alternative;
-   }
-
-   public void setAlternative(boolean alternative)
-   {
-      this.alternative = alternative;
-   }
-
-   public boolean isNullable()
-   {
-      return nullable;
-   }
-
-   public void setNullable(boolean nullable)
-   {
-      this.nullable = nullable;
-   }
-
-   public BeanLifecycle<T> getBeanLifecycle()
-   {
-      return beanLifecycle;
-   }
-
-   public void setBeanLifecycle(BeanLifecycle<T> beanLifecycle)
-   {
-      this.beanLifecycle = beanLifecycle;
-   }
-
-   public AnnotatedType<T> getType()
-   {
-      return type;
-   }
-
-   public BeanManager getBeanManager()
-   {
-      return beanManager;
-   }
-
-   public String getName()
-   {
-      return name;
-   }
-
-   public void setName(String name)
-   {
-      this.name = name;
-   }
-
-   public boolean isPassivationCapable()
-   {
-      return passivationCapable;
-   }
-
-   public void setPassivationCapable(boolean passivationCapable)
-   {
-      this.passivationCapable = passivationCapable;
-   }
-
-   public String getId()
-   {
-      return id;
-   }
-
-   public void setId(String id)
-   {
-      this.id = id;
-   }
-
-}

Deleted: extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/CustomInjectionPoint.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/CustomInjectionPoint.java	2010-04-29 21:51:53 UTC (rev 6202)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/CustomInjectionPoint.java	2010-04-29 22:13:29 UTC (rev 6203)
@@ -1,148 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat, Inc., and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * http://www.apache.org/licenses/LICENSE-2.0
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,  
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.jboss.weld.extensions.bean;
-
-import java.lang.annotation.Annotation;
-import java.lang.reflect.Member;
-import java.lang.reflect.Type;
-import java.util.HashSet;
-import java.util.Set;
-
-import javax.enterprise.inject.spi.Annotated;
-import javax.enterprise.inject.spi.AnnotatedField;
-import javax.enterprise.inject.spi.AnnotatedParameter;
-import javax.enterprise.inject.spi.Bean;
-import javax.enterprise.inject.spi.BeanManager;
-import javax.enterprise.inject.spi.InjectionPoint;
-
-/**
- * implementation of InjectionPoint that can be used by other extensions
- * 
- * @author stuart
- * 
- */
-public class CustomInjectionPoint implements InjectionPoint
-{
-
-   public CustomInjectionPoint(AnnotatedField<?> field, Set<Annotation> qualifiers, Bean<?> bean, boolean trans, boolean delegate)
-   {
-      this.annotated = field;
-      this.member = field.getJavaMember();
-      this.qualifiers = new HashSet<Annotation>(qualifiers);
-      this.type = field.getJavaMember().getGenericType();
-      this.trans = trans;
-      this.delegate = delegate;
-      this.bean = bean;
-   }
-
-   public CustomInjectionPoint(AnnotatedField<?> field, BeanManager beanManager, Bean<?> bean, boolean trans, boolean delegate)
-   {
-      this.annotated = field;
-      this.member = field.getJavaMember();
-      this.qualifiers = new HashSet<Annotation>();
-      this.type = field.getJavaMember().getGenericType();
-      this.trans = trans;
-      this.delegate = delegate;
-      this.bean = bean;
-      for (Annotation a : field.getAnnotations())
-      {
-         if (beanManager.isQualifier(a.annotationType()))
-         {
-            qualifiers.add(a);
-         }
-      }
-   }
-
-   public CustomInjectionPoint(AnnotatedParameter<?> param, Set<Annotation> qualifiers, Bean<?> bean, boolean trans, boolean delegate)
-   {
-      this.annotated = param;
-      this.member = param.getDeclaringCallable().getJavaMember();
-      this.qualifiers = new HashSet<Annotation>(qualifiers);
-      this.trans = trans;
-      this.delegate = delegate;
-      this.bean = bean;
-      this.type = param.getBaseType();
-   }
-
-   public CustomInjectionPoint(AnnotatedParameter<?> param, BeanManager beanManager, Bean<?> bean, boolean trans, boolean delegate)
-   {
-      this.annotated = param;
-      this.member = param.getDeclaringCallable().getJavaMember();
-      this.qualifiers = new HashSet<Annotation>();
-      this.trans = trans;
-      this.delegate = delegate;
-      this.bean = bean;
-      this.type = param.getBaseType();
-      for (Annotation a : annotated.getAnnotations())
-      {
-         if (beanManager.isQualifier(a.annotationType()))
-         {
-            qualifiers.add(a);
-         }
-      }
-   }
-
-   private final Annotated annotated;
-
-   private final Member member;
-
-   private final Bean<?> bean;
-
-   private final Set<Annotation> qualifiers;
-
-   private final Type type;
-
-   private final boolean trans;
-
-   private final boolean delegate;
-
-   public Annotated getAnnotated()
-   {
-      return annotated;
-   }
-
-   public Bean<?> getBean()
-   {
-      return bean;
-   }
-
-   public Member getMember()
-   {
-      return member;
-   }
-
-   public Set<Annotation> getQualifiers()
-   {
-      return qualifiers;
-   }
-
-   public Type getType()
-   {
-      return type;
-   }
-
-   public boolean isDelegate()
-   {
-      return delegate;
-   }
-
-   public boolean isTransient()
-   {
-      return trans;
-   }
-
-}

Copied: extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/InjectionPointImpl.java (from rev 6200, extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/CustomInjectionPoint.java)
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/InjectionPointImpl.java	                        (rev 0)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/InjectionPointImpl.java	2010-04-29 22:13:29 UTC (rev 6203)
@@ -0,0 +1,148 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,  
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jboss.weld.extensions.bean;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Member;
+import java.lang.reflect.Type;
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.enterprise.inject.spi.Annotated;
+import javax.enterprise.inject.spi.AnnotatedField;
+import javax.enterprise.inject.spi.AnnotatedParameter;
+import javax.enterprise.inject.spi.Bean;
+import javax.enterprise.inject.spi.BeanManager;
+import javax.enterprise.inject.spi.InjectionPoint;
+
+/**
+ * A simple implementation of InjectionPoint
+ * 
+ * @author stuart
+ * 
+ */
+public class InjectionPointImpl implements InjectionPoint
+{
+
+   public InjectionPointImpl(AnnotatedField<?> field, Set<Annotation> qualifiers, Bean<?> bean, boolean trans, boolean delegate)
+   {
+      this.annotated = field;
+      this.member = field.getJavaMember();
+      this.qualifiers = new HashSet<Annotation>(qualifiers);
+      this.type = field.getJavaMember().getGenericType();
+      this.trans = trans;
+      this.delegate = delegate;
+      this.bean = bean;
+   }
+
+   public InjectionPointImpl(AnnotatedField<?> field, BeanManager beanManager, Bean<?> bean, boolean trans, boolean delegate)
+   {
+      this.annotated = field;
+      this.member = field.getJavaMember();
+      this.qualifiers = new HashSet<Annotation>();
+      this.type = field.getJavaMember().getGenericType();
+      this.trans = trans;
+      this.delegate = delegate;
+      this.bean = bean;
+      for (Annotation a : field.getAnnotations())
+      {
+         if (beanManager.isQualifier(a.annotationType()))
+         {
+            qualifiers.add(a);
+         }
+      }
+   }
+
+   public InjectionPointImpl(AnnotatedParameter<?> param, Set<Annotation> qualifiers, Bean<?> bean, boolean trans, boolean delegate)
+   {
+      this.annotated = param;
+      this.member = param.getDeclaringCallable().getJavaMember();
+      this.qualifiers = new HashSet<Annotation>(qualifiers);
+      this.trans = trans;
+      this.delegate = delegate;
+      this.bean = bean;
+      this.type = param.getBaseType();
+   }
+
+   public InjectionPointImpl(AnnotatedParameter<?> param, BeanManager beanManager, Bean<?> bean, boolean trans, boolean delegate)
+   {
+      this.annotated = param;
+      this.member = param.getDeclaringCallable().getJavaMember();
+      this.qualifiers = new HashSet<Annotation>();
+      this.trans = trans;
+      this.delegate = delegate;
+      this.bean = bean;
+      this.type = param.getBaseType();
+      for (Annotation a : annotated.getAnnotations())
+      {
+         if (beanManager.isQualifier(a.annotationType()))
+         {
+            qualifiers.add(a);
+         }
+      }
+   }
+
+   private final Annotated annotated;
+
+   private final Member member;
+
+   private final Bean<?> bean;
+
+   private final Set<Annotation> qualifiers;
+
+   private final Type type;
+
+   private final boolean trans;
+
+   private final boolean delegate;
+
+   public Annotated getAnnotated()
+   {
+      return annotated;
+   }
+
+   public Bean<?> getBean()
+   {
+      return bean;
+   }
+
+   public Member getMember()
+   {
+      return member;
+   }
+
+   public Set<Annotation> getQualifiers()
+   {
+      return qualifiers;
+   }
+
+   public Type getType()
+   {
+      return type;
+   }
+
+   public boolean isDelegate()
+   {
+      return delegate;
+   }
+
+   public boolean isTransient()
+   {
+      return trans;
+   }
+
+}

Copied: extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/PassivationCapableBeanImpl.java (from rev 6200, extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/PassivationCapableCustomBean.java)
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/PassivationCapableBeanImpl.java	                        (rev 0)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/PassivationCapableBeanImpl.java	2010-04-29 22:13:29 UTC (rev 6203)
@@ -0,0 +1,41 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,  
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jboss.weld.extensions.bean;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+import java.util.Set;
+
+import javax.enterprise.inject.spi.InjectionTarget;
+import javax.enterprise.inject.spi.PassivationCapable;
+
+public class PassivationCapableBeanImpl<T> extends BeanImpl<T> implements PassivationCapable
+{
+   private final String id;
+
+   PassivationCapableBeanImpl(String id, Class<?> beanClass, InjectionTarget<T> injectionTarget, String name, Set<Annotation> qualifiers, Class<? extends Annotation> scope, Set<Class<? extends Annotation>> stereotypes, Set<Type> types, boolean alternative, boolean nullable, BeanLifecycle<T> beanLifecycle)
+   {
+      super(beanClass, injectionTarget, name, qualifiers, scope, stereotypes, types, alternative, nullable, beanLifecycle);
+      this.id = id;
+   }
+
+   public String getId()
+   {
+      return id;
+   }
+
+}

Deleted: extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/PassivationCapableCustomBean.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/PassivationCapableCustomBean.java	2010-04-29 21:51:53 UTC (rev 6202)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/PassivationCapableCustomBean.java	2010-04-29 22:13:29 UTC (rev 6203)
@@ -1,41 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat, Inc., and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * http://www.apache.org/licenses/LICENSE-2.0
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,  
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.jboss.weld.extensions.bean;
-
-import java.lang.annotation.Annotation;
-import java.lang.reflect.Type;
-import java.util.Set;
-
-import javax.enterprise.inject.spi.InjectionTarget;
-import javax.enterprise.inject.spi.PassivationCapable;
-
-public class PassivationCapableCustomBean<T> extends CustomBean<T> implements PassivationCapable
-{
-   final String id;
-
-   PassivationCapableCustomBean(String id, Class<?> beanClass, InjectionTarget<T> injectionTarget, String name, Set<Annotation> qualifiers, Class<? extends Annotation> scope, Set<Class<? extends Annotation>> stereotypes, Set<Type> types, boolean alternative, boolean nullable, BeanLifecycle<T> beanLifecycle)
-   {
-      super(beanClass, injectionTarget, name, qualifiers, scope, stereotypes, types, alternative, nullable, beanLifecycle);
-      this.id = id;
-   }
-
-   public String getId()
-   {
-      return id;
-   }
-
-}

Deleted: extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/SimpleBeanLifecycle.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/SimpleBeanLifecycle.java	2010-04-29 21:51:53 UTC (rev 6202)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/SimpleBeanLifecycle.java	2010-04-29 22:13:29 UTC (rev 6203)
@@ -1,54 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat, Inc., and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * http://www.apache.org/licenses/LICENSE-2.0
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,  
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.jboss.weld.extensions.bean;
-
-import javax.enterprise.context.spi.CreationalContext;
-import javax.enterprise.inject.spi.BeanManager;
-
-public class SimpleBeanLifecycle<T> implements BeanLifecycle<T>
-{
-   final Class<T> type;
-   final BeanManager beanManager;
-
-   public SimpleBeanLifecycle(Class<T> type, BeanManager beanManager)
-   {
-      this.type = type;
-      this.beanManager = beanManager;
-   }
-
-   public T create(CustomBean<T> bean, CreationalContext<T> creationalContext)
-   {
-      T instance = bean.getInjectionTarget().produce(creationalContext);
-      bean.getInjectionTarget().inject(instance, creationalContext);
-      bean.getInjectionTarget().postConstruct(instance);
-      return instance;
-   }
-
-   public void destroy(CustomBean<T> bean, T instance, CreationalContext<T> creationalContext)
-   {
-      try
-      {
-         bean.getInjectionTarget().preDestroy(instance);
-         creationalContext.release();
-      }
-      catch (Exception e)
-      {
-         throw new RuntimeException(e);
-      }
-   }
-
-}

Modified: extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/generic/GenericExtension.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/generic/GenericExtension.java	2010-04-29 21:51:53 UTC (rev 6202)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/bean/generic/GenericExtension.java	2010-04-29 22:13:29 UTC (rev 6203)
@@ -44,7 +44,7 @@
 import javax.inject.Inject;
 
 import org.jboss.weld.extensions.annotated.AnnotatedTypeBuilder;
-import org.jboss.weld.extensions.bean.CustomBeanBuilder;
+import org.jboss.weld.extensions.bean.BeanBuilder;
 import org.jboss.weld.extensions.util.AnnotationInstanceProvider;
 
 public class GenericExtension implements Extension
@@ -245,8 +245,8 @@
       InjectionTarget<X> it = beanManager.createInjectionTarget(newAnnotatedType);
 
       it = new GenericBeanInjectionTargetWrapper<X>(newAnnotatedType, it, conc);
-      CustomBeanBuilder<X> beanBuilder = new CustomBeanBuilder<X>(newAnnotatedType, beanManager, it);
-      return beanBuilder.build();
+      BeanBuilder<X> beanBuilder = new BeanBuilder<X>(newAnnotatedType, beanManager).defineBeanFromAnnotatedType().setInjectionTarget(it);
+      return beanBuilder.create();
    }
 
    public SyntheticQualifier getQualifierForGeneric(Annotation a)

Modified: extensions/trunk/src/main/java/org/jboss/weld/extensions/core/CoreExtension.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/core/CoreExtension.java	2010-04-29 21:51:53 UTC (rev 6202)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/core/CoreExtension.java	2010-04-29 22:13:29 UTC (rev 6203)
@@ -43,7 +43,7 @@
 import org.jboss.weld.extensions.annotated.MemberAnnotationRedefiner;
 import org.jboss.weld.extensions.annotated.Parameter;
 import org.jboss.weld.extensions.annotated.ParameterAnnotationRedefiner;
-import org.jboss.weld.extensions.bean.CustomBeanBuilder;
+import org.jboss.weld.extensions.bean.BeanBuilder;
 import org.jboss.weld.extensions.core.Exact.ExactLiteral;
 
 /**
@@ -173,7 +173,7 @@
                annotatedTypeBuilder.addToClass(ann);
             }
             AnnotatedType<X> construtsAnnotatedType = builder.create();
-            additionalBeans.add(new CustomBeanBuilder<X>(construtsAnnotatedType, beanManager).build());
+            additionalBeans.add(new BeanBuilder<X>(construtsAnnotatedType, beanManager).create());
          }
       }
    }



More information about the weld-commits mailing list