Home » apache-openwebbeans-1.0.0-incubating-M3-sources » org.apache.webbeans.inject.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.inject.xml;
   15   
   16   import java.lang.annotation.Annotation;
   17   import java.lang.reflect.Constructor;
   18   import java.util.ArrayList;
   19   import java.util.Iterator;
   20   import java.util.List;
   21   
   22   import javax.enterprise.context.spi.CreationalContext;
   23   
   24   import org.apache.webbeans.component.AbstractBean;
   25   import org.apache.webbeans.exception.WebBeansException;
   26   import org.apache.webbeans.inject.InjectableConstructor;
   27   import org.apache.webbeans.util.Asserts;
   28   
   29   /**
   30    * Defines the injectable constructor.
   31    * @param <T> type of the constructor
   32    */
   33   public class XMLInjectableConstructor<T> extends InjectableConstructor<T>
   34   {
   35       /**Constructor parameter injection models defined in the xml*/
   36       private List<XMLInjectionPointModel> injectionPointModelList = new ArrayList<XMLInjectionPointModel>();
   37   
   38       /**
   39        * Defines new <code>XMLInjectableConstructor</code> instance.
   40        * @param constructor bean constructor
   41        * @param owner constructor owner beans
   42        */
   43       public XMLInjectableConstructor(Constructor<T> constructor, AbstractBean<?> owner,CreationalContext<?> creationalContext)
   44       {
   45           super(constructor, owner,creationalContext);
   46       }
   47   
   48       /*
   49        * (non-Javadoc)
   50        * @see org.apache.webbeans.inject.InjectableConstructor#doInjection()
   51        */
   52       @Override
   53       public T doInjection()
   54       {
   55           T instance = null;
   56           List<Object> list = new ArrayList<Object>();
   57   
   58           Iterator<XMLInjectionPointModel> it = this.injectionPointModelList.iterator();
   59           while (it.hasNext())
   60           {
   61               XMLInjectionPointModel model = it.next();
   62               Annotation[] anns = new Annotation[model.getBindingTypes().size()];
   63               anns = model.getBindingTypes().toArray(anns);
   64   
   65               //list.add(inject(model.getInjectionGenericType(), anns));
   66           }
   67   
   68           try
   69           {
   70               if(!con.isAccessible())
   71               {
   72                   con.setAccessible(true);
   73               }
   74               
   75               instance = con.newInstance(list.toArray());
   76   
   77           }
   78           catch (Exception e)
   79           {
   80               e.printStackTrace();
   81               throw new WebBeansException(e);
   82           }
   83   
   84           return instance;
   85       }
   86   
   87       /**
   88        * @return the constructor
   89        */
   90       public Constructor<T> getConstructor()
   91       {
   92           return con;
   93       }
   94       
   95       /**
   96        * Adds new constructor parameter injection model.
   97        * @param model new injection point model for constructor parameter
   98        */
   99       public void addInjectionPointModel(XMLInjectionPointModel model)
  100       {
  101           Asserts.assertNotNull(model, "model parameter can not be null");
  102           this.injectionPointModelList.add(model);
  103       }
  104   }

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