Home » apache-openwebbeans-1.0.0-incubating-M3-sources » org.apache.webbeans.xml » [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.xml;
   15   
   16   import java.io.IOException;
   17   import java.io.InputStream;
   18   import java.lang.annotation.Annotation;
   19   import java.lang.reflect.Constructor;
   20   import java.lang.reflect.Field;
   21   import java.lang.reflect.Method;
   22   import java.lang.reflect.ParameterizedType;
   23   import java.lang.reflect.Type;
   24   import java.math.BigDecimal;
   25   import java.math.BigInteger;
   26   import java.sql.Time;
   27   import java.sql.Timestamp;
   28   import java.text.ParseException;
   29   import java.util.ArrayList;
   30   import java.util.Calendar;
   31   import java.util.Date;
   32   import java.util.HashSet;
   33   import java.util.Iterator;
   34   import java.util.List;
   35   import java.util.Set;
   36   
   37   import javax.decorator.Decorator;
   38   import javax.enterprise.context.NormalScope;
   39   import javax.enterprise.event.Observes;
   40   import javax.enterprise.inject.Disposes;
   41   import javax.enterprise.inject.Produces;
   42   import javax.enterprise.inject.deployment.DeploymentType;
   43   import javax.enterprise.inject.deployment.Production;
   44   import javax.inject.Inject;
   45   import javax.inject.Scope;
   46   import javax.interceptor.Interceptor;
   47   
   48   import org.apache.webbeans.WebBeansConstants;
   49   import org.apache.webbeans.annotation.CurrentLiteral;
   50   import org.apache.webbeans.annotation.ProductionLiteral;
   51   import org.apache.webbeans.component.AbstractBean;
   52   import org.apache.webbeans.component.xml.XMLManagedBean;
   53   import org.apache.webbeans.component.xml.XMLProducerBean;
   54   import org.apache.webbeans.config.DefinitionUtil;
   55   import org.apache.webbeans.config.ManagedBeanConfigurator;
   56   import org.apache.webbeans.config.OpenWebBeansConfiguration;
   57   import org.apache.webbeans.container.BeanManagerImpl;
   58   import org.apache.webbeans.decorator.DecoratorsManager;
   59   import org.apache.webbeans.deployment.DeploymentTypeManager;
   60   import org.apache.webbeans.exception.WebBeansConfigurationException;
   61   import org.apache.webbeans.exception.definition.NonexistentConstructorException;
   62   import org.apache.webbeans.exception.definition.NonexistentFieldException;
   63   import org.apache.webbeans.exception.definition.NonexistentMethodException;
   64   import org.apache.webbeans.exception.definition.NonexistentTypeException;
   65   import org.apache.webbeans.exception.inject.DefinitionException;
   66   import org.apache.webbeans.exception.inject.DeploymentException;
   67   import org.apache.webbeans.inject.AlternativesManager;
   68   import org.apache.webbeans.inject.impl.InjectionPointFactory;
   69   import org.apache.webbeans.inject.xml.XMLInjectableConstructor;
   70   import org.apache.webbeans.inject.xml.XMLInjectionModelType;
   71   import org.apache.webbeans.inject.xml.XMLInjectionPointModel;
   72   import org.apache.webbeans.intercept.InterceptorsManager;
   73   import org.apache.webbeans.jms.JMSManager;
   74   import org.apache.webbeans.jms.JMSModel;
   75   import org.apache.webbeans.jms.JMSModel.JMSType;
   76   import org.apache.webbeans.logger.WebBeansLogger;
   77   import org.apache.webbeans.plugins.OpenWebBeansEjbPlugin;
   78   import org.apache.webbeans.plugins.OpenWebBeansJmsPlugin;
   79   import org.apache.webbeans.plugins.PluginLoader;
   80   import org.apache.webbeans.proxy.JavassistProxyFactory;
   81   import org.apache.webbeans.util.AnnotationUtil;
   82   import org.apache.webbeans.util.Asserts;
   83   import org.apache.webbeans.util.ClassUtil;
   84   import org.apache.webbeans.util.WebBeansUtil;
   85   import org.dom4j.Element;
   86   
   87   /**
   88    * Configures the web beans from the xml declerations.
   89    */
   90   @SuppressWarnings("unchecked")
   91   public final class WebBeansXMLConfigurator
   92   {
   93       private static final WebBeansLogger logger = WebBeansLogger.getLogger(WebBeansXMLConfigurator.class);
   94       
   95       /** Enabled Deploy element check */
   96       private boolean DEPLOY_IS_DEFINED = false;
   97   
   98       /** Enabled Interceptors element check */
   99       private boolean INTERCEPTORS_IS_DEFINED = false;
  100   
  101       /** Enabled Decorators element check */
  102       private boolean DECORATORS_IS_DEFINED = false;    
  103   
  104       /** Current configuration file name */
  105       private String CURRENT_SCAN_FILE_NAME = null;
  106       
  107       /**OWB specific or not*/
  108       private boolean owbSpecificConfiguration = false;
  109   
  110       /** Annotation type manager that manages the XML defined annotations */
  111       private XMLAnnotationTypeManager xmlAnnotTypeManager = XMLAnnotationTypeManager.getInstance();
  112   
  113       /**
  114        * Creates a new instance of the <code>WebBeansXMLConfigurator</code>
  115        */
  116       public WebBeansXMLConfigurator()
  117       {
  118           String usage = OpenWebBeansConfiguration.getInstance().getProperty(OpenWebBeansConfiguration.USE_OWB_SPECIFIC_XML_CONFIGURATION);
  119           this.owbSpecificConfiguration = Boolean.parseBoolean(usage);
  120       }
  121       
  122       /**
  123        * Configures XML configuration file.
  124        * @param xmlStream xml configuration file
  125        */
  126       public void configure(InputStream xmlStream)
  127       {
  128           try
  129           {
  130               if(xmlStream.available() > 0)
  131               {
  132                   //Use OWB Specific XML Configuration
  133                   if(this.owbSpecificConfiguration)
  134                   {
  135                       configureOwbSpecific(xmlStream, "No-name XML Stream");    
  136                   }
  137                   else
  138                   {
  139                       configureSpecSpecific(xmlStream, "No-name XML Stream");
  140                   }
  141                       
  142               }
  143           }
  144           catch (IOException e)
  145           {
  146               throw new WebBeansConfigurationException(e);
  147           }
  148           
  149       }
  150       
  151       /**
  152        * Configures XML configuration file.
  153        * @param xmlStream xml configuration file
  154        * @param fileName file name
  155        */
  156       public void configure(InputStream xmlStream, String fileName)
  157       {
  158           try
  159           {
  160               if(xmlStream.available() > 0)
  161               {
  162                   //Use OWB Specific XML Configuration
  163                   if(this.owbSpecificConfiguration)
  164                   {
  165                       configureOwbSpecific(xmlStream, fileName);    
  166                   }
  167                   else
  168                   {
  169                       configureSpecSpecific(xmlStream, fileName);
  170                   }
  171                       
  172               }
  173           }
  174           catch (IOException e)
  175           {
  176               throw new WebBeansConfigurationException(e);
  177           }
  178           
  179       }
  180       
  181   
  182       /**
  183        * Configures the web beans from the given input stream.
  184        * 
  185        * @param xmlStream xml file containing the web beans definitions.
  186        * @param fileName name of the configuration file
  187        */
  188       public void configureOwbSpecific(InputStream xmlStream, String fileName)
  189       {
  190           try
  191           {
  192               if(xmlStream.available() > 0)
  193               {
  194                   Asserts.assertNotNull(xmlStream,"xmlStream parameter can not be null!");
  195                   Asserts.assertNotNull(fileName,"fileName parameter can not be null!");
  196                   
  197                   CURRENT_SCAN_FILE_NAME = fileName;
  198                   
  199                   //Get root element of the XML document
  200                   Element webBeansRoot = XMLUtil.getRootElement(xmlStream);
  201                   
  202                   //Start configuration
  203                   configureOwbSpecific(webBeansRoot);            
  204               }
  205           }
  206           catch (IOException e)
  207           {
  208               throw new WebBeansConfigurationException(e);
  209           }
  210       }
  211       
  212       /**
  213        * Configures the web beans from the given input stream.
  214        * 
  215        * @param xmlStream xml file containing the web beans definitions.
  216        * @param fileName name of the configuration file
  217        */
  218       public void configureSpecSpecific(InputStream xmlStream, String fileName)
  219       {
  220           try
  221           {
  222               if(xmlStream.available() > 0)
  223               {
  224                   Asserts.assertNotNull(xmlStream,"xmlStream parameter can not be null!");
  225                   Asserts.assertNotNull(fileName,"fileName parameter can not be null!");
  226                   
  227                   CURRENT_SCAN_FILE_NAME = fileName;
  228                   
  229                   //Get root element of the XML document
  230                   Element webBeansRoot = XMLUtil.getSpecStrictRootElement(xmlStream);
  231                   
  232                   //Start configuration
  233                   configureSpecSpecific(webBeansRoot);            
  234               }
  235           }
  236           catch (IOException e)
  237           {
  238               throw new WebBeansConfigurationException(e);
  239           }
  240       }
  241       
  242   
  243       /**
  244        * Configures the xml file root element.
  245        * 
  246        * @param webBeansRoot root element of the configuration xml file
  247        */
  248       private void configureOwbSpecific(Element webBeansRoot)
  249       {
  250           List<Element> webBeanDeclerationList = new ArrayList<Element>();
  251           List<Element> childs = webBeansRoot.elements();
  252           Iterator<Element> it = childs.iterator();
  253   
  254           Element child = null;
  255           while (it.hasNext())
  256           {
  257               child = it.next();
  258   
  259               /* WebBean element decleration */
  260               if (XMLUtil.isElementWebBeanDeclaration(child))
  261               {
  262                   webBeanDeclerationList.add(child);
  263   
  264               }
  265               /* <Deploy> element decleration */
  266               else if (XMLUtil.isElementDeployDeclaration(child))
  267               {
  268                   if (DEPLOY_IS_DEFINED)
  269                   {
  270                       throw new DeploymentException("There can not be more than one web-beans.xml file that declares <Deploy> element");
  271                   }
  272                   else
  273                   {
  274                       if (!XMLUtil.isElementChildExist(child, WebBeansConstants.WEB_BEANS_XML_STANDART_ELEMENT))
  275                       {
  276                           throw new DeploymentException("<Deploy> element must have <Standard/> deployment type in the web-beans.xml");
  277                       }
  278                       
  279                       DeploymentTypeManager.getInstance().removeProduction();
  280                       
  281                       configureDeploymentTypes(child);
  282                       DEPLOY_IS_DEFINED = true;
  283   
  284                   }
  285               }
  286               /* <Interceptors> element decleration */
  287               else if (XMLUtil.isElementInterceptorsDeclaration(child))
  288               {
  289                   if (INTERCEPTORS_IS_DEFINED)
  290                   {
  291                       throw new WebBeansConfigurationException("There can not be more than one web-beans.xml file that declares <Interceptors> element");
  292                   }
  293                   else
  294                   {
  295                       configureInterceptorsElement(child);
  296                       INTERCEPTORS_IS_DEFINED = true;
  297   
  298                   }
  299               }
  300               /* <Decorators> element decleration */
  301               else if (XMLUtil.isElementDecoratosDeclaration(child))
  302               {
  303                   if (DECORATORS_IS_DEFINED)
  304                   {
  305                       throw new WebBeansConfigurationException("There can not be more than one web-beans.xml file that declares <Decorators> element");
  306                   }
  307                   else
  308                   {
  309                       configureDecoratorsElement(child);
  310                       DECORATORS_IS_DEFINED = true;
  311   
  312                   }
  313               }
  314               /* <BindingType> annotation element decleration */
  315               else if (XMLUtil.isElementBindingTypeDecleration(child))
  316               {
  317                   addNewBindingType(child);
  318   
  319               }
  320               
  321               //X TODO <Resource> annotation element declaration */
  322               
  323               /* <InterceptorBindingType> annotation element decleration */
  324               else if (XMLUtil.isElementInterceptorBindingTypeDecleration(child))
  325               {
  326                   addNewInterceptorBindingType(child);
  327   
  328               }
  329               
  330               /* <Stereotype> annotation element decleration */
  331               else if (XMLUtil.isElementStereoTypeDecleration(child))
  332               {
  333                   addNewStereoTypeType(child);
  334               }
  335               else if(XMLUtil.getName(child).equals(WebBeansConstants.WEB_BEANS_XML_OWB_SPECIFIC_ALTERNATIVES))
  336               {
  337                   configureAlternativesElement(child);
  338               }
  339               
  340           }
  341   
  342           /*
  343            * If no <Deploy> element is defined in any webbeans.xml in the current
  344            * application
  345            */
  346           if (!DEPLOY_IS_DEFINED)
  347           {
  348               DeploymentTypeManager.getInstance().addNewDeploymentType(Production.class, 1);
  349           }
  350   
  351           // Configures the WebBeans components
  352           configureWebBeansComponents(webBeanDeclerationList);
  353   
  354       }
  355   
  356       /**
  357        * Configures the xml file root element.
  358        * 
  359        * @param webBeansRoot root element of the configuration xml file
  360        */
  361       private void configureSpecSpecific(Element webBeansRoot)
  362       {
  363           List<Element> childs = webBeansRoot.elements();
  364           Iterator<Element> it = childs.iterator();
  365   
  366           Element child = null;
  367           while (it.hasNext())
  368           {
  369               child = it.next();
  370   
  371               /* <Deploy> element decleration */
  372               if (XMLUtil.getName(child).equals(WebBeansConstants.WEB_BEANS_XML_SPEC_SPECIFIC_DEPLOY_ELEMENT))
  373               {
  374                   if (DEPLOY_IS_DEFINED)
  375                   {
  376                       throw new DeploymentException("There can not be more than one web-beans.xml file that declares <deploy> element");
  377                   }
  378                   else
  379                   {
  380                       if (!XMLUtil.isElementChildExist(child, WebBeansConstants.WEB_BEANS_XML_STANDART_ELEMENT))
  381                       {
  382                           throw new DeploymentException("<Deploy> element must have <Standard/> deployment type in the web-beans.xml");
  383                       }
  384                       
  385                       DeploymentTypeManager.getInstance().removeProduction();
  386                       
  387                       configureDeploymentTypes(child);
  388                       DEPLOY_IS_DEFINED = true;
  389   
  390                   }
  391               }
  392               /* <Interceptors> element decleration */
  393               else if (XMLUtil.getName(child).equals(WebBeansConstants.WEB_BEANS_XML_SPEC_SPECIFIC_INTERCEPTORS_ELEMENT))
  394               {
  395                   if (INTERCEPTORS_IS_DEFINED)
  396                   {
  397                       throw new WebBeansConfigurationException("There can not be more than one web-beans.xml file that declares <interceptors> element");
  398                   }
  399                   else
  400                   {
  401                       configureInterceptorsElement(child);
  402                       INTERCEPTORS_IS_DEFINED = true;
  403   
  404                   }
  405               }
  406               /* <Decorators> element decleration */
  407               else if (XMLUtil.getName(child).equals(WebBeansConstants.WEB_BEANS_XML_SPEC_SPECIFIC_DECORATORS_ELEMENT))
  408               {
  409                   if (DECORATORS_IS_DEFINED)
  410                   {
  411                       throw new WebBeansConfigurationException("There can not be more than one web-beans.xml file that declares <decorators> element");
  412                   }
  413                   else
  414                   {
  415                       configureDecoratorsElement(child);
  416                       DECORATORS_IS_DEFINED = true;
  417   
  418                   }
  419               }
  420               else if(XMLUtil.getName(child).equals(WebBeansConstants.WEB_BEANS_XML_SPEC_SPECIFIC_ALTERNATIVES))
  421               {
  422                   configureAlternativesElement(child);
  423               }
  424           }
  425   
  426           /*
  427            * If no <Deploy> element is defined in any webbeans.xml in the current
  428            * application
  429            */
  430           if (!DEPLOY_IS_DEFINED)
  431           {
  432               DeploymentTypeManager.getInstance().addNewDeploymentType(Production.class, 1);
  433           }
  434   
  435       }
  436       
  437       /**
  438        * Configures the webbeans defined in the xml file.
  439        * 
  440        * @param listOfWebBeanDecleration list of element that specifies new
  441        *            webbean decleration
  442        */
  443       private void configureWebBeansComponents(List<Element> listOfWebBeanDecleration)
  444       {
  445           if (!listOfWebBeanDecleration.isEmpty())
  446           {
  447               Iterator<Element> it = listOfWebBeanDecleration.iterator();
  448               while (it.hasNext())
  449               {
  450                   Element child = it.next();
  451                   /* JMS webbeans */
  452                   if (XMLUtil.isElementJMSDeclaration(child))
  453                   {
  454                       configureJMSEndpointComponent(child);
  455                   }
  456                   /* Simple or Enterprise webbean */
  457                   else
  458                   {
  459                       configureNewWebBeanComponent(child);
  460                   }
  461               }
  462           }
  463       }
  464   
  465       /**
  466        * Configure and add new binding type annotation.
  467        * 
  468        * @param bindingTypeElement new binding type element
  469        */
  470       private void addNewBindingType(Element bindingTypeElement)
  471       {
  472           Class<?> clazz = XMLUtil.getElementJavaType(bindingTypeElement);
  473           if (clazz == null)
  474           {
  475               throw new NonexistentTypeException(createConfigurationFailedMessage() + "Binding type with given class : " + bindingTypeElement.getName() + " not found");
  476           }
  477   
  478           Class<? extends Annotation> clazzAnnot = null;
  479           if (!clazz.isAnnotation())
  480           {
  481               throw new WebBeansConfigurationException(createConfigurationFailedMessage() + "Binding type with given class : " + bindingTypeElement.getName() + " is not an annotation type");
  482           }
  483           else
  484           {
  485               clazzAnnot = (Class<? extends Annotation>) clazz;
  486           }
  487   
  488           if (xmlAnnotTypeManager.isBindingTypeExist(clazzAnnot))
  489           {
  490               throw new DeploymentException(createConfigurationFailedMessage() + "Binding type with given class : " + bindingTypeElement.getName() + " is already defined in the XML");
  491           }
  492   
  493           xmlAnnotTypeManager.addBindingType(clazzAnnot);
  494       }
  495   
  496       /**
  497        * Configures and adds new interceptor binding type annotation.
  498        * 
  499        * @param interceptorBindingTypeElement new interceptor binding type element
  500        */
  501       private void addNewInterceptorBindingType(Element interceptorBindingTypeElement)
  502       {
  503           Class<?> clazz = XMLUtil.getElementJavaType(interceptorBindingTypeElement);
  504           if (clazz == null)
  505           {
  506               throw new NonexistentTypeException(createConfigurationFailedMessage() + "InterceptorBinding type with given class : " + interceptorBindingTypeElement.getName() + " not found");
  507           }
  508   
  509           Class<? extends Annotation> clazzAnnot = null;
  510           if (!clazz.isAnnotation())
  511           {
  512               throw new WebBeansConfigurationException(createConfigurationFailedMessage() + "InterceptorBinding type with given class : " + interceptorBindingTypeElement.getName() + " is not an annotation type");
  513           }
  514           else
  515           {
  516               clazzAnnot = (Class<? extends Annotation>) clazz;
  517           }
  518   
  519           if (xmlAnnotTypeManager.isInterceptorBindingTypeExist(clazzAnnot))
  520           {
  521               throw new DeploymentException(createConfigurationFailedMessage() + "InterceptorBinding type with given class : " + interceptorBindingTypeElement.getName() + " is already defined in the XML");
  522           }
  523   
  524           List<Element> childs = interceptorBindingTypeElement.elements();
  525           for (Element child : childs)
  526           {
  527               Class<?> clz = XMLUtil.getElementJavaType(child);
  528               if (clz == null)
  529               {
  530                   throw new NonexistentTypeException(createConfigurationFailedMessage() + "InterceptorBinding type with given class : " + XMLUtil.getElementJavaClassName(child) + " not found " + "in namespace : " + XMLUtil.getElementNameSpace(child));
  531               }
  532   
  533               if (!clz.isAnnotation() || !AnnotationUtil.isInterceptorBindingAnnotation((Class<? extends Annotation>) clz))
  534               {
  535                   throw new WebBeansConfigurationException(createConfigurationFailedMessage() + "InterceptorBinding type with given class : " + XMLUtil.getElementJavaClassName(child) + " is not interceptor binding annotation type");
  536               }
  537   
  538               Annotation inherited = XMLUtil.getXMLDefinedAnnotationMember(child, (Class<? extends Annotation>) clz, createConfigurationFailedMessage());
  539               xmlAnnotTypeManager.addInterceotorBindingTypeInheritAnnotation(clazzAnnot, inherited);
  540           }
  541   
  542       }
  543   
  544       /**
  545        * Configures and adds new stereotype annotation.
  546        * 
  547        * @param stereoTypeElement new stereotype annotation element
  548        */
  549       private void addNewStereoTypeType(Element stereoTypeElement)
  550       {
  551           Class<?> clazz = XMLUtil.getElementJavaType(stereoTypeElement);
  552           if (clazz == null)
  553           {
  554               throw new NonexistentTypeException(createConfigurationFailedMessage() + "Stereotype with given class : " + stereoTypeElement.getName() + " not found");
  555           }
  556   
  557           Class<? extends Annotation> clazzAnnot = null;
  558           if (!clazz.isAnnotation())
  559           {
  560               throw new WebBeansConfigurationException(createConfigurationFailedMessage() + "Stereotype with given class : " + stereoTypeElement.getName() + " is not an annotation type");
  561           }
  562           else
  563           {
  564               clazzAnnot = (Class<? extends Annotation>) clazz;
  565           }
  566   
  567           if (xmlAnnotTypeManager.isStereoTypeExist(clazzAnnot))
  568           {
  569               throw new DeploymentException(createConfigurationFailedMessage() + "Stereotype with given class : " + stereoTypeElement.getName() + " is already defined in the XML");
  570           }
  571   
  572           xmlAnnotTypeManager.addStereoType(clazzAnnot, stereoTypeElement, clazzAnnot.getName(), createConfigurationFailedMessage());
  573   
  574       }
  575   
  576       /**
  577        * Configures enablements of the interceptors.
  578        * 
  579        * @param interceptorsElement interceptors element
  580        */
  581       private void configureInterceptorsElement(Element interceptorsElement)
  582       {
  583           List<Element> childs = interceptorsElement.elements();
  584           Iterator<Element> itChilds = childs.iterator();
  585   
  586           InterceptorsManager manager = InterceptorsManager.getInstance();
  587           while (itChilds.hasNext())
  588           {
  589               Element child = itChilds.next();
  590               Class<?> clazz = null;
  591               
  592               if(this.owbSpecificConfiguration)
  593               {
  594                   clazz = XMLUtil.getElementJavaType(child);
  595               }
  596               else
  597               {
  598                   clazz = ClassUtil.getClassFromName(child.getTextTrim());
  599               }
  600   
  601               if (clazz == null)
  602               {
  603                   throw new WebBeansConfigurationException(createConfigurationFailedMessage() + "Interceptor class : " + XMLUtil.getName(child) + " not found");
  604               }
  605               else
  606               {
  607                   if (!AnnotationUtil.isInterceptorBindingMetaAnnotationExist(clazz.getDeclaredAnnotations()))
  608                   {
  609                       throw new WebBeansConfigurationException(createConfigurationFailedMessage() + "Interceptor class : " + XMLUtil.getName(child) + " must have at least one @InterceptorBindingType");
  610                   }
  611   
  612                   if (manager.isInterceptorEnabled(clazz))
  613                   {
  614                       throw new WebBeansConfigurationException(createConfigurationFailedMessage() + "Interceptor class : " + XMLUtil.getName(child) + " is already defined");
  615                   }
  616   
  617                   manager.addNewInterceptor(clazz);
  618               }
  619   
  620           }
  621   
  622       }
  623   
  624       /**
  625        * Configures enablements of the decorators.
  626        * 
  627        * @param decoratorsElement decorators element
  628        */
  629       private void configureDecoratorsElement(Element decoratorsElement)
  630       {
  631           List<Element> childs = decoratorsElement.elements();
  632           Iterator<Element> itChilds = childs.iterator();
  633   
  634           DecoratorsManager manager = DecoratorsManager.getInstance();
  635           while (itChilds.hasNext())
  636           {
  637               Element child = itChilds.next();
  638               Class<?> clazz = null;
  639               
  640               if(this.owbSpecificConfiguration)
  641               {
  642                   clazz = XMLUtil.getElementJavaType(child);
  643               }
  644               else
  645               {
  646                   clazz = ClassUtil.getClassFromName(child.getTextTrim());
  647               }
  648   
  649               if (clazz == null)
  650               {
  651                   throw new WebBeansConfigurationException(createConfigurationFailedMessage() + "Decorator class : " + XMLUtil.getName(child) + " not found");
  652               }
  653               else
  654               {
  655   
  656                   if (manager.isDecoratorEnabled(clazz))
  657                   {
  658                       throw new WebBeansConfigurationException(createConfigurationFailedMessage() + "Decorator class : " + XMLUtil.getName(child) + " is already defined");
  659                   }
  660   
  661                   manager.addNewDecorator(clazz);
  662               }
  663   
  664           }
  665   
  666       }
  667       
  668       /**
  669        * Configures enablements of the decorators.
  670        * 
  671        * @param decoratorsElement decorators element
  672        */
  673       private void configureAlternativesElement(Element alternativesElement)
  674       {
  675           List<Element> childs = alternativesElement.elements();
  676           Iterator<Element> itChilds = childs.iterator();
  677   
  678           while (itChilds.hasNext())
  679           {
  680               Element child = itChilds.next();
  681   
  682               if(XMLUtil.getName(child).equals(WebBeansConstants.WEB_BEANS_XML_SPEC_SPECIFIC_STEREOTYPE) ||
  683                       XMLUtil.getName(child).equals(WebBeansConstants.WEB_BEANS_XML_OWB_SPECIFIC_STEREOTYPE))
  684               {
  685                   addAlternative(child, true);
  686               }
  687               else if(XMLUtil.getName(child).equals(WebBeansConstants.WEB_BEANS_XML_SPEC_SPECIFIC_CLASS)
  688                       || XMLUtil.getName(child).equals(WebBeansConstants.WEB_BEANS_XML_OWB_SPECIFIC_CLASS))
  689               {
  690                   addAlternative(child, false);
  691               }
  692               else
  693               {
  694                   logger.warn("Alternative XML content is wrong. Child of <alternatives> must be <class>,<stereotype> but found " + XMLUtil.getName(child));
  695               }            
  696           }
  697       }
  698       
  699       private void addAlternative(Element child, boolean isStereoType)
  700       {
  701           Class<?> clazz = null;
  702           
  703           if(this.owbSpecificConfiguration)
  704           {
  705               clazz = XMLUtil.getElementJavaType(child);
  706           }
  707           else
  708           {
  709               clazz = ClassUtil.getClassFromName(child.getTextTrim());
  710           }
  711   
  712           if (clazz == null)
  713           {
  714               throw new WebBeansConfigurationException(createConfigurationFailedMessage() + "Alternative class : " + XMLUtil.getName(child) + " not found");
  715           }
  716           else
  717           {
  718               AlternativesManager manager = AlternativesManager.getInstance();
  719               if(isStereoType)
  720               {
  721                   manager.addStereoTypeAlternative(clazz);
  722               }
  723               else
  724               {
  725                   manager.addClazzAlternative(clazz);
  726               }
  727           }        
  728       }
  729       
  730   
  731       /**
  732        * Configures enablements of the deployment types.
  733        * 
  734        * @param deployElement deploy element
  735        */
  736       private void configureDeploymentTypes(Element deployElement)
  737       {
  738           List<Element> childs = deployElement.elements();
  739           Iterator<Element> itChilds = childs.iterator();
  740   
  741           int j = 1;
  742           while (itChilds.hasNext())
  743           {
  744               Element child = itChilds.next();
  745               Class<?> clazz = null;
  746               
  747               if(this.owbSpecificConfiguration)
  748               {
  749                   clazz = XMLUtil.getElementJavaType(child);
  750               }
  751               else
  752               {
  753                   clazz = ClassUtil.getClassFromName(child.getTextTrim());
  754               }
  755   
  756               if (clazz == null)
  757               {
  758                   throw new WebBeansConfigurationException(createConfigurationFailedMessage() + "@DeploymentType annotation with name : " + XMLUtil.getName(child) + " not found");
  759               }
  760               else
  761               {
  762                   if (!clazz.isAnnotation())
  763                       throw new WebBeansConfigurationException(createConfigurationFailedMessage() + "@DeploymentType annotation with name : " + XMLUtil.getName(child) + " is not annotation type");
  764                   else
  765                   {
  766                       Annotation ann = clazz.getAnnotation(DeploymentType.class);
  767                       if (ann == null)
  768                       {
  769                           throw new WebBeansConfigurationException(createConfigurationFailedMessage() + "@DeploymentType annotation with name : " + XMLUtil.getName(child) + " is not deployment type annotation");
  770                       }
  771                       else
  772                       {
  773                           DeploymentTypeManager.getInstance().addNewDeploymentType((Class<? extends Annotation>) clazz, j++);
  774                       }
  775                   }
  776               }
  777           }
  778       }
  779   
  780       /**
  781        * Configures new webbeans component from the given webbeans element.
  782        * 
  783        * @param webBeanElement web beans element
  784        */
  785       private void configureNewWebBeanComponent(Element webBeanElement)
  786       {
  787           Class<?> clazz = XMLUtil.getElementJavaType(webBeanElement);
  788   
  789           if (clazz == null)
  790           {
  791               throw new NonexistentTypeException(createConfigurationFailedMessage() + "Class with name : " + XMLUtil.getName(webBeanElement) + " is not found in namespace " + XMLUtil.getElementNameSpace(webBeanElement));
  792           }
  793   
  794           boolean ok = false;
  795   
  796           /* Enterprise WebBean */
  797           OpenWebBeansEjbPlugin plugin = PluginLoader.getInstance().getEjbPlugin();
  798           if (plugin != null && plugin.isSessionBean(clazz))
  799           {
  800               // Configure for EJB
  801               configureEJBWebBean(clazz);
  802               ok = true;
  803           }
  804           else
  805           {
  806               /* Simple WebBeans */
  807               if (ManagedBeanConfigurator.isManagedBean(clazz))
  808               {
  809                   // Configure Simple WebBean
  810                   configureSimpleWebBean(clazz, webBeanElement);
  811                   ok = true;
  812               }
  813           }
  814   
  815           /* If not applicable for configuration */
  816           if (!ok)
  817           {
  818               throw new WebBeansConfigurationException(createConfigurationFailedMessage() + "Given class with name : " + clazz.getName() + " is not resolved to any WebBeans type in {Simple WebBeans, Enterprise WebBeans, JMS WebBeans}");
  819           }
  820   
  821       }
  822   
  823       /**
  824        * Configures the simple webbean from the class.
  825        * 
  826        * @param simpleClass concrete java class defined in XML
  827        * @param webBeanDecleration webbeans decleration root element
  828        */
  829       public <T> XMLManagedBean<T> configureSimpleWebBean(Class<T> simpleClass, Element webBeanDecleration)
  830       {
  831           /* Checking XML defined simple webbeans condition check. Spec : 3.2.4 */
  832           XMLDefinitionUtil.checkSimpleWebBeansInXML(simpleClass, webBeanDecleration, createConfigurationFailedMessage());
  833   
  834           /* If interceptor, check this is enabled */
  835           if (XMLUtil.isElementChildExistWithWebBeansNameSpace(webBeanDecleration, WebBeansConstants.WEB_BEANS_XML_INTERCEPTOR_ELEMENT))
  836           {
  837               if (!InterceptorsManager.getInstance().isInterceptorEnabled(simpleClass))
  838               {
  839                   return null;
  840               }
  841           }
  842   
  843           /* If decorator, check this is enabled */
  844           if (XMLUtil.isElementChildExistWithWebBeansNameSpace(webBeanDecleration, WebBeansConstants.WEB_BEANS_XML_DECORATOR_ELEMENT))
  845           {
  846               if (!DecoratorsManager.getInstance().isDecoratorEnabled(simpleClass))
  847               {
  848                   return null;
  849               }
  850           }
  851   
  852           /* Create new XML component with class name */
  853           XMLManagedBean<T> component = new XMLManagedBean<T>(simpleClass);
  854   
  855           /* Configures API type of the webbeans component */
  856           DefinitionUtil.defineApiTypes(component, simpleClass);
  857   
  858           /* Configures child elements of this webbeans decleration element */
  859           configureWebBeanDeclerationChilds(component, webBeanDecleration);
  860   
  861           /* Check if the deployment type is enabled. */
  862           if (!DeploymentTypeManager.getInstance().isDeploymentTypeEnabled(component.getDeploymentType())) // Maybe
  863           {
  864               component = null;
  865   
  866           }
  867           /* Add to the manager */
  868           else
  869           {
  870               BeanManagerImpl.getManager().addBean(component);
  871           }
  872   
  873           return component;
  874       }
  875   
  876       /**
  877        * Configures the childs element of the given webbeans decleration element.
  878        * 
  879        * @param component xml webbeans element
  880        * @param webBeanDecleration webbeans element
  881        */
  882       private <T> void configureWebBeanDeclerationChilds(XMLManagedBean<T> component, Element webBeanDecleration)
  883       {
  884           List<Element> childs = webBeanDecleration.elements();
  885           Iterator<Element> it = childs.iterator();
  886   
  887           Element child = null;
  888   
  889           /* Constructor api type list */
  890           List<Class<?>> constTypeList = new ArrayList<Class<?>>();
  891   
  892           /* Constructor parameters element */
  893           List<Element> constructorParameterElementList = new ArrayList<Element>();
  894   
  895           /* Annotation set defined for webbeans */
  896           List<Class<? extends Annotation>> annotationSet = new ArrayList<Class<? extends Annotation>>();
  897   
  898           /* Annotation defined element list */
  899           List<Element> annotationElementList = new ArrayList<Element>();
  900   
  901           boolean isConstructor = false;
  902           String fieldOrMethodName = null;
  903           while (it.hasNext())
  904           {
  905               child = it.next();
  906               Class<?> type = XMLUtil.getElementJavaType(child);
  907   
  908               boolean isElementApplicable = false;
  909   
  910               // Java type then 2 possible outcome, Annotation type meta-data or
  911               // constructor
  912               if (type != null)
  913               {
  914                   if (type.isAnnotation())
  915                   {
  916                       // Annotation types defined on the webbeans
  917                       Class<? extends Annotation> annot = (Class<Annotation>) type;
  918                       annotationSet.add(annot);
  919                       annotationElementList.add(child);
  920   
  921                       isElementApplicable = true;
  922   
  923                   }
  924                   else
  925                   {
  926                       if (!isConstructor)
  927                       {
  928                           isConstructor = true;
  929                       }
  930   
  931                       /* Constructor parameter Element */
  932                       constructorParameterElementList.add(child);
  933   
  934                       // Adding constructor parameter class types
  935                       constTypeList.add(type);
  936   
  937                       isElementApplicable = true;
  938   
  939                   }
  940               }
  941               // Field or method decleration
  942               else
  943               {
  944                   // Namespace check
  945                   if (XMLUtil.getElementNameSpace(child).equals(XMLUtil.getElementNameSpace(webBeanDecleration)))
  946                   {
  947                       String name = XMLUtil.getName(child);
  948   
  949                       // Duplicate definition for field/method
  950                       if (fieldOrMethodName != null)
  951                       {
  952                           if (fieldOrMethodName.equals(name))
  953                           {
  954                               throw new WebBeansConfigurationException(createConfigurationFailedMessage() + "This field/method with name : " + fieldOrMethodName + " is already defined.");
  955                           }
  956   
  957                           else
  958                           {
  959                               configureFieldOrMethodMetaData(component, child);
  960                               fieldOrMethodName = name;
  961   
  962                               isElementApplicable = true;
  963                           }
  964                       }
  965                       else
  966                       {
  967                           configureFieldOrMethodMetaData(component, child);
  968                           fieldOrMethodName = name;
  969   
  970                           isElementApplicable = true;
  971                       }
  972                   }
  973                   else
  974                   {
  975                       throw new WebBeansConfigurationException(createConfigurationFailedMessage() + "Parent and child namespace has to be the same for field/method element decleration");
  976                   }
  977               }
  978   
  979               /* This element netiher constructor, annotation , field or method */
  980               if (!isElementApplicable)
  981               {
  982                   throw new WebBeansConfigurationException(createConfigurationFailedMessage() + "Element with name : " + XMLUtil.getName(child) + " is not applicable for child of the simple webbeans class :  " + component.getReturnType().getName());
  983               }
  984   
  985           }// end of while
  986   
  987           // Check Annotation Types
  988           XMLDefinitionUtil.checkTypeMetaDataClasses(annotationSet, createConfigurationFailedMessage());
  989   
  990           // Configure type-level metadata
  991           configureTypeLevelMetaData(component, annotationSet, annotationElementList, webBeanDecleration);
  992   
  993           // Constructor decleration
  994           if (isConstructor)
  995           {
  996               // Configure constructor parameters
  997               configureConstructorMetaData(component, constTypeList, constructorParameterElementList);
  998           }
  999           else
 1000           {
 1001               // Default constructor
 1002               component.setConstructor(WebBeansUtil.defineConstructor(component.getReturnType()));
 1003           }
 1004   
 1005       }
 1006   
 1007       /**
 1008        * Configures the type level meta data of the webbeans component.
 1009        * 
 1010        * @param component xml webbeans component
 1011        * @param annotationSet type level annotation set
 1012        * @param webBeanDecleration webbeans decleration element
 1013        */
 1014       public <T> void configureTypeLevelMetaData(XMLManagedBean<T> component, List<Class<? extends Annotation>> annotationSet, List<Element> annotationElementList, Element webBeanDecleration)
 1015       {
 1016           boolean isInterceptor = false;
 1017           boolean isDecorator = false;
 1018   
 1019           /* Check this is an Interceptor */
 1020           if (annotationSet.contains(Interceptor.class))
 1021           {
 1022               isInterceptor = true;
 1023           }
 1024   
 1025           /* Check this is a Decorator */
 1026           if (annotationSet.contains(Decorator.class))
 1027           {
 1028               isDecorator = true;
 1029           }
 1030   
 1031           // StereoType
 1032           configureStereoType(component, annotationSet, annotationElementList);
 1033   
 1034           // Deployment Type
 1035           configureDeploymentType(component, annotationSet, annotationElementList);
 1036   
 1037           // Scope Type
 1038           configureScopeType(component, annotationSet, annotationElementList);
 1039   
 1040           // Binding Type
 1041           configureBindingType(component, annotationSet, annotationElementList);
 1042   
 1043           if (!isInterceptor && !isDecorator)
 1044           {
 1045               // InterceptorBinding Type
 1046               configureInterceptorBindingType(component, annotationSet, annotationElementList);
 1047           }
 1048   
 1049           // Name configuration
 1050           configureNamed(component, annotationSet, webBeanDecleration);
 1051   
 1052           // Specializations
 1053           configureSpecializes(component, annotationSet);
 1054   
 1055           /* Interceptor Definition */
 1056           if (isInterceptor)
 1057           {
 1058               configureInterceptor(component, annotationSet, annotationElementList);
 1059           }
 1060   
 1061           /* Decorator Definition */
 1062           if (isDecorator)
 1063           {
 1064               configureDecorator(component, annotationSet, annotationElementList, webBeanDecleration);
 1065           }
 1066       }
 1067   
 1068       /**
 1069        * Configures the type level meta data of the webbeans component.
 1070        * 
 1071        * @param component xml webbeans component
 1072        * @param annotationSet type level annotation set
 1073        * @param webBeanDecleration webbeans decleration element
 1074        */
 1075       public <T> void configureProducerTypeLevelMetaData(AbstractBean<T> component, List<Class<? extends Annotation>> annotationSet, List<Element> annotationElementList, Element webBeanDecleration)
 1076       {
 1077           configureBindingType(component, annotationSet, annotationElementList);
 1078   
 1079           // StereoType
 1080           configureStereoType(component, annotationSet, annotationElementList);
 1081   
 1082           // Deployment Type
 1083           configureDeploymentType(component, annotationSet, annotationElementList);
 1084   
 1085           // Scope Type
 1086           configureScopeType(component, annotationSet, annotationElementList);
 1087   
 1088           // Name configuration
 1089           configureNamed(component, annotationSet, webBeanDecleration);
 1090       }
 1091   
 1092       /**
 1093        * Configures the component constructor. When resolution dependency of the
 1094        * constructor injection points, constructor parameter type defined in the
 1095        * xml is used.
 1096        * 
 1097        * @param component xml webbeans component
 1098        * @param typeList list of the constructor parameter types
 1099        * @param constructorParameterListElement parameter list element
 1100        * @throws DefinitionException if more than one constructor exists
 1101        * @throws NonexistentConstructorException if no constructor exists
 1102        */
 1103       private <T> void configureConstructorMetaData(XMLManagedBean<T> component, List<Class<?>> typeList, List<Element> constructorParameterListElement)
 1104       {
 1105           Class<T> implClazz = component.getReturnType();
 1106           Constructor<T> cons[] = ClassUtil.getConstructors(implClazz);
 1107   
 1108           boolean found = false;
 1109           Constructor<T> componentConstructor = null;
 1110           for (Constructor<T> constructor : cons)
 1111           {
 1112               Class<?>[] pt = constructor.getParameterTypes();
 1113   
 1114               // same parameter size
 1115               if (pt.length == typeList.size())
 1116               {
 1117                   int j = 0;
 1118                   boolean ok = false;
 1119   
 1120                   for (Class<?> parameterType : pt)
 1121                   {
 1122                       Class<?> xmlType = typeList.get(j);
 1123   
 1124                       if (ClassUtil.isAssignable(parameterType, xmlType))
 1125                       {
 1126                           if (!ok)
 1127                           {
 1128                               ok = true;
 1129                           }
 1130                       }
 1131                       else
 1132                       {
 1133                           ok = false;
 1134                       }
 1135   
 1136                       j++;
 1137                   }
 1138   
 1139                   if (ok)
 1140                   {
 1141                       if (found)
 1142                       {
 1143                           throw new WebBeansConfigurationException(createConfigurationFailedMessage() + "More than one constructor decleration exist.");
 1144                       }
 1145                       else
 1146                       {
 1147                           found = true;
 1148                           componentConstructor = constructor;
 1149                       }
 1150                   }
 1151   
 1152               }
 1153   
 1154           }
 1155   
 1156           if (!found)
 1157           {
 1158               throw new NonexistentConstructorException(createConfigurationFailedMessage() + "Constructor decleration not found in the class.");
 1159           }
 1160   
 1161           XMLInjectableConstructor<T> injectableConstructor = new XMLInjectableConstructor<T>(componentConstructor, component,null);
 1162           int i = 0;
 1163           Constructor<?> constructor = injectableConstructor.getConstructor();
 1164           for (Element element : constructorParameterListElement)
 1165           {
 1166               XMLInjectionPointModel model = XMLUtil.getInjectionPointModel(element, createConfigurationFailedMessage());
 1167               injectableConstructor.addInjectionPointModel(model);
 1168               
 1169               Annotation[] paramAnnos = constructor.getParameterAnnotations()[i++];            
 1170               
 1171               for(Annotation paramAnno : paramAnnos)
 1172               {
 1173                   model.addAnnotation(paramAnno);
 1174               }
 1175               
 1176               model.setInjectionMember(constructor);
 1177               model.setType(XMLInjectionModelType.CONSTRUCTOR);
 1178             
 1179               component.addInjectionPoint(InjectionPointFactory.getXMLInjectionPointData(component, model));
 1180           }
 1181   
 1182           component.setInjectableConstructor(injectableConstructor);
 1183       }
 1184   
 1185       /**
 1186        * Configures the field or method of the xml webbeans component. Checks for
 1187        * the field or method definition and call corresponding method.
 1188        * 
 1189        * @param component xml webbeans component
 1190        * @param child field or method child element
 1191        */
 1192       private <T> void configureFieldOrMethodMetaData(XMLManagedBean<T> component, Element child)
 1193       {
 1194           if (XMLUtil.isElementField(child))
 1195           {
 1196               configureField(component, child);
 1197   
 1198           }
 1199           else if (XMLUtil.isElementMethod(child))
 1200           {
 1201               configureMethod(component, child);
 1202           }
 1203       }
 1204   
 1205       /**
 1206        * Configures the given child element as field of the webbeans component.
 1207        * 
 1208        * @param component xml webbeans component
 1209        * @param child field element
 1210        * @throws NonexistentFieldException if field not exist
 1211        * @throws DefinitionException if field type declared in the xml is not
 1212        *             assignable to the type declared in class
 1213        * @throws DefinitionException if contains more than one &lt;valuegt;
 1214        *             element childs
 1215        */
 1216       private <T> void configureField(XMLManagedBean<T> component, Element child)
 1217       {
 1218           Class<?> clazz = component.getReturnType();
 1219   
 1220           String fieldName = XMLUtil.getName(child);
 1221           Field field = ClassUtil.getFieldWithName(clazz, fieldName);
 1222   
 1223           if (field == null)
 1224           {
 1225               throw new NonexistentFieldException(createConfigurationFailedMessage() + "Field name : " + fieldName + " decleration not found in the class : " + clazz.getName());
 1226           }
 1227   
 1228           boolean isValueElement = false;
 1229   
 1230           boolean isApplicable = false;
 1231           if (child.isTextOnly())
 1232           {
 1233               if (!isValueElement)
 1234               {
 1235                   isValueElement = true;
 1236                   isApplicable = true;
 1237               }
 1238           }
 1239   
 1240           List<Element> directChilds = child.elements();
 1241           Iterator<Element> itChilds = directChilds.iterator();
 1242   
 1243           boolean isTypeElement = false;
 1244   
 1245           // it has some other elements
 1246           while (itChilds.hasNext())
 1247           {
 1248               Element directChild = itChilds.next();
 1249               if (XMLUtil.isElementInWebBeansNameSpaceWithName(directChild, WebBeansConstants.WEB_BEANS_XML_VALUE_ELEMENT))
 1250               {
 1251                   if (!isValueElement)
 1252                   {
 1253                       isValueElement = true;
 1254                       isApplicable = true;
 1255                   }
 1256   
 1257               }
 1258               else
 1259               {
 1260                   Class<?> directChildType = XMLUtil.getElementJavaType(directChild);
 1261                   if (!ClassUtil.isAssignable(field.getType(), directChildType))
 1262                   {
 1263                       throw new WebBeansConfigurationException(createConfigurationFailedMessage() + "Declared field type is not assignable to class field type");
 1264                   }
 1265                   else
 1266                   {
 1267                       XMLInjectionPointModel injectionPointModel = XMLUtil.getInjectionPointModel(directChild, createConfigurationFailedMessage());
 1268                       component.addFieldInjectionPoint(field, injectionPointModel);
 1269                       
 1270                       Annotation[] annots = field.getAnnotations();
 1271                       for(Annotation annotation : annots)
 1272                       {
 1273                           injectionPointModel.addAnnotation(annotation);
 1274                       }
 1275                       
 1276                       injectionPointModel.setInjectionMember(field);
 1277                       injectionPointModel.setType(XMLInjectionModelType.FIELD);
 1278                       component.addInjectionPoint(InjectionPointFactory.getXMLInjectionPointData(component, injectionPointModel));
 1279   
 1280                       isTypeElement = true;
 1281                       isApplicable = true;
 1282                   }
 1283               }
 1284           }
 1285   
 1286           if (!isApplicable)
 1287           {
 1288               throw new WebBeansConfigurationException(createConfigurationFailedMessage() + "Field with name : " + fieldName + " element is not correctly defined");
 1289           }
 1290   
 1291           if (directChilds.size() > 1)
 1292           {
 1293               if (!isValueElement)
 1294               {
 1295                   throw new WebBeansConfigurationException(createConfigurationFailedMessage() + "One of the direct childs of the field must be element <value>");
 1296               }
 1297               else
 1298               {
 1299                   if (isValueElement && isTypeElement)
 1300                   {
 1301                       throw new WebBeansConfigurationException(createConfigurationFailedMessage() + "Direct child of the field can not contains both value element and type element");
 1302                   }
 1303               }
 1304           }
 1305   
 1306           // configure field values if available.
 1307           configureFieldValues(component, field, child, isValueElement);
 1308   
 1309       }
 1310   
 1311       /**
 1312        * Configures the method of the webbeans component.
 1313        * 
 1314        * @param component xml webbeans component
 1315        * @param child method element
 1316        * @throws NonexistentMethodException if method with name does not exist
 1317        * @throws NonexistentTypeException if method parameter types can not found
 1318        * @throws DefinitionException if any other configuration related exception
 1319        *             occurs.
 1320        */
 1321       private <T> void configureMethod(XMLManagedBean<T> component, Element child)
 1322       {
 1323           if (!ClassUtil.isMethodExistWithName(component.getReturnType(), XMLUtil.getName(child)))
 1324           {
 1325               throw new NonexistentMethodException(createConfigurationFailedMessage() + "Method declaration with name " + XMLUtil.getName(child) + " is not found in the class : " + component.getReturnType().getName());
 1326           }
 1327   
 1328           List<Element> methodChilds = child.elements();
 1329           Iterator<Element> itMethodChilds = methodChilds.iterator();
 1330   
 1331           boolean isDefineType = false;
 1332   
 1333           /*
 1334            * <Initializes> = 0; <Produces> = 1; <Disposes> = 2; <Observes> = 3;
 1335            * <Destructor> = 4; InterceptorBindingType annotation on method = 5;
 1336            */
 1337           int type = 0;
 1338   
 1339           /* Method parameters classes */
 1340           List<Class<?>> methodParameters = new ArrayList<Class<?>>();
 1341   
 1342           /* Method parameter xml elements */
 1343           List<Element> methodParameterElements = new ArrayList<Element>();
 1344   
 1345           Element methodChild = null;
 1346   
 1347           while (itMethodChilds.hasNext())
 1348           {
 1349               methodChild = itMethodChilds.next();
 1350               Class<?> childClazz = XMLUtil.getElementJavaType(methodChild);
 1351   
 1352               final String moreThanOneChildTypeErrorMesg = createConfigurationFailedMessage() + XMLUtil.getName(methodChild) + "method declaration can not contain more than one <Initializer>, <Destructor>, <Produces>, <Disposes> or <Observes> element";
 1353   
 1354               if (childClazz == null)
 1355               {
 1356                   throw new NonexistentTypeException(createConfigurationFailedMessage() + "Direct child element of method : " + XMLUtil.getName(methodChild) + " does not corresponds to any Java type");
 1357               }
 1358               else
 1359               {
 1360                   if (childClazz.isAnnotation())
 1361                   {
 1362                       if (childClazz.equals(Disposes.class))
 1363                       {
 1364                           if (isDefineType)
 1365                           {
 1366                               throw new WebBeansConfigurationException(moreThanOneChildTypeErrorMesg);
 1367                           }
 1368                           else
 1369                           {
 1370                               checkConfigureDisposes(component, methodChild);
 1371                               isDefineType = true;
 1372                               type = 2;
 1373                           }
 1374   
 1375                       }
 1376                       else if (childClazz.equals(Observes.class))
 1377                       {
 1378                           if (isDefineType)
 1379                           {
 1380                               throw new WebBeansConfigurationException(moreThanOneChildTypeErrorMesg);
 1381                           }
 1382                           else
 1383                           {
 1384                               checkConfigureObserves(component, methodChild);
 1385                               isDefineType = true;
 1386                               type = 3;
 1387                           }
 1388                       }
 1389                       else if (childClazz.equals(Inject.class))
 1390                       {
 1391                           if (isDefineType)
 1392                           {
 1393                               throw new WebBeansConfigurationException(moreThanOneChildTypeErrorMesg);
 1394                           }
 1395                           else
 1396                           {
 1397                               isDefineType = true;
 1398                               type = 0;
 1399                           }
 1400   
 1401                       }
 1402                       else if (childClazz.equals(Produces.class))
 1403                       {
 1404                           if (isDefineType)
 1405                           {
 1406                               throw new WebBeansConfigurationException(moreThanOneChildTypeErrorMesg);
 1407                           }
 1408                           else
 1409                           {
 1410                               isDefineType = true;
 1411                               type = 1;
 1412                           }
 1413                       }
 1414                       else if (AnnotationUtil.isInterceptorBindingAnnotation((Class<? extends Annotation>) childClazz))
 1415                       {
 1416                           // InterceptorBindingType with method
 1417                           type = 5;
 1418                       }
 1419                       else
 1420                       {
 1421                           throw new WebBeansConfigurationException(createConfigurationFailedMessage() + "Direct child element of method : " + XMLUtil.getName(methodChild) + " with Java type : " + childClazz + " is unknown");
 1422                       }
 1423                   }
 1424                   // Method parameter
 1425                   else
 1426                   {
 1427                       methodParameters.add(childClazz);
 1428                       methodParameterElements.add(methodChild);
 1429                   }
 1430               }
 1431           }
 1432   
 1433           // Check method conditions with method name and its parameter types.
 1434           Method annotatedMethod = checkConfigureMethodConditions(component, child, methodParameters);
 1435   
 1436           // Configures method according to the type of the element in 0,1,2,3,4,5
 1437           configureMethodAnnotationType(component, annotatedMethod, child, type, methodParameterElements);
 1438   
 1439       }
 1440   
 1441       /**
 1442        * Configures the webbeans component methods that are defines in the xml.
 1443        * 
 1444        * @param component xml webbeans component
 1445        * @param annotatedMethod annotated method to configure
 1446        * @param annotChild element child
 1447        * @param type type of the configuration method
 1448        */
 1449       private <T> void configureMethodAnnotationType(XMLManagedBean<T> component, Method annotatedMethod, Element annotChild, int type, List<Element> methodParameterElements)
 1450       {
 1451           switch (type)
 1452           {
 1453           case 0:
 1454   
 1455               configureMethodInitializeAnnotation(component, annotatedMethod, methodParameterElements);
 1456               break;
 1457   
 1458           case 1:
 1459               configureMethodProducesAnnotation(component, annotatedMethod, annotChild);
 1460               break;
 1461   
 1462           case 2:
 1463               configureMethodDisposesAnnotation(component, annotatedMethod, annotChild);
 1464               break;
 1465   
 1466           case 3:
 1467               configureMethodObservesAnnotation(component, annotatedMethod, annotChild);
 1468               break;
 1469   
 1470           case 5:
 1471               configureMethodInterceptorBindingTypeAnnotation(component, annotatedMethod, annotChild);
 1472               break;
 1473           }
 1474       }
 1475   
 1476       /**
 1477        * Configures the initializor method of the webbeans component.
 1478        * 
 1479        * @param component xml webbeans component
 1480        * @param initializeMethod initialize method of the webbeans component
 1481        * @param annotChild element child
 1482        */
 1483       private <T> void configureMethodInitializeAnnotation(XMLManagedBean<T> component, Method initializeMethod, List<Element> methodParameterElements)
 1484       {
 1485           if (methodParameterElements.isEmpty())
 1486           {
 1487               component.addMethodInjectionPoint(initializeMethod, null);
 1488           }
 1489           else
 1490           {
 1491               for (Element element : methodParameterElements)
 1492               {
 1493                   XMLInjectionPointModel model = XMLUtil.getInjectionPointModel(element, createConfigurationFailedMessage());
 1494                   component.addMethodInjectionPoint(initializeMethod, model);
 1495                   
 1496                   component.addInjectionPoint(XMLDefinitionUtil.getXMLMethodInjectionPoint(component, model, initializeMethod));
 1497               }
 1498           }
 1499       }
 1500   
 1501       private <T> void configureMethodProducesAnnotation(XMLManagedBean<T> component, Method producesMethod, Element annotChild)
 1502       {
 1503           XMLProducerBean<T> producer = XMLDefinitionUtil.defineXMLProducerMethod(this, component, producesMethod, annotChild, createConfigurationFailedMessage());
 1504           BeanManagerImpl.getManager().addBean(producer);
 1505       }
 1506   
 1507       private <T> void configureMethodDisposesAnnotation(XMLManagedBean<T> component, Method disposalMethod, Element annotChild)
 1508       {
 1509           XMLDefinitionUtil.defineXMLDisposalMethod(component, disposalMethod, annotChild, createConfigurationFailedMessage());
 1510   
 1511       }
 1512   
 1513       private <T> void configureMethodObservesAnnotation(XMLManagedBean<T> component, Method observesMethod, Element annotChild)
 1514       {
 1515           XMLDefinitionUtil.defineXMLObservesMethod(component, observesMethod, annotChild, createConfigurationFailedMessage());
 1516       }
 1517   
 1518       private <T> void configureMethodInterceptorBindingTypeAnnotation(XMLManagedBean<T> component, Method interceptorMethod, Element annotChild)
 1519       {
 1520           XMLDefinitionUtil.defineXMLMethodLevelInterceptorType(component, interceptorMethod, annotChild, createConfigurationFailedMessage());
 1521       }
 1522   
 1523       /**
 1524        * Check method conditions for the webbeans component.
 1525        * 
 1526        * @param component xml webbeans component
 1527        * @param child method element
 1528        * @param methodParameters method parameter types
 1529        * @throws NonexistentMethodException if no method is exist with given name
 1530        *             and method parameter types
 1531        * @throws DefinitionException if more than one method satisfies the
 1532        *             conditions
 1533        */
 1534       private <T> Method checkConfigureMethodConditions(XMLManagedBean<T> component, Element child, List<Class<?>> methodParameters)
 1535       {
 1536           // Check with name and also parameter types
 1537           List<Method> definedMethods = ClassUtil.getClassMethodsWithTypes(component.getReturnType(), XMLUtil.getName(child), methodParameters);
 1538   
 1539           if (definedMethods.size() == 0)
 1540           {
 1541               throw new NonexistentMethodException(createConfigurationFailedMessage() + "Method declaration with name " + XMLUtil.getName(child) + " is not found in the class : " + component.getReturnType().getName());
 1542   
 1543           }
 1544           else if (definedMethods.size() > 1)
 1545           {
 1546               throw new WebBeansConfigurationException(createConfigurationFailedMessage() + "More than one method : " + XMLUtil.getName(child) + " is found in the class : " + component.getReturnType().getName());
 1547           }
 1548   
 1549           return definedMethods.get(0);
 1550       }
 1551   
 1552       /**
 1553        * Configures the disposal method of the webbeans component.
 1554        * 
 1555        * @param component xml webbeans component
 1556        * @param disposes disposes element
 1557        * @throws DefinitionException if disposes element can not contain exactly
 1558        *             one child element
 1559        */
 1560       private <T> void checkConfigureDisposes(AbstractBean<T> component, Element disposes)
 1561       {
 1562           List<Element> disposesChilds = disposes.elements();
 1563   
 1564           if (disposesChilds.size() != 1)
 1565           {
 1566               throw new WebBeansConfigurationException(createConfigurationFailedMessage() + "Disposes element : " + XMLUtil.getName(disposes) + " can not contain more than one direct child elements");
 1567           }
 1568   
 1569       }
 1570   
 1571       /**
 1572        * Configures the observer method of the webbeans component
 1573        * 
 1574        * @param component xml webbeans component
 1575        * @param observes observes element
 1576        * @throws DefinitionException if disposes element can not contain exactly
 1577        *             one child element and it is not one of the {IfExists,
 1578        *             AfterTransactionCompletion, AfterTransactionSuccess,
 1579        *             AfterTransactionFailure, BeforeTransactionCompletion}
 1580        *             element.
 1581        */
 1582       private <T> void checkConfigureObserves(AbstractBean<T> component, Element observes)
 1583       {
 1584           List<Element> observesChilds = observes.elements();
 1585   
 1586           if (observesChilds.size() != 1)
 1587           {
 1588               throw new WebBeansConfigurationException(createConfigurationFailedMessage() + "Observes element : " + XMLUtil.getName(observes) + " can not contain more than one direct child elements");
 1589           }
 1590           else
 1591           {
 1592   //            Element child = observesChilds.iterator().next();
 1593   //            Class<?> clazz = XMLUtil.getElementJavaType(child);
 1594   
 1595   //            if ((clazz == null) || clazz.equals(IfExists.class) || clazz.equals(AfterTransactionCompletion.class) || clazz.equals(AfterTransactionSuccess.class) || clazz.equals(AfterTransactionFailure.class) || clazz.equals(BeforeTransactionCompletion.class))
 1596   //            {
 1597   //                throw new WebBeansConfigurationException(createConfigurationFailedMessage() + "Observes element : " + XMLUtil.getName(observes) + " must not have one of the {<IfExists>, <AfterTransactionCompletion>, <AfterTransactionSuccess>, <AfterTransactionFailure>, <BeforeTransactionCompletion>} as a direct child.");
 1598   //            }
 1599           }
 1600   
 1601       }
 1602   
 1603       /**
 1604        * Configures the deployment type of the XML component.
 1605        * 
 1606        * @param component xml defined web beans component
 1607        * @param annotationSet all annotation defined in XML
 1608        */
 1609       private <T> void configureDeploymentType(AbstractBean<T> component, List<Class<? extends Annotation>> annotationSet, List<Element> annotationElementList)
 1610       {
 1611           Class<? extends Annotation> deploymentType = XMLDefinitionUtil.defineXMLTypeMetaData(component, annotationSet, DeploymentType.class, createConfigurationFailedMessage() + "@DeploymentType annotation is not configured correctly for class : " + component.getReturnType().getName());
 1612   
 1613           if (deploymentType == null)
 1614           {
 1615               // Check from stereotype
 1616               Annotation stereoTypeDeploymentType = WebBeansUtil.getMaxPrecedenceSteroTypeDeploymentType(component);
 1617               
 1618               if(stereoTypeDeploymentType == null)
 1619               {
 1620                   // Default deployment type
 1621                   component.setType(new ProductionLiteral());                
 1622               }
 1623               else
 1624               {
 1625                   component.setType(stereoTypeDeploymentType);
 1626               }
 1627               
 1628           }
 1629           else
 1630           {
 1631               component.setType(JavassistProxyFactory.createNewAnnotationProxy(deploymentType));
 1632           }
 1633       }
 1634   
 1635       /**
 1636        * Configures the webbeans scope type.
 1637        * 
 1638        * @param component xml defined web beans component
 1639        * @param annotationSet all annotation defined in XML
 1640        */
 1641       private <T> void configureScopeType(AbstractBean<T> component, List<Class<? extends Annotation>> annotationSet, List<Element> annotationElementList)
 1642       {
 1643           Class<? extends Annotation> scopeType = XMLDefinitionUtil.defineXMLTypeMetaData(component, annotationSet, NormalScope.class, createConfigurationFailedMessage() + "@Scope/@NormalScope annotation is not configured correctly");
 1644   
 1645           if(scopeType == null)
 1646           {
 1647               scopeType = XMLDefinitionUtil.defineXMLTypeMetaData(component, annotationSet, Scope.class, createConfigurationFailedMessage() + "@Scope/@NormalScope annotation is not configured correctly");            
 1648           }
 1649           
 1650           if (scopeType == null)
 1651           { 
 1652               // From stereotype
 1653               DefinitionUtil.defineDefaultScopeType(component, createConfigurationFailedMessage() + "@Scope annotation is not configured correctly");
 1654           }
 1655           else
 1656           {
 1657               component.setImplScopeType(JavassistProxyFactory.createNewAnnotationProxy(scopeType));
 1658           }
 1659   
 1660       }
 1661   
 1662       /**
 1663        * Configures the binding types of the web beans component.
 1664        * 
 1665        * @param component web beans xml component
 1666        * @param anns annotations defined in the xml documents
 1667        */
 1668       private <T> void configureBindingType(AbstractBean<T> component, List<Class<? extends Annotation>> annotationSet, List<Element> annotationElementList)
 1669       {
 1670           boolean isDefined = XMLDefinitionUtil.defineXMLBindingType(component, annotationSet, annotationElementList, createConfigurationFailedMessage());
 1671   
 1672           if (!isDefined)
 1673           {
 1674               component.addQualifier(new CurrentLiteral());
 1675           }
 1676   
 1677       }
 1678   
 1679       /**
 1680        * Configures the class level interceptor binding types.
 1681        * 
 1682        * @param component web beans xml component
 1683        * @param anns annotations defined in the xml documents
 1684        */
 1685       private <T> void configureInterceptorBindingType(XMLManagedBean<T> component, List<Class<? extends Annotation>> annotationSet, List<Element> annotationElementList)
 1686       {
 1687           XMLDefinitionUtil.defineXMLClassLevelInterceptorType(component, annotationSet, annotationElementList, createConfigurationFailedMessage());
 1688       }
 1689   
 1690       /**
 1691        * Defines the component stereotypes.
 1692        * 
 1693        * @param component webbeans component
 1694        * @param annotationSet type-level metadata annotation set
 1695        */
 1696       private <T> void configureStereoType(AbstractBean<T> component, List<Class<? extends Annotation>> annotationSet, List<Element> annotationElementList)
 1697       {
 1698           XMLDefinitionUtil.defineXMLStereoType(component, annotationSet);
 1699       }
 1700   
 1701       /**
 1702        * Configures the webbeans name.
 1703        * 
 1704        * @param component webbeans component
 1705        * @param annotationSet type-level metadata annotation set
 1706        * @param webBeanDecleration webbeans decleration element
 1707        */
 1708       private <T> void configureNamed(AbstractBean<T> component, List<Class<? extends Annotation>> annotationSet, Element webBeanDecleration)
 1709       {
 1710           boolean isDefined = XMLDefinitionUtil.defineXMLName(component, annotationSet);
 1711           if (isDefined)
 1712           {
 1713               Element element = webBeanDecleration.element(WebBeansConstants.WEB_BEANS_XML_NAMED_ELEMENT);
 1714               String name = element.getTextTrim();
 1715   
 1716               if (name != null && !name.equals(""))
 1717               {
 1718                   component.setName(name);
 1719               }
 1720               else
 1721               {
 1722                   component.setName(WebBeansUtil.getSimpleWebBeanDefaultName(component.getReturnType().getName()));
 1723               }
 1724           }
 1725           else
 1726           {
 1727               DefinitionUtil.defineName(component, component.getReturnType().getDeclaredAnnotations(), WebBeansUtil.getSimpleWebBeanDefaultName(component.getReturnType().getSimpleName()));
 1728           }
 1729       }
 1730   
 1731       /**
 1732        * Configures the webbeans specializations.
 1733        * 
 1734        * @param component webbeans component
 1735        * @param annotationSet type-level metadata annotation set
 1736        */
 1737       private <T> void configureSpecializes(XMLManagedBean<T> component, List<Class<? extends Annotation>> annotationSet)
 1738       {
 1739           XMLDefinitionUtil.defineXMLSpecializes(component, annotationSet);
 1740       }
 1741   
 1742       /**
 1743        * Configures the interceptors simple webbeans.
 1744        * 
 1745        * @param component webbeans component
 1746        * @param annotationSet type-level metadata annotation set
 1747        */
 1748       private <T> void configureInterceptor(XMLManagedBean<T> component, List<Class<? extends Annotation>> annotationSet, List<Element> annotationElementList)
 1749       {
 1750           XMLDefinitionUtil.defineXMLInterceptors(component, annotationSet, annotationElementList, createConfigurationFailedMessage());
 1751   
 1752       }
 1753   
 1754       /**
 1755        * Configures the decorators simple webbeans.
 1756        * 
 1757        * @param component webbeans component
 1758        * @param annotationSet type-level metadata annotation set
 1759        */
 1760       private <T> void configureDecorator(XMLManagedBean<T> component, List<Class<? extends Annotation>> annotationSet, List<Element> annotationElementList, Element webBeanDecleration)
 1761       {
 1762           XMLDefinitionUtil.defineXMLDecorators(component, annotationSet, webBeanDecleration, createConfigurationFailedMessage());
 1763       }
 1764   
 1765       /**
 1766        * Configures the enterprise web bean from ejb class.
 1767        * 
 1768        * @param ejbClass ejb class
 1769        */
 1770       private void configureEJBWebBean(Class<?> ejbClass)
 1771       {
 1772           // TODO EJB Decleration
 1773       }
 1774   
 1775       /**
 1776        * Configures JMS endpoint.
 1777        * 
 1778        * @param webBeanElement element
 1779        */
 1780       private void configureJMSEndpointComponent(Element webBeanElement)
 1781       {
 1782           List<Element> childs = webBeanElement.elements();               
 1783           Element resource = webBeanElement.element(WebBeansConstants.WEB_BEANS_XML_JMS_RESOURCE);
 1784           
 1785           if(resource == null)
 1786           {
 1787               throw new WebBeansConfigurationException("Topic or Queue resource mut be defined in the XML");
 1788           }
 1789   
 1790           Element name = resource.element(WebBeansConstants.WEB_BEANS_XML_JMS_RESOURCE_NAME);
 1791           Element mappedName = resource.element(WebBeansConstants.WEB_BEANS_XML_JMS_RESOURCE_MAPPED_NAME);
 1792           
 1793           if(name== null && mappedName == null)
 1794           {
 1795               throw new WebBeansConfigurationException("Topic or Queue must define name or mapped name for the JNDI");
 1796           }
 1797           
 1798           List<Annotation> bindingTypes = new ArrayList<Annotation>();
 1799           for(Element child : childs)
 1800           {
 1801               if(child.getName() != WebBeansConstants.WEB_BEANS_XML_JMS_RESOURCE)
 1802               {
 1803                   Class<? extends Annotation> binding = (Class<Annotation>)XMLUtil.getElementJavaType(child);
 1804                   
 1805                   if(AnnotationUtil.isQualifierAnnotation(binding))
 1806                   {
 1807                       bindingTypes.add(JavassistProxyFactory.createNewAnnotationProxy(binding));                
 1808                   }                
 1809               }            
 1810           }
 1811                           
 1812           JMSType type = null;
 1813           
 1814           if(webBeanElement.getName().equals(WebBeansConstants.WEB_BEANS_XML_TOPIC_ELEMENT))
 1815           {
 1816               type = JMSType.TOPIC;
 1817           }
 1818           else
 1819           {
 1820               type = JMSType.QUEUE;
 1821           }
 1822           
 1823           
 1824           String jndiName = name == null ? null : name.getTextTrim();
 1825           String mapName = mappedName== null ? null : mappedName.getTextTrim();
 1826           
 1827           
 1828           JMSModel model = new JMSModel(type,jndiName,mapName);        
 1829           JMSManager.getInstance().addJmsModel(model);
 1830           
 1831           for(Annotation ann : bindingTypes)
 1832           {
 1833               model.addBinding(ann);
 1834           }
 1835           
 1836           //Adding JMS Beans
 1837           OpenWebBeansJmsPlugin plugin = PluginLoader.getInstance().getJmsPlugin();
 1838           BeanManagerImpl.getManager().addBean(plugin.getJmsBean(model));
 1839       }
 1840   
 1841       /**
 1842        * Cofigures the initial value of the given field.
 1843        * 
 1844        * @param component webbeans component
 1845        * @param field field of the webbean
 1846        * @param child child element that declares field
 1847        * @param isValueElement is it applicable for value setting
 1848        */
 1849       private <T> void configureFieldValues(XMLManagedBean<T> component, Field field, Element child, boolean isValueElement)
 1850       {
 1851           if (isValueElement)
 1852           {
 1853               String errorMessage = createConfigurationFailedMessage() + "Field value of field name : " + field.getName() + " is not applicable for initial value assignment";
 1854   
 1855               /* Field type */
 1856               Class<?> fieldType = field.getType();
 1857   
 1858               String value = child.getTextTrim();
 1859   
 1860               try
 1861               {
 1862   
 1863                   if (!ClassUtil.isInValueTypes(fieldType))
 1864                   {
 1865                       throw new WebBeansConfigurationException(createConfigurationFailedMessage() + "Field type with field name : " + field.getName() + " is not compatible for initial value assignment");
 1866                   }
 1867                   
 1868                   /*Primitive type*/
 1869                   if (ClassUtil.isPrimitive(fieldType) || ClassUtil.isPrimitiveWrapper(fieldType)) 
 1870                   {
 1871                       Object objVal = null;
 1872   
 1873                       if ((objVal = ClassUtil.isValueOkForPrimitiveOrWrapper(fieldType, value)) != null)
 1874                       {
 1875                           component.addFieldValue(field, objVal);
 1876   
 1877                       }
 1878                       else
 1879                       {
 1880                           throw new WebBeansConfigurationException(errorMessage);
 1881                       }
 1882   
 1883                   }
 1884                   /* Enumeration value */
 1885                   else if (ClassUtil.isEnum(fieldType))
 1886                   {
 1887                       Enum enumValue = ClassUtil.isValueOkForEnum(fieldType, value);
 1888   
 1889                       if (enumValue == null)
 1890                       {
 1891                           throw new WebBeansConfigurationException(errorMessage);
 1892                       }
 1893   
 1894                       component.addFieldValue(field, enumValue);
 1895   
 1896                   }
 1897                   /* String value */
 1898                   else if (fieldType.equals(String.class))
 1899                   {
 1900                       component.addFieldValue(field, value);
 1901   
 1902                   }
 1903                   
 1904                   /*
 1905                    * Date, Time, Sql Date,
 1906                    * Time stamp, Calendar
 1907                    * value
 1908                    */                
 1909                   else if (fieldType.equals(Date.class)
 1910                           || fieldType.equals(java.sql.Date.class) || fieldType.equals(Time.class) || fieldType.equals(Timestamp.class))
 1911                   {
 1912                       Date date = ClassUtil.isValueOkForDate(value);
 1913   
 1914                       if (date == null)
 1915                       {
 1916                           throw new WebBeansConfigurationException(errorMessage);
 1917                       }
 1918                       else
 1919                       {
 1920                           component.addFieldValue(field, date);
 1921                       }
 1922   
 1923                   }
 1924                   else if (fieldType.equals(Calendar.class))
 1925                   {
 1926                       Calendar calendar = ClassUtil.isValueOkForCalendar(value);
 1927   
 1928                       if (calendar == null)
 1929                       {
 1930                           throw new WebBeansConfigurationException(errorMessage);
 1931                       }
 1932                       else
 1933                       {
 1934                           component.addFieldValue(field, calendar);
 1935                       }
 1936   
 1937                   }
 1938                   /*
 1939                    * BigDecimal
 1940                    * or
 1941                    * BigInteger
 1942                    */                
 1943                   else if (fieldType.equals(BigDecimal.class) || fieldType.equals(BigInteger.class)) 
 1944                   {
 1945                       Object bigValue = ClassUtil.isValueOkForBigDecimalOrInteger(fieldType, value);
 1946   
 1947                       if (bigValue == null)
 1948                       {
 1949                           throw new WebBeansConfigurationException(errorMessage);
 1950                       }
 1951                       else
 1952                       {
 1953                           component.addFieldValue(field, bigValue);
 1954                       }
 1955   
 1956                   }
 1957                   /* Class value */
 1958                   else if (fieldType.equals(Class.class))
 1959                   {
 1960                       Class<?> clazz = ClassUtil.getClassFromName(value);
 1961   
 1962                       if (clazz == null)
 1963                       {
 1964                           throw new WebBeansConfigurationException(errorMessage);
 1965                       }
 1966                       else
 1967                       {
 1968                           component.addFieldValue(field, clazz);
 1969                       }
 1970                   }
 1971                   
 1972                   /*
 1973                    * List value
 1974                    */
 1975                   else if (List.class.isAssignableFrom(fieldType)) 
 1976                   {
 1977                       configureFieldListValue(component, field, child, errorMessage);
 1978                   }
 1979                   
 1980                   /* Set value */
 1981                   else if (Set.class.isAssignableFrom(fieldType)) 
 1982                   {
 1983                       configureFieldSetValue(component, field, child, errorMessage);
 1984                   }
 1985   
 1986               }
 1987               catch (ParseException e)
 1988               {
 1989                   throw new WebBeansConfigurationException(errorMessage, e);
 1990               }
 1991           }
 1992       }
 1993   
 1994       /**
 1995        * Configures the xml field with {@link List} type.
 1996        * 
 1997        * @param component xml component
 1998        * @param field list field
 1999        * @param child list field xml element
 2000        * @param errorMessage error message
 2001        */
 2002       private void configureFieldListValue(XMLManagedBean<?> component, Field field, Element child, String errorMessage)
 2003       {
 2004           boolean isString = false;
 2005           boolean isEnum = false;
 2006           boolean isClazz = false;
 2007           Type type = field.getGenericType();
 2008           Class<?> argClazz = null;
 2009           List list = null;
 2010   
 2011           /*
 2012            * Type must be parametrized type
 2013            * to mark type
 2014            */        
 2015           if (type instanceof ParameterizedType) 
 2016           {
 2017               ParameterizedType pt = (ParameterizedType) type;
 2018               Type arg = pt.getActualTypeArguments()[0];
 2019   
 2020               if (ClassUtil.isFirstParametricTypeArgGeneric(pt))
 2021               {
 2022                   throw new WebBeansConfigurationException(createConfigurationFailedMessage() + "List field type with field name : " + field.getName() + " must be declared as ParametrizedType " + "but parametric type can not be TypeVariable or Wildcard Type");
 2023               }
 2024   
 2025               else
 2026               {
 2027                   argClazz = (Class<?>) arg;
 2028   
 2029                   if (argClazz.equals(String.class))
 2030                   {
 2031                       isString = true;
 2032                       list = new ArrayList<String>();
 2033                   }
 2034                   else if (Enum.class.isAssignableFrom(argClazz))
 2035                   {
 2036                       isEnum = true;
 2037                       list = new ArrayList<Enum>();
 2038                   }
 2039                   else if (argClazz.equals(Class.class))
 2040                   {
 2041                       isClazz = true;
 2042                       list = new ArrayList<Class>();
 2043                   }
 2044               }
 2045           }
 2046           else
 2047           {
 2048               throw new WebBeansConfigurationException(createConfigurationFailedMessage() + "List field type with field name : " + field.getName() + " must be declared as ParametrizedType");
 2049           }
 2050   
 2051           List<Element> valueElements = child.elements();
 2052           for (Element valueElement : valueElements)
 2053           {
 2054               String value = valueElement.getTextTrim();
 2055               if (isString)
 2056               {
 2057                   list.add(value);
 2058               }
 2059               else if (isEnum)
 2060               {
 2061                   Enum en = ClassUtil.isValueOkForEnum(argClazz, value);
 2062                   if (en == null)
 2063                   {
 2064                       throw new WebBeansConfigurationException(errorMessage);
 2065                   }
 2066                   else
 2067                   {
 2068                       list.add(en);
 2069                   }
 2070               }
 2071               else if (isClazz)
 2072               {
 2073                   Class<?> clazz = ClassUtil.getClassFromName(value);
 2074   
 2075                   if (clazz == null)
 2076                   {
 2077                       throw new WebBeansConfigurationException(errorMessage);
 2078                   }
 2079                   else
 2080                   {
 2081                       list.add(clazz);
 2082                   }
 2083               }
 2084           }
 2085   
 2086           component.addFieldValue(field, list);
 2087       }
 2088   
 2089       /**
 2090        * Configures the xml field with {@link Set} type.
 2091        * 
 2092        * @param component xml component
 2093        * @param field list field
 2094        * @param child list field xml element
 2095        * @param errorMessage error message
 2096        */
 2097       private void configureFieldSetValue(XMLManagedBean<?> component, Field field, Element child, String errorMessage)
 2098       {
 2099           boolean isString = false;
 2100           boolean isEnum = false;
 2101           boolean isClazz = false;
 2102           Type type = field.getGenericType();
 2103           Class<?> argClazz = null;
 2104           Set set = null;
 2105   
 2106           /*
 2107            * Type must be parametrized type
 2108            * to mark type
 2109            */        
 2110           if (type instanceof ParameterizedType)
 2111           {
 2112               ParameterizedType pt = (ParameterizedType) type;
 2113               Type arg = pt.getActualTypeArguments()[0];
 2114   
 2115               if (ClassUtil.isFirstParametricTypeArgGeneric(pt))
 2116               {
 2117                   throw new WebBeansConfigurationException(createConfigurationFailedMessage() + "Set field type with field name : " + field.getName() + " must be declared as ParametrizedType " + "but parametric type can not be TypeVariable or Wildcard Type");
 2118               }
 2119   
 2120               else
 2121               {
 2122                   argClazz = (Class<?>) arg;
 2123   
 2124                   if (argClazz.equals(String.class))
 2125                   {
 2126                       isString = true;
 2127                       set = new HashSet<String>();
 2128                   }
 2129                   else if (Enum.class.isAssignableFrom(argClazz))
 2130                   {
 2131                       isEnum = true;
 2132                       set = new HashSet<Enum>();
 2133                   }
 2134                   else if (argClazz.equals(Class.class))
 2135                   {
 2136                       isClazz = true;
 2137                       set = new HashSet<Class>();
 2138                   }
 2139               }
 2140           }
 2141           else
 2142           {
 2143               throw new WebBeansConfigurationException(createConfigurationFailedMessage() + "Set field type with field name : " + field.getName() + " must be declared as ParametrizedType");
 2144           }
 2145   
 2146           List<Element> valueElements = child.elements();
 2147           for (Element valueElement : valueElements)
 2148           {
 2149               String value = valueElement.getTextTrim();
 2150               if (isString)
 2151               {
 2152                   set.add(value);
 2153               }
 2154               else if (isEnum)
 2155               {
 2156                   Enum en = ClassUtil.isValueOkForEnum(argClazz, value);
 2157                   if (en == null)
 2158                   {
 2159                       throw new WebBeansConfigurationException(errorMessage);
 2160                   }
 2161                   else
 2162                   {
 2163                       set.add(en);
 2164                   }
 2165               }
 2166               else if (isClazz)
 2167               {
 2168                   Class<?> clazz = ClassUtil.getClassFromName(value);
 2169   
 2170                   if (clazz == null)
 2171                   {
 2172                       throw new WebBeansConfigurationException(errorMessage);
 2173                   }
 2174                   else
 2175                   {
 2176                       set.add(clazz);
 2177                   }
 2178               }
 2179           }
 2180   
 2181           component.addFieldValue(field, set);
 2182       }
 2183   
 2184       /**
 2185        * Gets error message for XML parsing of the current XML file.
 2186        * 
 2187        * @return the error messages
 2188        */
 2189       private String createConfigurationFailedMessage()
 2190       {
 2191           return "WebBeans XML configuration defined in " + CURRENT_SCAN_FILE_NAME + " is failed. Reason is : ";
 2192       }
 2193   
 2194   }

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