[webbeans-commits] Webbeans SVN: r3722 - in ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean: builder and 1 other directory.

webbeans-commits at lists.jboss.org webbeans-commits at lists.jboss.org
Tue Sep 22 09:46:49 EDT 2009


Author: kabir.khan at jboss.com
Date: 2009-09-22 09:46:48 -0400 (Tue, 22 Sep 2009)
New Revision: 3722

Modified:
   ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/AbstractClassBean.java
   ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/DisposalMethod.java
   ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/ManagedBean.java
   ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/NewSessionBean.java
   ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/ProducerMethod.java
   ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/SessionBean.java
   ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/builder/ProducerFieldBuilder.java
Log:
Get rid of duplicate code in Beans/Builders

Modified: ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/AbstractClassBean.java
===================================================================
--- ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/AbstractClassBean.java	2009-09-22 13:26:47 UTC (rev 3721)
+++ ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/AbstractClassBean.java	2009-09-22 13:46:48 UTC (rev 3722)
@@ -118,16 +118,9 @@
       this.injectableFields = initInjectableFields();
       this.initializerMethods = initInitializerMethods();
 
-      checkBeanImplementation();
       this.decorators = decorators;
-      checkType();
    }
    
-   protected void checkType()
-   {
-      
-   }
-   
    public boolean hasDecorators()
    {
       return this.decorators != null && this.decorators.size() > 0;
@@ -220,11 +213,6 @@
    }
 
    /**
-    * Validates the bean implementation
-    */
-   protected void checkBeanImplementation() {}
-
-   /**
     * Gets the annotated item
     * 
     * @return The annotated item

Modified: ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/DisposalMethod.java
===================================================================
--- ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/DisposalMethod.java	2009-09-22 13:26:47 UTC (rev 3721)
+++ ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/DisposalMethod.java	2009-09-22 13:46:48 UTC (rev 3722)
@@ -22,13 +22,9 @@
 import java.util.Set;
 
 import javax.enterprise.context.spi.CreationalContext;
-import javax.enterprise.event.Observes;
 import javax.enterprise.inject.Disposes;
-import javax.enterprise.inject.Produces;
-import javax.inject.Inject;
 
 import org.jboss.webbeans.BeanManagerImpl;
-import org.jboss.webbeans.DefinitionException;
 import org.jboss.webbeans.injection.MethodInjectionPoint;
 import org.jboss.webbeans.introspector.WBMethod;
 import org.jboss.webbeans.metadata.cache.MergedStereotypes;
@@ -60,7 +56,6 @@
       this.disposalMethodInjectionPoint = MethodInjectionPoint.of(this, disposalMethod);
       this.id = createId("DisposalMethod-" + declaringBean.getName() + "-" + disposalMethod.getSignature().toString());
       addInjectionPoint(disposalMethodInjectionPoint);
-      checkDisposalMethod();
    }
    
    @Override
@@ -118,55 +113,6 @@
       creationalContext.release();
    }
 
-   private void checkDisposalMethod()
-   {
-      if (!disposalMethodInjectionPoint.getWBParameters().get(0).isAnnotationPresent(Disposes.class))
-      {
-         throw new DefinitionException(disposalMethodInjectionPoint.toString() + " doesn't have @Dispose as first parameter");
-      }
-      if (disposalMethodInjectionPoint.getAnnotatedParameters(Disposes.class).size() > 1)
-      {
-         throw new DefinitionException(disposalMethodInjectionPoint.toString() + " has more than one @Dispose parameters");
-      }
-      if (disposalMethodInjectionPoint.getAnnotatedParameters(Observes.class).size() > 0)
-      {
-         throw new DefinitionException("@Observes is not allowed on disposal method, see " + disposalMethodInjectionPoint.toString());
-      }
-      if (disposalMethodInjectionPoint.getAnnotation(Inject.class) != null)
-      {
-         throw new DefinitionException("@Intitializer is not allowed on a disposal method, see " + disposalMethodInjectionPoint.toString());
-      }
-      if (disposalMethodInjectionPoint.getAnnotation(Produces.class) != null)
-      {
-         throw new DefinitionException("@Produces is not allowed on a disposal method, see " + disposalMethodInjectionPoint.toString());
-      }
-      if (getDeclaringBean() instanceof SessionBean<?>)
-      {
-         boolean methodDeclaredOnTypes = false;
-         // TODO use annotated item?
-         for (Type type : getDeclaringBean().getTypes())
-         {
-            if (type instanceof Class<?>)
-            {
-               Class<?> clazz = (Class<?>) type;
-               try
-               {
-                  clazz.getDeclaredMethod(disposalMethodInjectionPoint.getName(), disposalMethodInjectionPoint.getParameterTypesAsArray());
-                  methodDeclaredOnTypes = true;
-               }
-               catch (NoSuchMethodException nsme)
-               {
-                  // No - op
-               }
-            }
-         }
-         if (!methodDeclaredOnTypes)
-         {
-            throw new DefinitionException("Producer method " + toString() + " must be declared on a business interface of " + getDeclaringBean());
-         }
-      }
-   }
-
    @Override
    protected String getDefaultName()
    {

Modified: ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/ManagedBean.java
===================================================================
--- ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/ManagedBean.java	2009-09-22 13:26:47 UTC (rev 3721)
+++ ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/ManagedBean.java	2009-09-22 13:46:48 UTC (rev 3722)
@@ -33,12 +33,10 @@
 import org.jboss.webbeans.injection.WBInjectionPoint;
 import org.jboss.webbeans.introspector.WBClass;
 import org.jboss.webbeans.introspector.WBConstructor;
-import org.jboss.webbeans.introspector.WBField;
 import org.jboss.webbeans.introspector.WBMethod;
 import org.jboss.webbeans.log.LogProvider;
 import org.jboss.webbeans.log.Logging;
 import org.jboss.webbeans.metadata.cache.MergedStereotypes;
-import org.jboss.webbeans.metadata.cache.MetaAnnotationStore;
 import org.jboss.webbeans.util.Beans;
 import org.jboss.webbeans.util.Names;
 import org.jboss.webbeans.util.Reflections;
@@ -212,68 +210,6 @@
       }
    }
 
-   /**
-    * Validates the type
-    */
-   protected void checkType()
-   {
-      if (getAnnotatedItem().isNonStaticMemberClass())
-      {
-         throw new DefinitionException("Simple bean " + type + " cannot be a non-static inner class");
-      }
-      if (!isDependent() && getAnnotatedItem().isParameterizedType())
-      {
-         throw new DefinitionException("Managed bean " + type + " must be @Dependent");
-      }
-      boolean passivating = getManager().getServices().get(MetaAnnotationStore.class).getScopeModel(scopeType).isPassivating();
-      if (passivating && !Reflections.isSerializable(getBeanClass()))
-      {
-         throw new DefinitionException("Simple bean declaring a passivating scope must have a serializable implementation class " + toString());
-      }
-      if (hasDecorators())
-      {
-         if (getAnnotatedItem().isFinal())
-         {
-            throw new DefinitionException("Bean class which has decorators cannot be declared final " + this);
-         }
-         for (Decorator<?> decorator : getDecorators())
-         {
-            if (decorator instanceof DecoratorImpl<?>)
-            {
-               DecoratorImpl<?> decoratorBean = (DecoratorImpl<?>) decorator;
-               for (WBMethod<?, ?> decoratorMethod : decoratorBean.getAnnotatedItem().getWBMethods())
-               {
-                  WBMethod<?, ?> method = getAnnotatedItem().getWBMethod(decoratorMethod.getSignature());  
-                  if (method != null && !method.isStatic() && !method.isPrivate() && method.isFinal())
-                  {
-                     throw new DefinitionException("Decorated bean method " + method + " (decorated by "+ decoratorMethod + ") cannot be declarted final");
-                  }
-               }
-            }
-            else
-            {
-               throw new IllegalStateException("Can only operate on container provided decorators " + decorator);
-            }
-         }
-      }
-   }
-
-   @Override
-   protected void checkBeanImplementation()
-   {
-      super.checkBeanImplementation();
-      if (!isDependent())
-      {
-         for (WBField<?, ?> field : getAnnotatedItem().getWBFields())
-         {
-            if (field.isPublic() && !field.isStatic())
-            {
-               throw new DefinitionException("Normal scoped Web Bean implementation class has a public field " + getAnnotatedItem());
-            }
-         }
-      }
-   }
-   
    protected void checkConstructor()
    {
       if (!constructor.getAnnotatedWBParameters(Disposes.class).isEmpty())

Modified: ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/NewSessionBean.java
===================================================================
--- ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/NewSessionBean.java	2009-09-22 13:26:47 UTC (rev 3721)
+++ ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/NewSessionBean.java	2009-09-22 13:46:48 UTC (rev 3722)
@@ -100,12 +100,5 @@
    public boolean isSpecializing()
    {
       return false;
-   }
-   
-   @Override
-   protected void checkScopeAllowed()
-   {
-      // No-op
-   }
-
+   }   
 }

Modified: ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/ProducerMethod.java
===================================================================
--- ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/ProducerMethod.java	2009-09-22 13:26:47 UTC (rev 3721)
+++ ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/ProducerMethod.java	2009-09-22 13:46:48 UTC (rev 3722)
@@ -23,12 +23,9 @@
 import java.util.Set;
 
 import javax.enterprise.context.spi.CreationalContext;
-import javax.enterprise.event.Observes;
 import javax.enterprise.inject.CreationException;
-import javax.enterprise.inject.Disposes;
 
 import org.jboss.webbeans.BeanManagerImpl;
-import org.jboss.webbeans.DefinitionException;
 import org.jboss.webbeans.injection.MethodInjectionPoint;
 import org.jboss.webbeans.injection.ParameterInjectionPoint;
 import org.jboss.webbeans.introspector.WBMethod;
@@ -99,7 +96,6 @@
       this.specializedBean = specializedBean;
       this.id = createId("ProducerMethod-" + declaringBean.getType().getName() + "-" + method.getSignature().toString());
       initProducerMethodInjectableParameters();
-      checkProducerMethod();
    }
 
    public T produce(CreationalContext<T> creationalContext)
@@ -126,46 +122,6 @@
       }
    }
 
-   /**
-    * Validates the producer method
-    */
-   protected void checkProducerMethod()
-   {
-      if (getAnnotatedItem().getAnnotatedWBParameters(Observes.class).size() > 0)
-      {
-         throw new DefinitionException("Producer method cannot have parameter annotated @Observes");
-      }
-      else if (getAnnotatedItem().getAnnotatedWBParameters(Disposes.class).size() > 0)
-      {
-         throw new DefinitionException("Producer method cannot have parameter annotated @Disposes");
-      }
-      else if (getDeclaringBean() instanceof SessionBean<?>)
-      {
-         boolean methodDeclaredOnTypes = false;
-         // TODO use annotated item?
-         for (Type type : getDeclaringBean().getTypes())
-         {
-            if (type instanceof Class)
-            {
-               Class<?> clazz = (Class<?>) type;
-               try
-               {
-                  clazz.getDeclaredMethod(getAnnotatedItem().getName(), getAnnotatedItem().getParameterTypesAsArray());
-                  methodDeclaredOnTypes = true;
-               }
-               catch (NoSuchMethodException nsme)
-               {
-                  // No - op
-               }
-            }
-         }
-         if (!methodDeclaredOnTypes)
-         {
-            throw new DefinitionException("Producer method " + toString() + " must be declared on a business interface of " + getDeclaringBean());
-         }
-      }
-   }
-
    public void destroy(T instance, CreationalContext<T> creationalContext)
    {
       try

Modified: ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/SessionBean.java
===================================================================
--- ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/SessionBean.java	2009-09-22 13:26:47 UTC (rev 3721)
+++ ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/SessionBean.java	2009-09-22 13:46:48 UTC (rev 3722)
@@ -26,15 +26,10 @@
 
 import javassist.util.proxy.ProxyObject;
 
-import javax.decorator.Decorator;
-import javax.enterprise.context.ApplicationScoped;
 import javax.enterprise.context.spi.CreationalContext;
-import javax.enterprise.event.Observes;
 import javax.enterprise.inject.CreationException;
-import javax.interceptor.Interceptor;
 
 import org.jboss.webbeans.BeanManagerImpl;
-import org.jboss.webbeans.DefinitionException;
 import org.jboss.webbeans.bean.proxy.EnterpriseBeanInstance;
 import org.jboss.webbeans.bean.proxy.EnterpriseBeanProxyMethodHandler;
 import org.jboss.webbeans.bean.proxy.Marker;
@@ -128,46 +123,10 @@
       this.ejbDescriptor = ejbDescriptor;
       this.proxyClass = proxyClass;
       this.specializedBean = specializedBean;
-
-      checkEJBTypeAllowed();
-      checkConflictingRoles();
-      checkObserverMethods();
-      checkScopeAllowed();
    }
 
 
    /**
-    * Validates for non-conflicting roles
-    */
-   protected void checkConflictingRoles()
-   {
-      if (getType().isAnnotationPresent(Interceptor.class))
-      {
-         throw new DefinitionException("Enterprise beans cannot be interceptors");
-      }
-      if (getType().isAnnotationPresent(Decorator.class))
-      {
-         throw new DefinitionException("Enterprise beans cannot be decorators");
-      }
-   }
-
-   /**
-    * Check that the scope type is allowed by the stereotypes on the bean and
-    * the bean type
-    */
-   protected void checkScopeAllowed()
-   {
-      if (ejbDescriptor.isStateless() && !isDependent())
-      {
-         throw new DefinitionException("Scope " + getScope() + " is not allowed on stateless enterpise beans for " + getType() + ". Only @Dependent is allowed on stateless enterprise beans");
-      }
-      if (ejbDescriptor.isSingleton() && !(isDependent() || getScope().equals(ApplicationScoped.class)))
-      {
-         throw new DefinitionException("Scope " + getScope() + " is not allowed on singleton enterpise beans for " + getType() + ". Only @Dependent or @ApplicationScoped is allowed on singleton enterprise beans");
-      }
-   }
-
-   /**
     * Creates an instance of the bean
     * 
     * @return The instance
@@ -237,17 +196,6 @@
    }
 
    /**
-    * Validates the bean type
-    */
-   private void checkEJBTypeAllowed()
-   {
-      if (ejbDescriptor.isMessageDriven())
-      {
-         throw new DefinitionException("Message Driven Beans can't be Web Beans");
-      }
-   }
-
-   /**
     * Gets a string representation
     * 
     * @return The string representation
@@ -304,24 +252,6 @@
       return specializedBean;
    }
 
-   /**
-    * If there are any observer methods, they must be static or business
-    * methods.
-    */
-   protected void checkObserverMethods()
-   {
-      for (WBMethod<?, ?> method : super.getAnnotatedItem().getWBDeclaredMethodsWithAnnotatedParameters(Observes.class))
-      {
-         if (!method.isStatic())
-         {
-            if (!isMethodExistsOnTypes(method))
-            {
-               throw new DefinitionException("Observer method must be static or business method: " + method + " on " + getAnnotatedItem());
-            }
-         }
-      }
-   }
-   
    // TODO must be a nicer way to do this!
    public boolean isMethodExistsOnTypes(WBMethod<?, ?> method)
    {

Modified: ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/builder/ProducerFieldBuilder.java
===================================================================
--- ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/builder/ProducerFieldBuilder.java	2009-09-22 13:26:47 UTC (rev 3721)
+++ ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/bean/builder/ProducerFieldBuilder.java	2009-09-22 13:46:48 UTC (rev 3722)
@@ -213,11 +213,6 @@
       return bean;
    }
    
-   private Set<Class<? extends Annotation>> createEmptyStereotypes()
-   {
-      return Collections.emptySet();
-   } 
-
    protected boolean isPersistenceContextProducerField(WBField<?, ?> field)
    {
       PersistenceApiAbstraction persistenceApiAbstraction = getManager().getServices().get(PersistenceApiAbstraction.class);




More information about the weld-commits mailing list