Home » apache-openwebbeans-1.0.0-incubating-M3-sources » org.apache.webbeans.util » [javadoc | source]

    1   /*
    2    * Licensed to the Apache Software Foundation (ASF) under one or more
    3    * contributor license agreements. See the NOTICE file distributed with this
    4    * work for additional information regarding copyright ownership. The ASF
    5    * licenses this file to You under the Apache License, Version 2.0 (the
    6    * "License"); you may not use this file except in compliance with the License.
    7    * You may obtain a copy of the License at
    8    * http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law
    9    * or agreed to in writing, software distributed under the License is
   10    * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
   11    * KIND, either express or implied. See the License for the specific language
   12    * governing permissions and limitations under the License.
   13    */
   14   package org.apache.webbeans.util;
   15   
   16   import java.lang.annotation.Annotation;
   17   import java.lang.annotation.ElementType;
   18   import java.lang.annotation.Target;
   19   import java.lang.reflect.Constructor;
   20   import java.lang.reflect.Field;
   21   import java.lang.reflect.Member;
   22   import java.lang.reflect.Method;
   23   import java.lang.reflect.ParameterizedType;
   24   import java.lang.reflect.Type;
   25   import java.lang.reflect.TypeVariable;
   26   import java.security.AccessController;
   27   import java.security.PrivilegedAction;
   28   import java.util.ArrayList;
   29   import java.util.Arrays;
   30   import java.util.Collections;
   31   import java.util.HashSet;
   32   import java.util.Iterator;
   33   import java.util.List;
   34   import java.util.Map;
   35   import java.util.Set;
   36   
   37   import javax.annotation.PostConstruct;
   38   import javax.annotation.PreDestroy;
   39   import javax.decorator.Decorator;
   40   import javax.enterprise.context.ApplicationScoped;
   41   import javax.enterprise.context.Conversation;
   42   import javax.enterprise.context.ConversationScoped;
   43   import javax.enterprise.context.Dependent;
   44   import javax.enterprise.context.RequestScoped;
   45   import javax.enterprise.context.NormalScope;
   46   import javax.enterprise.context.SessionScoped;
   47   import javax.enterprise.event.Observes;
   48   import javax.enterprise.inject.Disposes;
   49   import javax.enterprise.inject.IllegalProductException;
   50   import javax.enterprise.inject.Instance;
   51   import javax.inject.Named;
   52   import javax.inject.Scope;
   53   import javax.enterprise.inject.New;
   54   import javax.enterprise.inject.Produces;
   55   import javax.enterprise.inject.UnproxyableResolutionException;
   56   import javax.enterprise.inject.deployment.DeploymentType;
   57   import javax.enterprise.inject.deployment.Specializes;
   58   import javax.enterprise.inject.spi.AnnotatedField;
   59   import javax.enterprise.inject.spi.AnnotatedMethod;
   60   import javax.enterprise.inject.spi.AnnotatedType;
   61   import javax.enterprise.inject.spi.Bean;
   62   import javax.enterprise.inject.spi.InjectionPoint;
   63   import javax.enterprise.inject.spi.Interceptor;
   64   import javax.enterprise.inject.spi.BeanManager;
   65   import javax.enterprise.inject.stereotype.Stereotype;
   66   import javax.inject.Inject;
   67   import javax.interceptor.AroundInvoke;
   68   import javax.interceptor.InvocationContext;
   69   
   70   import org.apache.webbeans.annotation.ApplicationScopeLiteral;
   71   import org.apache.webbeans.annotation.CurrentLiteral;
   72   import org.apache.webbeans.annotation.DependentScopeLiteral;
   73   import org.apache.webbeans.annotation.NewLiteral;
   74   import org.apache.webbeans.annotation.ProductionLiteral;
   75   import org.apache.webbeans.annotation.RequestedScopeLiteral;
   76   import org.apache.webbeans.annotation.StandardLiteral;
   77   import org.apache.webbeans.component.AbstractBean;
   78   import org.apache.webbeans.component.AbstractInjectionTargetBean;
   79   import org.apache.webbeans.component.BaseBean;
   80   import org.apache.webbeans.component.EnterpriseBeanMarker;
   81   import org.apache.webbeans.component.ManagedBean;
   82   import org.apache.webbeans.component.ConversationBean;
   83   import org.apache.webbeans.component.ExtensionBean;
   84   import org.apache.webbeans.component.InjectionPointBean;
   85   import org.apache.webbeans.component.InstanceBean;
   86   import org.apache.webbeans.component.BeanManagerBean;
   87   import org.apache.webbeans.component.NewBean;
   88   import org.apache.webbeans.component.EventBean;
   89   import org.apache.webbeans.component.ProducerMethodBean;
   90   import org.apache.webbeans.component.ProducerFieldBean;
   91   import org.apache.webbeans.component.WebBeansType;
   92   import org.apache.webbeans.config.DefinitionUtil;
   93   import org.apache.webbeans.config.EJBWebBeansConfigurator;
   94   import org.apache.webbeans.config.ManagedBeanConfigurator;
   95   import org.apache.webbeans.container.BeanManagerImpl;
   96   import org.apache.webbeans.conversation.ConversationImpl;
   97   import org.apache.webbeans.decorator.DecoratorUtil;
   98   import org.apache.webbeans.decorator.DecoratorsManager;
   99   import org.apache.webbeans.decorator.WebBeansDecoratorConfig;
  100   import org.apache.webbeans.deployment.DeploymentTypeManager;
  101   import org.apache.webbeans.event.EventImpl;
  102   import org.apache.webbeans.exception.WebBeansConfigurationException;
  103   import org.apache.webbeans.exception.WebBeansException;
  104   import org.apache.webbeans.exception.WebBeansPassivationException;
  105   import org.apache.webbeans.exception.inject.DefinitionException;
  106   import org.apache.webbeans.exception.inject.InconsistentSpecializationException;
  107   import org.apache.webbeans.exception.inject.NullableDependencyException;
  108   import org.apache.webbeans.intercept.InterceptorData;
  109   import org.apache.webbeans.intercept.InterceptorDataImpl;
  110   import org.apache.webbeans.intercept.InterceptorType;
  111   import org.apache.webbeans.intercept.InterceptorUtil;
  112   import org.apache.webbeans.intercept.InterceptorsManager;
  113   import org.apache.webbeans.intercept.WebBeansInterceptorConfig;
  114   import org.apache.webbeans.intercept.webbeans.WebBeansInterceptor;
  115   import org.apache.webbeans.plugins.OpenWebBeansPlugin;
  116   import org.apache.webbeans.plugins.PluginLoader;
  117   import org.apache.webbeans.portable.AnnotatedElementFactory;
  118   import org.apache.webbeans.portable.creation.InjectionTargetProducer;
  119   import org.apache.webbeans.portable.events.generics.GProcessAnnotatedType;
  120   import org.apache.webbeans.portable.events.generics.GProcessInjectionTarget;
  121   import org.apache.webbeans.portable.events.generics.GProcessProducer;
  122   import org.apache.webbeans.portable.events.generics.GProcessProducerField;
  123   import org.apache.webbeans.portable.events.generics.GProcessProducerMethod;
  124   
  125   /**
  126    * Contains some utility methods used in the all project.
  127    * 
  128    * @version $Rev: 811507 $ $Date: 2009-09-04 21:18:41 +0300 (Fri, 04 Sep 2009) $ 
  129    */
  130   @SuppressWarnings("unchecked")
  131   public final class WebBeansUtil
  132   {
  133       // No instantiate
  134       private WebBeansUtil()
  135       {
  136           throw new UnsupportedOperationException();
  137       }
  138   
  139       /**
  140        * Gets current classloader with current thread.
  141        * 
  142        * @return Current class loader instance
  143        */
  144       public static ClassLoader getCurrentClassLoader()
  145       {
  146           ClassLoader loader = AccessController.doPrivileged(new PrivilegedAction<ClassLoader>()
  147           {
  148   
  149               public ClassLoader run()
  150               {
  151                   try
  152                   {
  153                       return Thread.currentThread().getContextClassLoader();
  154   
  155                   }
  156                   catch (Exception e)
  157                   {
  158                       return null;
  159                   }
  160               }
  161   
  162           });
  163   
  164           if (loader == null)
  165           {
  166               loader = WebBeansUtil.class.getClassLoader();
  167           }
  168   
  169           return loader;
  170       }
  171   
  172       /**
  173        * Checks the generic type requirements.
  174        * 
  175        * @param bean managed bean instance
  176        */
  177       public static void checkGenericType(Bean<?> bean)
  178       {
  179       	Asserts.assertNotNull(bean);
  180       	
  181       	Class<?> clazz = bean.getBeanClass();
  182       	
  183           if (ClassUtil.isDefinitionConstainsTypeVariables(clazz))
  184           {
  185               if(!bean.getScope().equals(Dependent.class))
  186               {
  187                   throw new WebBeansConfigurationException("Generic type may only defined with scope @Dependent for bean class : " + clazz.getName());
  188               }
  189           }
  190       }
  191       
  192       
  193       /**
  194        * Check producer method/field bean return type. 
  195        * @param bean producer bean instance
  196        * @param member related member instance
  197        */
  198       public static void checkProducerGenericType(Bean<?> bean,Member member)
  199       {
  200       	Asserts.assertNotNull(bean,"Bean is null");
  201       	
  202       	Type type = null;
  203       	
  204       	if(bean instanceof ProducerMethodBean)
  205       	{
  206       		type = ((ProducerMethodBean<?>)bean).getCreatorMethod().getGenericReturnType();
  207       	}
  208       	else if(bean instanceof ProducerFieldBean)
  209       	{
  210       		type = ((ProducerFieldBean<?>)bean).getCreatorField().getGenericType();
  211       	}
  212       	else
  213       	{
  214       		throw new IllegalArgumentException("Bean must be Producer Field or Method Bean instance : " + bean);
  215       	}
  216       	
  217       	String message = "Producer Field/Method Bean with name : " + member.getName() + " in bean class : " + member.getDeclaringClass().getName(); 
  218       	
  219       	if(checkGenericForProducers(type, message))
  220       	{
  221               if(!bean.getScope().equals(Dependent.class))
  222               {
  223                   throw new WebBeansConfigurationException(message + " scope must bee @Dependent");
  224               }
  225       	}
  226       }
  227       
  228       /**
  229        * Check generic types for producer method and fields.
  230        * @param type generic return type
  231        * @param message error message
  232        * @return true if parametrized type argument is TypeVariable 
  233        */
  234       //Helper method
  235       private static boolean checkGenericForProducers(Type type, String message)
  236       {
  237       	boolean result = false;
  238       	
  239       	if(type instanceof TypeVariable)
  240       	{
  241       		throw new WebBeansConfigurationException(message + " return type can not be type variable");
  242       	}
  243       	
  244       	if(ClassUtil.isParametrizedType(type))
  245       	{
  246       		Type[] actualTypes = ClassUtil.getActualTypeArguements(type);
  247       		
  248       		if(actualTypes.length == 0)
  249       		{
  250           		throw new WebBeansConfigurationException(message + " return type must define actual type arguments or type variable");
  251       		}
  252       		
  253       		for(Type actualType : actualTypes)
  254       		{
  255       			if(ClassUtil.isWildCardType(actualType))
  256       			{
  257       				throw new WebBeansConfigurationException(message + " return type can not define wildcard actual type argument");
  258       			}
  259       			
  260       			if(ClassUtil.isTypeVariable(actualType))
  261       			{
  262       				result = true; 
  263       			}
  264       		}    		
  265       	}
  266       	
  267       	return result;
  268       }
  269       
  270       /**
  271        * Return <code>true</code> if the given class is ok for manage bean conditions,
  272        * <code>false</code> otherwise.
  273        * 
  274        * @param clazz class in hand
  275        * @return <code>true</code> if the given class is ok for simple web bean conditions.
  276        */
  277       public static void isManagedBeanClass(Class<?> clazz)
  278       {
  279           Asserts.nullCheckForClass(clazz, "Class is null");
  280           
  281           int modifier = clazz.getModifiers();
  282   
  283           if (!ClassUtil.isStatic(modifier) && ClassUtil.isInnerClazz(clazz))
  284               throw new WebBeansConfigurationException("Bean implementation class : " + clazz.getName() + " can not be non-static inner class");
  285   
  286           if (!ClassUtil.isConcrete(clazz) && !AnnotationUtil.isAnnotationExistOnClass(clazz, Decorator.class))
  287               throw new WebBeansConfigurationException("Bean implementation class : " + clazz.getName() + " have to be concrete if not defines as @Decorator");
  288                   
  289           if (!isConstructureOk(clazz))
  290           {
  291               throw new WebBeansConfigurationException("Bean implementation class : " + clazz.getName() + " must define at least one Constructor");   
  292           }
  293               
  294           // and finally call all checks which are defined in plugins like JSF, JPA, etc
  295           List<OpenWebBeansPlugin> plugins = PluginLoader.getInstance().getPlugins();
  296           for (OpenWebBeansPlugin plugin : plugins)
  297           {
  298               plugin.isManagedBean(clazz);
  299           }
  300       }
  301   
  302       /**
  303        * Defines applicable constructor.
  304        * @param <T> type info
  305        * @param clazz class type
  306        * @return constructor
  307        * @throws WebBeansConfigurationException any configuration exception
  308        */
  309       public static <T> Constructor<T> defineConstructor(Class<T> clazz) throws WebBeansConfigurationException
  310       {
  311           Asserts.nullCheckForClass(clazz);
  312           Constructor<T> result = null;
  313           Constructor<T>[] constructors = ClassUtil.getConstructors(clazz);
  314   
  315           boolean inAnnotation = false;
  316           int j = 0;
  317   
  318           /* Check for @Initializer */
  319           for (Constructor<T> constructor : constructors)
  320           {
  321               j++;
  322               if (constructor.getAnnotation(Inject.class) != null)
  323               {
  324                   if (inAnnotation == true)// duplicate @In
  325                   {
  326                       throw new WebBeansConfigurationException("There are more than one Constructor with Initializer annotation in class " + clazz.getName());
  327                   }
  328                   else
  329                   {
  330                       inAnnotation = true;
  331                       result = constructor;
  332                   }
  333               }
  334           }
  335   
  336           if (result != null)
  337           {
  338               Annotation[][] parameterAnns = result.getParameterAnnotations();
  339               for (Annotation[] parameters : parameterAnns)
  340               {
  341                   for (Annotation param : parameters)
  342                   {
  343                       Annotation btype = param.annotationType().getAnnotation(Disposes.class);
  344                       if (btype != null)
  345                       {
  346                           throw new WebBeansConfigurationException("Constructor parameter qualifier annotation can not be @Disposes annotation in class " + clazz.getName());
  347                       }
  348                       else
  349                       {
  350                           btype = param.annotationType().getAnnotation(Observes.class);
  351                           if (btype != null)
  352                           {
  353                               throw new WebBeansConfigurationException("Constructor parameter qualifier annotation can not be @Observes annotation in class " + clazz.getName());
  354                           }
  355                       }
  356                   }
  357   
  358               }
  359           }
  360   
  361           if (result == null)
  362           {
  363               if ((result = ClassUtil.isContaintNoArgConstructor(clazz)) != null)
  364               {
  365                   return result;
  366               }
  367               else
  368               {
  369                   throw new WebBeansConfigurationException("No constructor is found for the class : " + clazz.getName());
  370               }
  371           }
  372   
  373           return result;
  374       }
  375   
  376       /**
  377        * Check that simple web beans class has compatible constructor. 
  378        * @param clazz web beans simple class
  379        * @throws WebBeansConfigurationException if the web beans has incompatible
  380        *             constructor
  381        */
  382       public static boolean isConstructureOk(Class<?> clazz) throws WebBeansConfigurationException
  383       {
  384           Asserts.nullCheckForClass(clazz);
  385   
  386           if (ClassUtil.isContaintNoArgConstructor(clazz) != null)
  387           {
  388               return true;
  389           }
  390   
  391           Constructor<?>[] constructors = ClassUtil.getConstructors(clazz);
  392   
  393           int j = 0;
  394   
  395           for (Constructor<?> constructor : constructors)
  396           {
  397               j++;
  398               if (constructor.getAnnotation(Inject.class) != null)
  399               {
  400                   return true;
  401               }
  402           }
  403   
  404           return false;
  405       }
  406       
  407       /**
  408        * Check producer method is ok for deployment.
  409        * 
  410        * @param method producer method
  411        * @param parentImplClazzName parent class name
  412        */
  413       public static void checkProducerMethodForDeployment(Method method, String parentImplClazzName)
  414       {
  415           Asserts.assertNotNull(method, "Method argument can not be null");
  416   
  417           if (AnnotationUtil.isMethodHasAnnotation(method, Inject.class) || AnnotationUtil.isMethodParameterAnnotationExist(method, Disposes.class) || AnnotationUtil.isMethodParameterAnnotationExist(method, Observes.class))
  418           {
  419               throw new WebBeansConfigurationException("Producer Method Bean with name : " + method.getName() + " in bean class : " + parentImplClazzName + " can not be annotated with" + " @Initializer/@Destructor annotation or has a parameter annotated with @Disposes/@Observes");
  420           }
  421       }
  422       
  423       /**
  424        * CheckProducerMethodDisposal.
  425        * @param disposalMethod disposal method
  426        * @param definedBeanClassName bean class name 
  427        */
  428       public static void checkProducerMethodDisposal(Method disposalMethod, String definedBeanClassName)
  429       {
  430           if (AnnotationUtil.isMethodMultipleParameterAnnotationExist(disposalMethod, Disposes.class))
  431           {
  432               throw new WebBeansConfigurationException("Disposal method : " + disposalMethod.getName() + " in class " + definedBeanClassName + " has multiple @Disposes annotation parameter");
  433           }
  434   
  435           if (AnnotationUtil.isMethodHasAnnotation(disposalMethod, Inject.class) || AnnotationUtil.isMethodParameterAnnotationExist(disposalMethod, Observes.class) || AnnotationUtil.isMethodHasAnnotation(disposalMethod, Produces.class))
  436           {
  437               throw new WebBeansConfigurationException("Disposal method : " + disposalMethod.getName() + " in the class : " + definedBeanClassName + " can not be annotated with" + " @Initializer/@Destructor/@Produces annotation or has a parameter annotated with @Observes");
  438           }
  439   
  440       }
  441   
  442       /**
  443        * Check conditions for the new binding. 
  444        * @param annotations annotations
  445        * @return Annotation[] with all binding annotations
  446        * @throws WebBeansConfigurationException if &x0040;New plus any other binding annotation is set or
  447        *         if &x0040;New is used for an Interface or an abstract class.
  448        */
  449       public static Annotation[] checkForNewQualifierForDeployment(Type type, Class<?> clazz, String name, Annotation[] annotations)
  450       {
  451           Asserts.assertNotNull(type, "Type argument can not be null");
  452           Asserts.assertNotNull(clazz, "Clazz argument can not be null");
  453           Asserts.assertNotNull(annotations, "Annotations argument can not be null");
  454   
  455           Annotation[] as = AnnotationUtil.getQualifierAnnotations(annotations);
  456           for (Annotation a : annotations)
  457           {
  458               if (a.annotationType().equals(New.class))
  459               {
  460                   if (as.length > 1)
  461                   {
  462                       throw new WebBeansConfigurationException("@New binding annotation can not have any binding annotation in class : " + clazz.getName() + " in field/method : " + name);
  463                   }
  464   
  465                   if (ClassUtil.isAbstract(ClassUtil.getClass(type).getModifiers()) || ClassUtil.isInterface(ClassUtil.getClass(type).getModifiers()))
  466                   {
  467                       throw new WebBeansConfigurationException("@New binding annotation field can not have interface or abstract type in class : " + clazz.getName() + " in field/method : " + name);
  468                   }
  469               }
  470           }
  471           
  472           return as;
  473       }
  474   
  475       /**
  476        * Check conditions for the resources.
  477        * 
  478        * @param annotations annotations
  479        * @throws WebBeansConfigurationException if resource annotations exists and do not fit to the fields type, etc.
  480        * @see AnnotationUtil#isResourceAnnotation(Class)
  481        */
  482       public static void checkForValidResources(Type type, Class<?> clazz, String name, Annotation[] annotations)
  483       {
  484           Asserts.assertNotNull(type, "Type argument can not be null");
  485           Asserts.assertNotNull(clazz, "Clazz argument can not be null");
  486           Asserts.assertNotNull(annotations, "Annotations argument can not be null");
  487   
  488           List<OpenWebBeansPlugin> plugins = PluginLoader.getInstance().getPlugins();
  489           for (OpenWebBeansPlugin plugin : plugins)
  490           {
  491               plugin.checkForValidResources(type, clazz, name, annotations);
  492           }
  493       }
  494       
  495       /**
  496        * Returns true if src scope encloses the target.
  497        * 
  498        * @param src src scope
  499        * @param target target scope
  500        * @return true if src scope encloses the target
  501        */
  502       public static boolean isScopeEncloseOther(Class<? extends Annotation> src, Class<? extends Annotation> target)
  503       {
  504           Asserts.assertNotNull(src, "Src argument can not be null");
  505           Asserts.assertNotNull(target, "Target argument can not be null");
  506   
  507           if (src.equals(ConversationScoped.class))
  508           {
  509               return true;
  510           }
  511           else if (src.equals(ApplicationScoped.class))
  512           {
  513               if (target.equals(ConversationScoped.class) || (target.equals(ApplicationScoped.class)))
  514               {
  515                   return false;
  516               }
  517               else
  518               {
  519                   return true;
  520               }
  521   
  522           }
  523           else if (src.equals(SessionScoped.class))
  524           {
  525               if (target.equals(ConversationScoped.class) || target.equals(ApplicationScoped.class) || target.equals(SessionScoped.class))
  526               {
  527                   return false;
  528               }
  529               else
  530               {
  531                   return true;
  532               }
  533   
  534           }
  535           else if (src.equals(RequestScoped.class))
  536           {
  537               return false;
  538           }
  539           else
  540           {
  541               throw new WebBeansException("Scope is not correct");
  542           }
  543   
  544       }
  545   
  546       /**
  547        * New WebBeans component class.
  548        * 
  549        * @param <T>
  550        * @param clazz impl. class
  551        * @return the new component
  552        */
  553       public static <T> NewBean<T> createNewComponent(Class<T> clazz)
  554       {
  555           Asserts.assertNotNull(clazz, "Clazz argument can not be null");
  556   
  557           NewBean<T> comp = null;
  558   
  559           if (ManagedBeanConfigurator.isManagedBean(clazz))
  560           {
  561               comp = new NewBean<T>(clazz, WebBeansType.MANAGED);
  562               comp.setConstructor(WebBeansUtil.defineConstructor(clazz));
  563   
  564               DefinitionUtil.defineInjectedFields(comp);
  565               DefinitionUtil.defineInjectedMethods(comp);
  566           }
  567           else if (EJBWebBeansConfigurator.isSessionBean(clazz))
  568           {
  569               comp = new NewBean<T>(clazz, WebBeansType.ENTERPRISE);
  570           }
  571           else
  572           {
  573               throw new WebBeansConfigurationException("@New annotation on type : " + clazz.getName() + " must defined as a simple or an enterprise web bean");
  574           }
  575   
  576           comp.setImplScopeType(new DependentScopeLiteral());
  577           comp.addQualifier(new NewLiteral());
  578           comp.setName(null);
  579           comp.addApiType(clazz);
  580           comp.addApiType(Object.class);
  581           comp.setType(new ProductionLiteral());
  582   
  583           return comp;
  584       }
  585       
  586       /**
  587        * Creates a new extension bean.
  588        * 
  589        * @param <T> extension service class
  590        * @param clazz impl. class
  591        * @return a new extension service bean
  592        */
  593       public static <T> ExtensionBean<T> createExtensionComponent(Class<T> clazz)
  594       {
  595           Asserts.assertNotNull(clazz, "Clazz argument can not be null");
  596   
  597           ExtensionBean<T> comp = null;
  598           comp = new ExtensionBean<T>(clazz);
  599           
  600           DefinitionUtil.defineApiTypes(comp, clazz);
  601           
  602           comp.setImplScopeType(new ApplicationScopeLiteral());
  603           comp.addQualifier(new CurrentLiteral());
  604           comp.setType(new ProductionLiteral());
  605           
  606           DefinitionUtil.defineObserverMethods(comp, clazz);
  607   
  608           return comp;
  609       }
  610       
  611   
  612       /**
  613        * Returns a new managed bean from given bean.
  614        * 
  615        * @param <T> bean type parameter
  616        * @param component managed bean
  617        * @return the new bean from given managed bean
  618        */
  619       public static <T> NewBean<T> createNewSimpleBeanComponent(ManagedBean<T> component)
  620       {
  621           Asserts.assertNotNull(component, "component argument can not be null");
  622   
  623           NewBean<T> comp = null;
  624   
  625           comp = new NewBean<T>(component.getReturnType(), WebBeansType.NEW);
  626           
  627           DefinitionUtil.defineApiTypes(comp, component.getReturnType());
  628           comp.setConstructor(component.getConstructor());
  629           
  630           for(Field injectedField : component.getInjectedFields())
  631           {
  632               comp.addInjectedField(injectedField);
  633           }
  634           
  635           for(Method injectedMethod : component.getInjectedMethods())
  636           {
  637               comp.addInjectedMethod(injectedMethod);
  638           }
  639           
  640           List<InterceptorData> interceptorList = component.getInterceptorStack();
  641           if(!interceptorList.isEmpty())
  642           {
  643               component.getInterceptorStack().addAll(interceptorList);   
  644           }
  645           
  646           
  647           comp.setImplScopeType(new DependentScopeLiteral());
  648           comp.addQualifier(new NewLiteral());
  649           comp.setType(new StandardLiteral());
  650           comp.setName(null);
  651           
  652           Set<InjectionPoint> injectionPoints = component.getInjectionPoints();
  653           for(InjectionPoint injectionPoint : injectionPoints)
  654           {
  655               comp.addInjectionPoint(injectionPoint);
  656           }        
  657   
  658           return comp;
  659       }    
  660       
  661       /**
  662        * Creates a new event bean instance.
  663        * @param <T> type info
  664        * @param returnType bean api type
  665        * @param eventType event type
  666        * @param annotations event binding annotations
  667        * @return new event bean instance
  668        */
  669       public static <T> EventBean<T> createObservableImplicitComponent(Class<T> returnType, Type eventType, Annotation... annotations)
  670       {
  671           EventBean<T> component = new EventBean<T>(returnType, eventType, WebBeansType.OBSERVABLE);
  672   
  673           DefinitionUtil.defineApiTypes(component, returnType);
  674           DefinitionUtil.defineQualifiers(component, annotations);
  675   
  676           component.setType(new StandardLiteral());
  677           component.setImplScopeType(new DependentScopeLiteral());                      
  678   
  679           return component;
  680       }
  681   
  682       /**
  683        * Creates a new manager bean instance.
  684        * @return new manager bean instance
  685        */
  686       public static BeanManagerBean getManagerComponent()
  687       {
  688           BeanManagerBean managerComponent = new BeanManagerBean();
  689   
  690           managerComponent.setImplScopeType(new DependentScopeLiteral());
  691           managerComponent.setType(new StandardLiteral());
  692           managerComponent.addQualifier(new CurrentLiteral());
  693           managerComponent.addApiType(BeanManager.class);
  694           managerComponent.addApiType(Object.class);
  695   
  696           return managerComponent;
  697       }
  698       
  699       /**
  700        * Creates a new instance bean.
  701        * @param <T> type info
  702        * @param instance Instance instance
  703        * @param clazz Instance class
  704        * @param injectedType injected type
  705        * @param obtainsBindings instance bindings
  706        * @return new instance bean
  707        */
  708       public static <T> InstanceBean<T> createInstanceComponent(ParameterizedType instance,Class<Instance<T>> clazz, Type injectedType, Annotation...obtainsBindings)
  709       {
  710           InstanceBean<T> instanceComponent = new InstanceBean<T>(clazz,injectedType);
  711           
  712           instanceComponent.addApiType(clazz);
  713           instanceComponent.addApiType(Object.class);
  714           
  715           DefinitionUtil.defineQualifiers(instanceComponent, obtainsBindings);
  716           instanceComponent.setImplScopeType(new DependentScopeLiteral());
  717           instanceComponent.setType(new StandardLiteral());
  718           instanceComponent.setName(null);
  719           
  720           
  721           return instanceComponent;
  722       }
  723   
  724       /**
  725        * Returns new conversation bean instance.
  726        * @return new conversation bean
  727        */
  728       public static ConversationBean getConversationComponent()
  729       {
  730           ConversationBean conversationComp = new ConversationBean();
  731   
  732           conversationComp.addApiType(Conversation.class);
  733           conversationComp.addApiType(ConversationImpl.class);
  734           conversationComp.addApiType(Object.class);
  735           conversationComp.setImplScopeType(new RequestedScopeLiteral());
  736           conversationComp.setType(new StandardLiteral());
  737           conversationComp.addQualifier(new CurrentLiteral());
  738           conversationComp.setName("javax.context.conversation");
  739   
  740           return conversationComp;
  741       }
  742       
  743       /**
  744        * Returns a new injected point bean instance.
  745        * @return new injected point bean
  746        */
  747       public static InjectionPointBean getInjectionPointComponent()
  748       {
  749           return new InjectionPointBean(null);
  750       }
  751   
  752       /**
  753        * Check the {@link PostConstruct} or {@link PreDestroy} annotated method
  754        * criterias, and return post construct or pre destroy method.
  755        * <p>
  756        * Web Beans container is responsible for setting the post construct or pre
  757        * destroy annotation if the web beans component is not an EJB components,
  758        * in this case EJB container is responsible for this.
  759        * </p>
  760        * 
  761        * @param clazz checked class
  762        * @param commonAnnotation post construct or predestroy annotation
  763        * @return post construct or predestroy method
  764        */
  765       public static Method checkCommonAnnotationCriterias(Class<?> clazz, Class<? extends Annotation> commonAnnotation, boolean invocationContext)
  766       {
  767           Asserts.assertNotNull(clazz, "Clazz argument can not be null");
  768   
  769           Method[] methods = ClassUtil.getDeclaredMethods(clazz);
  770           Method result = null;
  771           boolean found = false;
  772           for (Method method : methods)
  773           {
  774               if (AnnotationUtil.isMethodHasAnnotation(method, commonAnnotation))
  775               {
  776                   if (ClassUtil.isMoreThanOneMethodWithName(method.getName(), clazz))
  777                   {
  778                       continue;
  779                   }
  780   
  781                   if (found == true)
  782                   {
  783                       throw new WebBeansConfigurationException("@" + commonAnnotation.getSimpleName() + " annotation is declared more than one method in the class : " + clazz.getName());
  784                   }
  785                   else
  786                   {
  787                       found = true;
  788                       result = method;
  789   
  790                       // Check method criterias
  791                       if (ClassUtil.isMethodHasParameter(method))
  792                       {
  793                           if (!invocationContext)
  794                               throw new WebBeansConfigurationException("@" + commonAnnotation.getSimpleName() + " annotated method : " + method.getName() + " in class : " + clazz.getName() + " can not take any formal arguments");
  795                           else
  796                           {
  797                               // Check method criterias
  798                               Class<?>[] params = ClassUtil.getMethodParameterTypes(method);
  799                               if (params.length != 1 || !params[0].equals(InvocationContext.class))
  800                                   throw new WebBeansConfigurationException("@" + commonAnnotation.getSimpleName() + " annotated method : " + method.getName() + " in class : " + clazz.getName() + " can not take any formal arguments other than InvocationContext");
  801   
  802                           }
  803                       }
  804   
  805                       if (!ClassUtil.getReturnType(method).equals(Void.TYPE))
  806                       {
  807                           throw new WebBeansConfigurationException("@" + commonAnnotation.getSimpleName() + " annotated method : " + method.getName() + " in class : " + clazz.getName() + " must return void type");
  808                       }
  809   
  810                       if (ClassUtil.isMethodHasCheckedException(method))
  811                       {
  812                           throw new WebBeansConfigurationException("@" + commonAnnotation.getSimpleName() + " annotated method : " + method.getName() + " in class : " + clazz.getName() + " can not throw any checked exception");
  813                       }
  814   
  815                       if (ClassUtil.isStatic(method.getModifiers()))
  816                       {
  817                           throw new WebBeansConfigurationException("@" + commonAnnotation.getSimpleName() + " annotated method : " + method.getName() + " in class : " + clazz.getName() + " can not be static");
  818                       }
  819                   }
  820               }
  821           }
  822   
  823           return result;
  824       }
  825   
  826       /**
  827        * Check the {@link AroundInvoke} annotated method criterias, and return
  828        * around invoke method.
  829        * <p>
  830        * Web Beans container is responsible for setting around invoke annotation
  831        * if the web beans component is not an EJB components, in this case EJB
  832        * container is responsible for this.
  833        * </p>
  834        * 
  835        * @param clazz checked class
  836        * @return around invoke method
  837        */
  838       public static Method checkAroundInvokeAnnotationCriterias(Class<?> clazz)
  839       {
  840           Asserts.assertNotNull(clazz, "Clazz argument can not be null");
  841   
  842           Method[] methods = ClassUtil.getDeclaredMethods(clazz);
  843           Method result = null;
  844           boolean found = false;
  845           for (Method method : methods)
  846           {
  847               if (AnnotationUtil.isMethodHasAnnotation(method, AroundInvoke.class))
  848               {
  849                   // Overriden methods
  850                   if (ClassUtil.isMoreThanOneMethodWithName(method.getName(), clazz))
  851                   {
  852                       continue;
  853                   }
  854   
  855                   if (found == true)
  856                   {
  857                       throw new WebBeansConfigurationException("@" + AroundInvoke.class.getSimpleName() + " annotation is declared more than one method in the class : " + clazz.getName());
  858                   }
  859                   else
  860                   {
  861                       found = true;
  862                       result = method;
  863   
  864                       // Check method criterias
  865                       Class<?>[] params = ClassUtil.getMethodParameterTypes(method);
  866                       if (params.length != 1 || !params[0].equals(InvocationContext.class))
  867                           throw new WebBeansConfigurationException("@" + AroundInvoke.class.getSimpleName() + " annotated method : " + method.getName() + " in class : " + clazz.getName() + " can not take any formal arguments other than InvocationContext");
  868   
  869                       if (!ClassUtil.getReturnType(method).equals(Object.class))
  870                       {
  871                           throw new WebBeansConfigurationException("@" + AroundInvoke.class.getSimpleName() + " annotated method : " + method.getName() + " in class : " + clazz.getName() + " must return Object type");
  872                       }
  873   
  874                       if (!ClassUtil.isMethodHasException(method))
  875                       {
  876                           throw new WebBeansConfigurationException("@" + AroundInvoke.class.getSimpleName() + " annotated method : " + method.getName() + " in class : " + clazz.getName() + " must throw Exception");
  877                       }
  878   
  879                       if (ClassUtil.isStatic(method.getModifiers()) || ClassUtil.isFinal(method.getModifiers()))
  880                       {
  881                           throw new WebBeansConfigurationException("@" + AroundInvoke.class.getSimpleName() + " annotated method : " + method.getName() + " in class : " + clazz.getName() + " can not be static or final");
  882                       }
  883                   }
  884               }
  885           }
  886   
  887           return result;
  888       }
  889   
  890       /**
  891        * Configures the interceptor stack of the web beans component.
  892        * 
  893        * @param clazz interceptor class
  894        * @param annotation annotation type
  895        * @param definedInInterceptorClass check if annotation is defined in
  896        *            interceptor class
  897        * @param definedInMethod check if the interceptor is defined in the comp.
  898        *            method
  899        * @param stack interceptor stack
  900        * @param annotatedInterceptorClassMethod if definedInMethod, this specify
  901        *            method
  902        * @param isDefinedWithWebBeans if interceptor is defined with WebBeans
  903        *            spec, not EJB spec
  904        */
  905       public static void configureInterceptorMethods(Interceptor<?> webBeansInterceptor, Class<?> clazz, Class<? extends Annotation> annotation, boolean definedInInterceptorClass, boolean definedInMethod, List<InterceptorData> stack, Method annotatedInterceptorClassMethod, boolean isDefinedWithWebBeans)
  906       {
  907           InterceptorData intData = null;
  908           Method method = null;
  909   
  910           if (annotation.equals(AroundInvoke.class))
  911           {
  912               method = WebBeansUtil.checkAroundInvokeAnnotationCriterias(clazz);
  913           }
  914           else if (annotation.equals(PostConstruct.class))
  915           {
  916               if (definedInInterceptorClass)
  917               {
  918                   method = WebBeansUtil.checkCommonAnnotationCriterias(clazz, PostConstruct.class, true);
  919               }
  920               else
  921               {
  922                   method = WebBeansUtil.checkCommonAnnotationCriterias(clazz, PostConstruct.class, false);
  923               }
  924           }
  925           else if (annotation.equals(PreDestroy.class))
  926           {
  927               if (definedInInterceptorClass)
  928               {
  929                   method = WebBeansUtil.checkCommonAnnotationCriterias(clazz, PreDestroy.class, true);
  930               }
  931               else
  932               {
  933                   method = WebBeansUtil.checkCommonAnnotationCriterias(clazz, PreDestroy.class, false);
  934               }
  935           }
  936   
  937           if (method != null)
  938           {
  939               intData = new InterceptorDataImpl(isDefinedWithWebBeans);
  940               intData.setDefinedInInterceptorClass(definedInInterceptorClass);
  941               intData.setDefinedInMethod(definedInMethod);
  942               intData.setAnnotatedMethod(annotatedInterceptorClassMethod);
  943               intData.setWebBeansInterceptor(webBeansInterceptor);
  944   
  945               if (definedInInterceptorClass)
  946               {
  947                   try
  948                   {
  949                       if (isDefinedWithWebBeans)
  950                       {
  951                           Object interceptorProxy = BeanManagerImpl.getManager().getInstance(webBeansInterceptor);
  952                           WebBeansInterceptor<?> interceptor = (WebBeansInterceptor<?>) webBeansInterceptor;
  953                           interceptor.setInjections(interceptorProxy);
  954   
  955                           //Setting interceptor proxy instance
  956                           intData.setInterceptorInstance(interceptorProxy);
  957                       }
  958                       else
  959                       {
  960                           if (ClassUtil.isContaintNoArgConstructor(clazz) == null)
  961                           {
  962                               throw new WebBeansConfigurationException("Interceptor class : " + clazz.getName() + " must have no-arg constructor");
  963                           }
  964   
  965                           intData.setInterceptorInstance(clazz.newInstance());
  966                       }
  967   
  968                   }
  969                   catch (WebBeansConfigurationException e1)
  970                   {
  971                       throw e1;
  972                   }
  973                   catch (Exception e)
  974                   {
  975                       throw new WebBeansException(e);
  976                   }
  977               }
  978   
  979               intData.setInterceptor(method, annotation);
  980   
  981               stack.add(intData);
  982           }
  983       }
  984   
  985       /**
  986        * Returns true if interceptor stack contains interceptor with given type.
  987        * 
  988        * @param stack interceptor stack
  989        * @param type interceptor type
  990        * @return true if stack contains the interceptor with given type
  991        */
  992       public static boolean isContainsInterceptorMethod(List<InterceptorData> stack, InterceptorType type)
  993       {
  994           Iterator<InterceptorData> it = stack.iterator();
  995           while (it.hasNext())
  996           {
  997               Method m = null;
  998               InterceptorData data = it.next();
  999   
 1000               if (type.equals(InterceptorType.AROUND_INVOKE))
 1001               {
 1002                   m = data.getAroundInvoke();
 1003               }
 1004               else if (type.equals(InterceptorType.POST_CONSTRUCT))
 1005               {
 1006                   m = data.getPostConstruct();
 1007   
 1008               }
 1009               else if (type.equals(InterceptorType.PRE_DESTROY))
 1010               {
 1011                   m = data.getPreDestroy();
 1012               }
 1013   
 1014               if (m != null)
 1015               {
 1016                   return true;
 1017               }
 1018   
 1019           }
 1020   
 1021           return false;
 1022       }
 1023   
 1024       /**
 1025        * Gets list of interceptors with the given type.
 1026        * 
 1027        * @param stack interceptor stack
 1028        * @param type interceptor type
 1029        * @return list of interceptor
 1030        */
 1031       
 1032       public static List<InterceptorData> getInterceptorMethods(List<InterceptorData> stack, InterceptorType type)
 1033       {
 1034           List<InterceptorData> ai = new ArrayList<InterceptorData>();
 1035           List<InterceptorData> pc = new ArrayList<InterceptorData>();
 1036           List<InterceptorData> pd = new ArrayList<InterceptorData>();
 1037   
 1038           Iterator<InterceptorData> it = stack.iterator();
 1039           while (it.hasNext())
 1040           {
 1041               Method m = null;
 1042               InterceptorData data = it.next();
 1043   
 1044               if (type.equals(InterceptorType.AROUND_INVOKE))
 1045               {
 1046                   m = data.getAroundInvoke();
 1047                   if (m != null)
 1048                   {
 1049                       ai.add(data);
 1050                   }
 1051   
 1052               }
 1053               else if (type.equals(InterceptorType.POST_CONSTRUCT))
 1054               {
 1055                   m = data.getPostConstruct();
 1056                   if (m != null)
 1057                   {
 1058                       pc.add(data);
 1059                   }
 1060   
 1061               }
 1062               else if (type.equals(InterceptorType.PRE_DESTROY))
 1063               {
 1064                   m = data.getPreDestroy();
 1065                   if (m != null)
 1066                   {
 1067                       pd.add(data);
 1068                   }
 1069   
 1070               }
 1071   
 1072           }
 1073   
 1074           if (type.equals(InterceptorType.AROUND_INVOKE))
 1075           {
 1076               return ai;
 1077           }
 1078           else if (type.equals(InterceptorType.POST_CONSTRUCT))
 1079           {
 1080               return pc;
 1081   
 1082           }
 1083           else if (type.equals(InterceptorType.PRE_DESTROY))
 1084           {
 1085               return pd;
 1086           }
 1087   
 1088           return Collections.EMPTY_LIST;
 1089       }
 1090   
 1091       /**
 1092        * Returns true if array contains the StereoType meta annotation
 1093        * 
 1094        * @param anns annotation array
 1095        * @return true if array contains the StereoType meta annotation
 1096        */
 1097       public static boolean isComponentHasStereoType(BaseBean<?> component)
 1098       {
 1099           Asserts.assertNotNull(component, "component parameter can not be null");
 1100   
 1101           Set<Annotation> set = component.getOwbStereotypes();
 1102           Annotation[] anns = new Annotation[set.size()];
 1103           anns = set.toArray(anns);
 1104           if (AnnotationUtil.isStereoTypeMetaAnnotationExist(anns))
 1105           {
 1106               return true;
 1107           }
 1108   
 1109           return false;
 1110       }
 1111   
 1112       /**
 1113        * Returns bean stereotypes.
 1114        * @param bean bean instance
 1115        * @return bean stereotypes
 1116        */
 1117       public static Annotation[] getComponentStereoTypes(BaseBean<?> bean)
 1118       {
 1119           Asserts.assertNotNull(bean, "bean parameter can not be null");
 1120           if (isComponentHasStereoType(bean))
 1121           {
 1122               Set<Annotation> set = bean.getOwbStereotypes();
 1123               Annotation[] anns = new Annotation[set.size()];
 1124               anns = set.toArray(anns);
 1125   
 1126               return AnnotationUtil.getStereotypeMetaAnnotations(anns);
 1127           }
 1128   
 1129           return new Annotation[] {};
 1130       }
 1131   
 1132       /**
 1133        * Returns true if name exists,false otherwise.
 1134        * @param bean bean instance
 1135        * @return true if name exists
 1136        */
 1137       public static boolean isNamedExistOnStereoTypes(BaseBean<?> bean)
 1138       {
 1139           Annotation[] types = getComponentStereoTypes(bean);
 1140   
 1141           for (Annotation ann : types)
 1142           {
 1143               if (AnnotationUtil.isAnnotationExistOnClass(ann.annotationType(), Named.class))
 1144               {
 1145                   return true;
 1146               }
 1147           }
 1148   
 1149           return false;
 1150       }
 1151   
 1152       public static Annotation getMaxPrecedenceSteroTypeDeploymentType(BaseBean<?> component)
 1153       {
 1154           Annotation[] deploymentTypes = getComponentStereoTypes(component);
 1155           Class<? extends Annotation> maxPrecedDeploymentType = null;
 1156           Annotation result = null;
 1157           if (deploymentTypes.length > 0)
 1158           {
 1159               for (Annotation dt : deploymentTypes)
 1160               {
 1161                   if (AnnotationUtil.isMetaAnnotationExist(dt.annotationType().getDeclaredAnnotations(), DeploymentType.class))
 1162                   {
 1163                       Annotation result2[] = AnnotationUtil.getMetaAnnotations(dt.annotationType().getDeclaredAnnotations(), DeploymentType.class);
 1164   
 1165                       Class<? extends Annotation> dtAnnot = result2[0].annotationType();
 1166                       if (maxPrecedDeploymentType == null)
 1167                       {
 1168                           maxPrecedDeploymentType = dtAnnot;
 1169                           result = result2[0];
 1170                       }
 1171                       else
 1172                       {
 1173                           if (DeploymentTypeManager.getInstance().comparePrecedences(maxPrecedDeploymentType, dtAnnot) < 0)
 1174                           {
 1175                               maxPrecedDeploymentType = dtAnnot;
 1176                               result = result2[0];
 1177                           }
 1178                       }
 1179                   }
 1180   
 1181               }
 1182           }
 1183   
 1184    
 1185           return result;
 1186       }
 1187   
 1188       public static String getSimpleWebBeanDefaultName(String clazzName)
 1189       {
 1190           Asserts.assertNotNull(clazzName);
 1191           
 1192           if(clazzName.length() > 0)
 1193           {
 1194               StringBuffer name = new StringBuffer(clazzName);
 1195               name.setCharAt(0, Character.toLowerCase(name.charAt(0)));
 1196   
 1197               return name.toString();            
 1198           }
 1199           
 1200           return clazzName;
 1201       }
 1202   
 1203       public static String getProducerDefaultName(String methodName)
 1204       {
 1205           StringBuffer buffer = new StringBuffer(methodName);
 1206               
 1207           if (buffer.length() > 3 &&  (buffer.substring(0, 3).equals("get") || buffer.substring(0, 3).equals("set")))                
 1208           {
 1209               
 1210               if(Character.isUpperCase(buffer.charAt(3)))
 1211               {
 1212                   buffer.setCharAt(3, Character.toLowerCase(buffer.charAt(3)));   
 1213               }
 1214   
 1215               return buffer.substring(3);
 1216           }
 1217           else if ((buffer.length() > 2 &&  buffer.substring(0, 2).equals("is")))                
 1218           {            
 1219               if(Character.isUpperCase(buffer.charAt(2)))
 1220               {
 1221                   buffer.setCharAt(2, Character.toLowerCase(buffer.charAt(2)));   
 1222               }
 1223   
 1224               return buffer.substring(2);
 1225           }
 1226           
 1227           else
 1228           {
 1229               buffer.setCharAt(0, Character.toLowerCase(buffer.charAt(0)));
 1230               return buffer.toString();
 1231           }
 1232       }
 1233   
 1234       /**
 1235        * Validates that given class obeys stereotype model
 1236        * defined by the specification.
 1237        * @param clazz stereotype class
 1238        */
 1239       public static void checkStereoTypeClass(Class<?> clazz)
 1240       {
 1241           Asserts.nullCheckForClass(clazz);
 1242   
 1243           Annotation[] annotations = clazz.getDeclaredAnnotations();
 1244   
 1245           boolean deploymentTypeFound = false;
 1246           boolean scopeTypeFound = false;
 1247           for (Annotation annotation : annotations)
 1248           {
 1249               Class<? extends Annotation> annotType = annotation.annotationType();
 1250   
 1251               if (annotType.isAnnotationPresent(DeploymentType.class))
 1252               {
 1253                   if (deploymentTypeFound == true)
 1254                   {
 1255                       throw new WebBeansConfigurationException("@StereoType annotation can not contain more than one @DeploymentType annotation");
 1256                   }
 1257                   else
 1258                   {
 1259                       deploymentTypeFound = true;
 1260                   }
 1261               }
 1262               else if (annotType.isAnnotationPresent(NormalScope.class) || annotType.isAnnotationPresent(Scope.class))
 1263               {
 1264                   if (scopeTypeFound == true)
 1265                   {
 1266                       throw new WebBeansConfigurationException("@StereoType annotation can not contain more than one @Scope/@NormalScope annotation");
 1267                   }
 1268                   else
 1269                   {
 1270                       scopeTypeFound = true;
 1271                   }
 1272               }
 1273               else if (annotType.equals(Named.class))
 1274               {
 1275                   Named name = (Named) annotation;
 1276                   if (!name.value().equals(""))
 1277                   {
 1278                       throw new WebBeansConfigurationException("@StereoType annotation can not define @Named annotation with value");
 1279                   }
 1280               }
 1281               else if (AnnotationUtil.isQualifierAnnotation(annotType))
 1282               {
 1283                   throw new WebBeansConfigurationException("@StereoType annotation can not define @Qualifier annotation");
 1284               }
 1285               else if (AnnotationUtil.isInterceptorBindingAnnotation(annotType))
 1286               {
 1287                   Target target = clazz.getAnnotation(Target.class);
 1288                   ElementType[] type = target.value();
 1289   
 1290                   if (type.length != 1 && !type[0].equals(ElementType.TYPE))
 1291                   {
 1292                       throw new WebBeansConfigurationException("Stereotype with @InterceptorBinding must be defined as @Target{TYPE}");
 1293                   }
 1294   
 1295               }
 1296           }
 1297       }
 1298   
 1299       /**
 1300        * Configures the bean specializations.
 1301        * <p>
 1302        * Specialized beans inherit the <code>name</code> property
 1303        * from their parents. Specialized bean deployment priority
 1304        * must be higher than its super class related bean.
 1305        * </p>
 1306        * 
 1307        * @param specializedClass specialized class
 1308        * @throws DefinitionException if name is defined
 1309        * @throws InconsistentSpecializationException related with priority
 1310        * @throws WebBeansConfigurationException any other exception
 1311        */
 1312       public static void configureSpecializations(Class<?> specializedClass)
 1313       {
 1314           Asserts.nullCheckForClass(specializedClass);
 1315   
 1316           Bean<?> superBean = null;
 1317           Bean<?> specialized = null;
 1318           Set<Bean<?>> resolvers = null;
 1319           
 1320           if ((resolvers = isConfiguredWebBeans(specializedClass,true)) != null)
 1321           {            
 1322               if(resolvers.isEmpty())
 1323               {
 1324                   throw new InconsistentSpecializationException("Specialized bean for class : " + specializedClass + " is not enabled in the deployment.");
 1325               }
 1326               
 1327               if(resolvers.size() > 1)
 1328               {
 1329                   throw new InconsistentSpecializationException("More than one specialized bean for class : " + specializedClass + " is enabled in the deployment.");
 1330               }
 1331               
 1332                                      
 1333               specialized = resolvers.iterator().next();
 1334               
 1335               Class<?> superClass = specializedClass.getSuperclass();
 1336               
 1337               resolvers = isConfiguredWebBeans(superClass,false);
 1338               
 1339               for(Bean<?> candidates : resolvers)
 1340               {
 1341                   AbstractBean<?> candidate = (AbstractBean<?>)candidates;
 1342                   
 1343                   if(!(candidate instanceof NewBean))
 1344                   {
 1345                       if(candidate.getReturnType().equals(superClass))
 1346                       {
 1347                           superBean = candidates;
 1348                           break;
 1349                       }                    
 1350                   }                
 1351               }
 1352                           
 1353               if (superBean != null)
 1354               {
 1355                   int res = DeploymentTypeManager.getInstance().comparePrecedences(specialized.getDeploymentType(), superBean.getDeploymentType());
 1356                   if (res <= 0)
 1357                   {
 1358                       throw new InconsistentSpecializationException("@Specializes exception. Class : " + specializedClass.getName() + " must have higher deployment type precedence from the class : " + superClass.getName());
 1359                   }
 1360                   
 1361                   AbstractBean<?> comp = (AbstractBean<?>)specialized;
 1362   
 1363                   if(superBean.getName() != null)
 1364                   {
 1365                       if(comp.getName() != null)
 1366                       {
 1367                           throw new DefinitionException("@Specialized Class : " + specializedClass.getName() + " may not explicitly declare a bean name");
 1368                       }                    
 1369                       
 1370                       comp.setName(superBean.getName());
 1371                       comp.setSpecializedBean(true);
 1372                   }
 1373                                   
 1374                   specialized.getQualifiers().addAll(superBean.getQualifiers());
 1375               }
 1376               
 1377               else
 1378               {
 1379                   throw new InconsistentSpecializationException("WebBean component class : " + specializedClass.getName() + " is not enabled for specialized by the " + specializedClass + " class");
 1380               }
 1381           }
 1382   
 1383       }
 1384   
 1385       public static Set<Bean<?>> isConfiguredWebBeans(Class<?> clazz,boolean annotate)
 1386       {   
 1387           Asserts.nullCheckForClass(clazz);
 1388           
 1389           Set<Bean<?>> beans = new HashSet<Bean<?>>();
 1390           
 1391           Set<Bean<?>> components = BeanManagerImpl.getManager().getComponents();
 1392           Iterator<Bean<?>> it = components.iterator();
 1393   
 1394           while (it.hasNext())
 1395           {
 1396               AbstractBean<?> bean = (AbstractBean<?>)it.next();
 1397               
 1398               if (bean.getTypes().contains(clazz))
 1399               {
 1400                   if(annotate)
 1401                   {
 1402                       if(bean.getReturnType().isAnnotationPresent(Specializes.class))
 1403                       {
 1404                           if(!(bean instanceof NewBean))
 1405                           {
 1406                               if(DeploymentTypeManager.getInstance().isDeploymentTypeEnabled(bean.getDeploymentType()))
 1407                               {
 1408                                   beans.add(bean);    
 1409                               }                            
 1410                           }                           
 1411                       }                                    
 1412                   }
 1413                   else
 1414                   {
 1415                       if(DeploymentTypeManager.getInstance().isDeploymentTypeEnabled(bean.getDeploymentType()))
 1416                       {
 1417                           beans.add(bean);   
 1418                       }
 1419                   }
 1420               }
 1421           }
 1422   
 1423           return beans;
 1424       }
 1425       
 1426       public static void checkUnproxiableApiType(Bean<?> bean, Class<? extends Annotation> scopeType)
 1427       {
 1428           Asserts.assertNotNull("bean", "bean parameter can not be null");
 1429           Asserts.assertNotNull(scopeType, "scopeType parameter can not be null");
 1430   
 1431           Set<Type> types = bean.getTypes();
 1432           Class<?> superClass = null;
 1433           for (Type t : types)
 1434           {
 1435               Class<?> type = ClassUtil.getClazz(t);
 1436               
 1437               if (!type.isInterface())
 1438               {
 1439                   if ((superClass == null) || (superClass.isAssignableFrom(type) && type != Object.class))
 1440                   {
 1441                       superClass = type;
 1442                   }
 1443   
 1444               }
 1445           }
 1446   
 1447           if (superClass != null && !superClass.equals(Object.class))
 1448           {
 1449               Constructor<?> cons = ClassUtil.isContaintNoArgConstructor(superClass);
 1450   
 1451               if (ClassUtil.isPrimitive(superClass) || ClassUtil.isArray(superClass) || ClassUtil.isFinal(superClass.getModifiers()) || ClassUtil.hasFinalMethod(superClass) || (cons == null || ClassUtil.isPrivate(cons.getModifiers())))
 1452               {
 1453                   if (scopeType.isAnnotationPresent(NormalScope.class))
 1454                   {
 1455                       throw new UnproxyableResolutionException("WebBeans with api type with normal scope must be proxiable to inject, but class : " + superClass.getName() + " is not proxiable type");
 1456                   }
 1457               }
 1458   
 1459           }
 1460   
 1461       }
 1462   
 1463       public static void checkNullable(Class<?> type, AbstractBean<?> component)
 1464       {
 1465           Asserts.assertNotNull(type, "type parameter can not be null");
 1466           Asserts.assertNotNull(component, "component parameter can not be null");
 1467   
 1468           if (type.isPrimitive())
 1469           {
 1470               if (component.isNullable())
 1471               {
 1472                   throw new NullableDependencyException("Injection point for primitive type resolves webbeans component with return type : " + component.getReturnType().getName() + " with nullable");
 1473               }
 1474           }
 1475       }
 1476   
 1477       /**
 1478        * Configures the producer method specialization.
 1479        * 
 1480        * @param component producer method component
 1481        * @param method specialized producer method
 1482        * @param superClass bean super class that has overriden method
 1483        * @throws DefinitionException if the name is exist on the producer method when
 1484        *         parent also has name
 1485        * @throws WebBeansConfigurationException any other exceptions
 1486        */
 1487       public static void configureProducerSpecialization(AbstractBean<?> component, Method method, Class<?> superClass)
 1488       {
 1489           Method superMethod = ClassUtil.getClassMethodWithTypes(superClass, method.getName(), Arrays.asList(method.getParameterTypes()));
 1490           if (superMethod == null)
 1491           {
 1492               throw new WebBeansConfigurationException("Producer method specialization is failed. Method " + method.getName() + " not found in super class : " + superClass.getName());
 1493           }
 1494           
 1495           if (!AnnotationUtil.isAnnotationExist(superMethod.getAnnotations(), Produces.class))
 1496           {
 1497               throw new WebBeansConfigurationException("Producer method specialization is failed. Method " + method.getName() + " found in super class : " + superClass.getName() + " is not annotated with @Produces");
 1498           }
 1499   
 1500           Annotation[] anns = AnnotationUtil.getQualifierAnnotations(superMethod.getAnnotations());
 1501   
 1502           for (Annotation ann : anns)
 1503           {
 1504               component.addQualifier(ann);
 1505           }
 1506           
 1507           configuredProducerSpecializedName(component, method, superMethod);
 1508           
 1509           component.setSpecializedBean(true);
 1510           
 1511       }
 1512       
 1513       /**
 1514        * Configures the name of the producer method for specializing the parent.
 1515        * 
 1516        * @param component producer method component
 1517        * @param method specialized producer method
 1518        * @param superMethod overriden super producer method
 1519        */
 1520       public static void configuredProducerSpecializedName(AbstractBean<?> component,Method method,Method superMethod)
 1521       {
 1522           Asserts.assertNotNull(component,"component parameter can not be null");
 1523           Asserts.assertNotNull(method,"method parameter can not be null");
 1524           Asserts.assertNotNull(superMethod,"superMethod parameter can not be null");
 1525           
 1526           String name = null;
 1527           boolean hasName = false;
 1528           if(AnnotationUtil.isMethodHasAnnotation(superMethod, Named.class))
 1529           {
 1530             Named named =  superMethod.getAnnotation(Named.class);
 1531             hasName = true;
 1532             if(!named.value().equals(""))
 1533             {
 1534                 name = named.value();
 1535             }
 1536             else
 1537             {
 1538                 name = getProducerDefaultName(superMethod.getName());
 1539             }
 1540           }
 1541           else 
 1542           {
 1543               Annotation[] anns = AnnotationUtil.getStereotypeMetaAnnotations(superMethod.getAnnotations());
 1544               for(Annotation ann : anns)
 1545               {
 1546                   if(ann.annotationType().isAnnotationPresent(Stereotype.class))
 1547                   {
 1548                       hasName = true;
 1549                       name = getProducerDefaultName(superMethod.getName());
 1550                       break;
 1551                   }
 1552               }                        
 1553           }
 1554           
 1555           if(hasName)
 1556           {
 1557               if(AnnotationUtil.isMethodHasAnnotation(method, Named.class))
 1558               {
 1559                   throw new DefinitionException("Specialized method : " + method.getName() + " in class : " + component.getReturnType().getName() + " may not define @Named annotation");
 1560               }
 1561               
 1562               component.setName(name);
 1563           }
 1564           
 1565   //        else
 1566   //        {
 1567   //            component.setName(name);
 1568   //        }
 1569           
 1570       }
 1571       
 1572       public static void checkInjectedMethodParameterConditions(Method method, Class<?> clazz)
 1573       {
 1574           Asserts.assertNotNull(method, "method parameter can not be null");
 1575           Asserts.nullCheckForClass(clazz);
 1576   
 1577           if (AnnotationUtil.isMethodParameterAnnotationExist(method, Disposes.class) || AnnotationUtil.isMethodParameterAnnotationExist(method, Observes.class))
 1578           {
 1579               throw new WebBeansConfigurationException("Initializer method parameters in method : " + method.getName() + " in class : " + clazz.getName() + " can not be annotated with @Disposes or @Observers");
 1580   
 1581           }
 1582   
 1583       }
 1584   
 1585       public static void checkInterceptorResolverParams(Annotation... interceptorBindings)
 1586       {
 1587           if (interceptorBindings == null || interceptorBindings.length == 0)
 1588           {
 1589               throw new IllegalArgumentException("Manager.resolveInterceptors() method parameter interceptor bindings array argument can not be empty");
 1590           }
 1591   
 1592           Annotation old = null;
 1593           for (Annotation interceptorBinding : interceptorBindings)
 1594           {
 1595               if (old == null)
 1596               {
 1597                   old = interceptorBinding;
 1598               }
 1599               else
 1600               {
 1601                   if (old.equals(interceptorBinding))
 1602                   {
 1603                       throw new IllegalArgumentException("Manager.resolveInterceptors() method parameter interceptor bindings array argument can not define duplicate binding annotation with name : @" + old.getClass().getName());
 1604                   }
 1605   
 1606                   if (!AnnotationUtil.isInterceptorBindingAnnotation(interceptorBinding.annotationType()))
 1607                   {
 1608                       throw new IllegalArgumentException("Manager.resolveInterceptors() method parameter interceptor bindings array can not contain other annotation that is not @InterceptorBinding");
 1609                   }
 1610   
 1611                   old = interceptorBinding;
 1612               }
 1613           }
 1614       }
 1615   
 1616       public static void checkDecoratorResolverParams(Set<Type> apiTypes, Annotation... qualifiers)
 1617       {
 1618           if (apiTypes == null || apiTypes.size() == 0)
 1619           {
 1620               throw new IllegalArgumentException("Manager.resolveDecorators() method parameter api types argument can not be empty");
 1621           }
 1622   
 1623           Annotation old = null;
 1624           for (Annotation qualifier : qualifiers)
 1625           {
 1626               if (old == null)
 1627               {
 1628                   old = qualifier;
 1629               }
 1630               else
 1631               {
 1632                   if (old.annotationType().equals(qualifier.annotationType()))
 1633                   {
 1634                       throw new IllegalArgumentException("Manager.resolveDecorators() method parameter qualifiers array argument can not define duplicate qualifier annotation with name : @" + old.annotationType().getName());
 1635                   }
 1636   
 1637                   if (!AnnotationUtil.isQualifierAnnotation(qualifier.annotationType()))
 1638                   {
 1639                       throw new IllegalArgumentException("Manager.resolveDecorators() method parameter qualifiers array can not contain other annotation that is not @Qualifier");
 1640                   }
 1641   
 1642                   old = qualifier;
 1643               }
 1644           }
 1645   
 1646       }
 1647       
 1648       /**
 1649        * Returns true if instance injection point false otherwise.
 1650        * 
 1651        * @param injectionPoint injection point definition
 1652        * @return true if instance injection point
 1653        */
 1654       public static boolean checkObtainsInjectionPointConditions(InjectionPoint injectionPoint)
 1655       {        
 1656           Type type = injectionPoint.getType();
 1657           
 1658           Class<?> candidateClazz = null;
 1659           if(type instanceof Class)
 1660           {
 1661               candidateClazz = (Class<?>)type;
 1662           }
 1663           else if(type instanceof ParameterizedType)
 1664           {
 1665               ParameterizedType pt = (ParameterizedType)type;
 1666               candidateClazz = (Class<?>)pt.getRawType();
 1667           }
 1668           
 1669           if(!candidateClazz.equals(Instance.class))
 1670           {
 1671               return false;
 1672           }        
 1673           
 1674           Class<?> rawType = null;
 1675           
 1676           if(ClassUtil.isParametrizedType(injectionPoint.getType()))
 1677           {
 1678               ParameterizedType pt = (ParameterizedType)injectionPoint.getType();
 1679               
 1680               rawType = (Class<?>) pt.getRawType();
 1681               
 1682               Type[] typeArgs = pt.getActualTypeArguments();
 1683               
 1684               if(!(rawType.equals(Instance.class)))
 1685               {
 1686                   throw new WebBeansConfigurationException("<Instance> field injection " + injectionPoint.toString() + " must have type javax.inject.Instance");
 1687               }                
 1688               else
 1689               {                                        
 1690                   if(typeArgs.length == 1)
 1691                   {
 1692                       Type actualArgument = typeArgs[0];
 1693                       
 1694                       if(ClassUtil.isParametrizedType(actualArgument) || ClassUtil.isWildCardType(actualArgument) || ClassUtil.isTypeVariable(actualArgument))
 1695                       {                            
 1696                           throw new WebBeansConfigurationException("<Instance> field injection " + injectionPoint.toString() + " actual type argument can not be Parametrized, Wildcard type or Type variable");                            
 1697                       }
 1698                                               
 1699                       if(ClassUtil.isDefinitionConstainsTypeVariables((Class<?>)actualArgument))
 1700                       {
 1701                           throw new WebBeansConfigurationException("<Instance> field injection " + injectionPoint.toString() + " must not have TypeVariable or WildCard generic type argument");                            
 1702                       }
 1703                   }
 1704                   else
 1705                   {
 1706                       throw new WebBeansConfigurationException("<Instance> field injection " + injectionPoint.toString() + " must not have more than one actual type argument");
 1707                   }
 1708               }                                
 1709           }
 1710           else
 1711           {
 1712               throw new WebBeansConfigurationException("<Instance> field injection " + injectionPoint.toString() + " must be defined as ParameterizedType with one actual type argument");
 1713           }  
 1714           
 1715           return true;
 1716       }
 1717   
 1718       public static <T> void checkPassivationScope(AbstractBean<T> component, NormalScope scope)
 1719       {
 1720           Asserts.assertNotNull(component, "component parameter can not be null");
 1721   
 1722           if(scope != null)
 1723           {
 1724               boolean passivating = scope.passivating();
 1725               Class<T> clazz = component.getReturnType();
 1726   
 1727               if (passivating)
 1728               {
 1729                   if (!component.isSerializable())
 1730                   {
 1731                       throw new WebBeansPassivationException("WebBeans component implementation class : " + clazz.getName() + " with passivating scope @" + scope.annotationType().getName() + " must be Serializable");
 1732                   }
 1733               }            
 1734           }        
 1735       }
 1736   
 1737       
 1738       public static <T> void defineInterceptors(Class<T> clazz)
 1739       {
 1740           if (InterceptorsManager.getInstance().isInterceptorEnabled(clazz))
 1741           {
 1742               ManagedBean<T> component = null;
 1743   
 1744               InterceptorUtil.checkInterceptorConditions(clazz);
 1745               component = ManagedBeanConfigurator.define(clazz, WebBeansType.INTERCEPTOR);
 1746   
 1747               if (component != null)
 1748               {
 1749                   WebBeansInterceptorConfig.configureInterceptorClass((ManagedBean<Object>) component, clazz.getDeclaredAnnotations());
 1750               }
 1751           }
 1752   
 1753       }
 1754   
 1755       
 1756       public static <T> void defineDecorators(Class<T> clazz)
 1757       {
 1758           if (DecoratorsManager.getInstance().isDecoratorEnabled(clazz))
 1759           {
 1760               ManagedBean<T> component = null;
 1761   
 1762               DecoratorUtil.checkDecoratorConditions(clazz);
 1763               component = ManagedBeanConfigurator.define(clazz, WebBeansType.DECORATOR);
 1764   
 1765               if (component != null)
 1766               {
 1767                   WebBeansDecoratorConfig.configureDecoratorClass((ManagedBean<Object>) component);
 1768               }
 1769           }
 1770       }
 1771   
 1772       public static boolean isScopeTypeNormal(Class<? extends Annotation> scopeType)
 1773       {
 1774           Asserts.assertNotNull(scopeType, "scopeType argument can not be null");
 1775   
 1776           if (scopeType.isAnnotationPresent(NormalScope.class))
 1777           {
 1778               return true;
 1779           }
 1780           else if(scopeType.isAnnotationPresent(Scope.class))
 1781           {
 1782               return false;
 1783           }
 1784           else
 1785           {
 1786               throw new IllegalArgumentException("scopeType argument must be annotated with @Scope or @NormalScope");
 1787           }
 1788       }
 1789       
 1790       public static void checkNullInstance(Object instance,Class<?> scopeType, String errorMessage)
 1791       {
 1792           if (instance == null)
 1793           {
 1794               if (!scopeType.equals(Dependent.class))
 1795               {
 1796                   throw new IllegalProductException(errorMessage);
 1797               }
 1798           }
 1799           
 1800       }
 1801       
 1802       public static void checkSerializableScopeType(Class<?> scopeType, boolean isSerializable, String errorMessage)
 1803       {
 1804           // Scope type check
 1805           NormalScope scope = scopeType.getAnnotation(NormalScope.class);
 1806           if(scope != null)
 1807           {
 1808               if (scope.passivating())
 1809               {
 1810                   if (!isSerializable)
 1811                   {
 1812                       throw new IllegalProductException(errorMessage);
 1813                   }
 1814               }            
 1815           }
 1816       }
 1817       
 1818       public static boolean isManagedBean(AbstractBean<?> component)
 1819       {
 1820           if(component.getWebBeansType().equals(WebBeansType.MANAGED) ||
 1821                   component.getWebBeansType().equals(WebBeansType.INTERCEPTOR) ||
 1822                   component.getWebBeansType().equals(WebBeansType.DECORATOR))
 1823           {
 1824               return true;
 1825           }
 1826           
 1827           return false;
 1828       }
 1829       
 1830       /**
 1831        * Returns true if bean is an enterprise bean, false otherwise.
 1832        * @param bean bean instance
 1833        * @return true if bean is an enterprise bean
 1834        */
 1835       public static boolean isEnterpriseBean(AbstractBean<?> bean)
 1836       {
 1837           Asserts.assertNotNull(bean,"Bean is null");
 1838           
 1839           if(bean.getWebBeansType().equals(WebBeansType.ENTERPRISE))
 1840           {
 1841               return true;
 1842           }
 1843           
 1844           return false;
 1845       }
 1846       
 1847       public static void addInjectedImplicitEventComponent(InjectionPoint injectionPoint)
 1848       {
 1849           Type type = injectionPoint.getType();
 1850           
 1851           if(!(type instanceof ParameterizedType))
 1852           {
 1853               return;
 1854           }
 1855           
 1856           Type[] args = new Type[0];
 1857           
 1858           Class<?> clazz = null;
 1859           if (type instanceof ParameterizedType)
 1860           {
 1861               ParameterizedType pt = (ParameterizedType) type;
 1862               args = pt.getActualTypeArguments();
 1863           }
 1864           
 1865           clazz = (Class<?>)args[0];
 1866           
 1867           Annotation[] qualifiers = new Annotation[injectionPoint.getQualifiers().size()];
 1868           qualifiers = injectionPoint.getQualifiers().toArray(qualifiers);
 1869           
 1870           Bean<?> bean = createObservableImplicitComponent(EventImpl.class, clazz, qualifiers);
 1871           BeanManagerImpl.getManager().addBean(bean);                  
 1872       }
 1873       
 1874       
 1875       public static <T> void addInjectedImplicitInstanceComponent(InjectionPoint injectionPoint)
 1876       {
 1877           ParameterizedType genericType = (ParameterizedType)injectionPoint.getType();
 1878           
 1879           Class<Instance<T>> clazz = (Class<Instance<T>>)genericType.getRawType();
 1880           
 1881           Annotation[] qualifiers = new Annotation[injectionPoint.getQualifiers().size()];
 1882           qualifiers = injectionPoint.getQualifiers().toArray(qualifiers);
 1883           
 1884           Bean<Instance<T>> bean = createInstanceComponent(genericType,clazz, genericType.getActualTypeArguments()[0], qualifiers);
 1885           BeanManagerImpl.getManager().addBean(bean);
 1886           
 1887       }
 1888       
 1889       public static Bean<?> getMostSpecializedBean(BeanManager manager, Bean<?> component)
 1890       {
 1891           Set<Bean<?>> beans = manager.getBeans(component.getBeanClass(), AnnotationUtil.getAnnotationsFromSet(component.getQualifiers()));
 1892                   
 1893           for(Bean<?> bean : beans)
 1894           {
 1895               Bean<?> find = bean;
 1896               
 1897               if(!find.equals(component))
 1898               {
 1899                   if(AnnotationUtil.isAnnotationExistOnClass(find.getBeanClass(), Specializes.class))
 1900                   {
 1901                       return getMostSpecializedBean(manager, find);
 1902                   }                
 1903               }            
 1904           }
 1905           
 1906           return component;
 1907       }      
 1908       
 1909       public static boolean isDeploymentTypeEnabled(Class<? extends Annotation> deploymentType)
 1910       {
 1911           Asserts.assertNotNull(deploymentType, "deplymentType parameter can not be null");
 1912           
 1913           if (!DeploymentTypeManager.getInstance().isDeploymentTypeEnabled(deploymentType))
 1914           {
 1915               return false;
 1916           }
 1917           
 1918           return true;        
 1919       }
 1920       
 1921       /**
 1922        * Returns <code>ProcessAnnotatedType</code> event. 
 1923        * @param <T> bean type
 1924        * @param clazz bean class
 1925        * @return event
 1926        */
 1927       public static <T> GProcessAnnotatedType fireProcessAnnotatedTypeEvent(AnnotatedType<T> annotatedType)
 1928       {                
 1929           GProcessAnnotatedType processAnnotatedEvent = new GProcessAnnotatedType(annotatedType);
 1930           
 1931           //Fires ProcessAnnotatedType
 1932           BeanManagerImpl.getManager().fireEvent(processAnnotatedEvent, new Annotation[0]);
 1933           
 1934           return processAnnotatedEvent;        
 1935       }
 1936       
 1937       /**
 1938        * Returns <code>ProcessInjectionTarget</code> event.
 1939        * @param <T> bean type
 1940        * @param bean bean instance
 1941        * @return event
 1942        */
 1943       public static <T> GProcessInjectionTarget fireProcessInjectionTargetEvent(AbstractInjectionTargetBean<T> bean)
 1944       {
 1945           AnnotatedType<T> annotatedType = AnnotatedElementFactory.newAnnotatedType(bean.getReturnType());
 1946           InjectionTargetProducer<T> injectionTarget = new InjectionTargetProducer<T>(bean);
 1947           GProcessInjectionTarget processInjectionTargetEvent = new GProcessInjectionTarget(injectionTarget,annotatedType);
 1948           
 1949           //Fires ProcessInjectionTarget
 1950           BeanManagerImpl.getManager().fireEvent(processInjectionTargetEvent, new Annotation[0]);
 1951           
 1952           return processInjectionTargetEvent;
 1953           
 1954       }
 1955       
 1956       public static GProcessProducer fireProcessProducerEventForMethod(ProducerMethodBean<?> producerMethod,AnnotatedMethod<?> method)
 1957       {         
 1958           GProcessProducer producerEvent = new GProcessProducer(method);
 1959           
 1960           //Fires ProcessProducer for methods
 1961           BeanManagerImpl.getManager().fireEvent(producerEvent, new Annotation[0]);
 1962           
 1963           return producerEvent;
 1964       }
 1965       
 1966       public static GProcessProducer fireProcessProducerEventForField(ProducerFieldBean<?> producerField,AnnotatedField<?> field)
 1967       {         
 1968           GProcessProducer producerEvent = new GProcessProducer(field);
 1969           
 1970           //Fires ProcessProducer for fields
 1971           BeanManagerImpl.getManager().fireEvent(producerEvent, new Annotation[0]);
 1972           
 1973           return producerEvent;
 1974       }
 1975       
 1976       public static void fireProcessProducerMethodBeanEvent(Map<ProducerMethodBean<?>,AnnotatedMethod<?>> annotatedMethods)
 1977       {
 1978           for(ProducerMethodBean<?> bean : annotatedMethods.keySet())
 1979           {
 1980               AnnotatedMethod<?> annotatedMethod = annotatedMethods.get(bean);                
 1981               Method disposal = bean.getDisposalMethod();
 1982               
 1983               AnnotatedMethod<?> disposalAnnotated = null;
 1984               GProcessProducerMethod processProducerMethodEvent = null;
 1985               if(disposal != null)
 1986               {
 1987                   disposalAnnotated = AnnotatedElementFactory.newAnnotatedMethod(disposal, bean.getParent().getReturnType());
 1988                   processProducerMethodEvent = new GProcessProducerMethod(bean,annotatedMethod,disposalAnnotated.getParameters().get(0));                
 1989               }
 1990               else
 1991               {
 1992                   processProducerMethodEvent = new GProcessProducerMethod(bean,annotatedMethod,null);
 1993               }
 1994               
 1995   
 1996               //Fires ProcessProducer
 1997               BeanManagerImpl.getManager().fireEvent(processProducerMethodEvent, new Annotation[0]);
 1998           }                
 1999       }
 2000       
 2001       public static void fireProcessProducerFieldBeanEvent(Map<ProducerFieldBean<?>,AnnotatedField<?>> annotatedFields)
 2002       {
 2003           for(ProducerFieldBean<?> bean : annotatedFields.keySet())
 2004           {
 2005               AnnotatedField<?> field = annotatedFields.get(bean);
 2006               
 2007               GProcessProducerField processProducerFieldEvent = new GProcessProducerField(bean,field);
 2008               
 2009               //Fire ProcessProducer
 2010               BeanManagerImpl.getManager().fireEvent(processProducerFieldEvent, new Annotation[0]);
 2011           }        
 2012       }
 2013       
 2014       /**
 2015        * Returns true if bean instance is an enterprise bean instance
 2016        * false otherwise.
 2017        * @param beanInstance bean instance
 2018        * @return true if bean instance is an enterprise bean instance
 2019        */
 2020       public static boolean isBeanHasEnterpriseMarker(Object beanInstance)
 2021       {
 2022           Asserts.assertNotNull(beanInstance,"Bean instance is null");
 2023           
 2024           if(beanInstance instanceof EnterpriseBeanMarker)
 2025           {
 2026               return true;
 2027           }
 2028           
 2029           return false;
 2030       }
 2031   }

Home » apache-openwebbeans-1.0.0-incubating-M3-sources » org.apache.webbeans.util » [javadoc | source]