Home » apache-openwebbeans-1.0.0-incubating-M3-sources » org.apache.webbeans.component.creation » [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.component.creation;
   15   
   16   import java.util.Set;
   17   
   18   import javax.enterprise.context.spi.CreationalContext;
   19   import javax.enterprise.inject.spi.InjectionTarget;
   20   
   21   import org.apache.webbeans.component.AbstractInjectionTargetBean;
   22   import org.apache.webbeans.component.ProducerFieldBean;
   23   import org.apache.webbeans.component.ProducerMethodBean;
   24   import org.apache.webbeans.config.DefinitionUtil;
   25   
   26   /**
   27    * Abstract implementation of {@link InjectedTargetBeanCreator}.
   28    * 
   29    * @version $Rev: 791957 $ $Date: 2009-07-07 22:46:05 +0300 (Tue, 07 Jul 2009) $
   30    *
   31    * @param <T> bean class type
   32    */
   33   public abstract class AbstractInjectedTargetBeanCreator<T> extends AbstractBeanCreator<T> implements InjectedTargetBeanCreator<T>
   34   {    
   35       /**Injection target instance. Null if not set by the ProcessInjectionTarget event*/
   36       private InjectionTarget<T> injectionTarget; 
   37   
   38       /**Set or not*/
   39       private boolean injectionTargetSet = false;
   40       
   41       /**
   42        * Creates a new instance.
   43        * 
   44        * @param bean bean instance
   45        */
   46       public AbstractInjectedTargetBeanCreator(AbstractInjectionTargetBean<T> bean)
   47       {
   48           super(bean, bean.getReturnType().getDeclaredAnnotations());
   49       }
   50       
   51       /**
   52        * {@inheritDoc}
   53        */
   54       @Override
   55       public boolean isInjectionTargetSet()
   56       {
   57           return this.injectionTargetSet;
   58       }
   59       
   60       /**
   61        * {@inheritDoc}
   62        */
   63       @Override
   64       public void defineDisposalMethods()
   65       {
   66           if(isDefaultMetaDataProvider())
   67           {
   68               DefinitionUtil.defineDisposalMethods(getBean());   
   69           }
   70           else
   71           {
   72               //TODO
   73           }
   74           
   75       }
   76   
   77       /**
   78        * {@inheritDoc}
   79        */
   80       @Override
   81       public void defineInjectedFields()
   82       {
   83           if(isDefaultMetaDataProvider())
   84           {
   85               DefinitionUtil.defineInjectedFields(getBean());   
   86           }
   87           else
   88           {
   89               //TODO
   90           }
   91           
   92       }
   93   
   94       /**
   95        * {@inheritDoc}
   96        */
   97       @Override
   98       public void defineInjectedMethods()
   99       {
  100           if(isDefaultMetaDataProvider())
  101           {
  102               DefinitionUtil.defineInjectedMethods(getBean());
  103           }
  104           
  105       }
  106   
  107       /**
  108        * {@inheritDoc}
  109        */
  110       @Override
  111       public void defineObserverMethods()
  112       {   
  113           if(isDefaultMetaDataProvider())
  114           {
  115               DefinitionUtil.defineObserverMethods(getBean(), getBean().getReturnType());
  116           }
  117           else
  118           {
  119               //TODO
  120           }
  121       }
  122   
  123       /**
  124        * {@inheritDoc}
  125        */
  126       @Override
  127       public Set<ProducerFieldBean<?>> defineProducerFields()
  128       {
  129           if(isDefaultMetaDataProvider())
  130           {
  131               return DefinitionUtil.defineProduerFields(getBean());
  132           }
  133           else
  134           {
  135               return null;
  136           }
  137       }
  138   
  139       /**
  140        * {@inheritDoc}
  141        */
  142       @Override
  143       public Set<ProducerMethodBean<?>> defineProducerMethods()
  144       {
  145           if(isDefaultMetaDataProvider())
  146           {
  147               return DefinitionUtil.defineProducerMethods(getBean());
  148           }
  149           else
  150           {
  151               return null;
  152           }
  153       }
  154       
  155       /**
  156        * Return type-safe bean instance.
  157        */
  158       public AbstractInjectionTargetBean<T> getBean()
  159       {
  160           return (AbstractInjectionTargetBean<T>)super.getBean();
  161       }
  162   
  163       /**
  164        * {@inheritDoc}
  165        */
  166       @Override
  167       public InjectionTarget<T> getInjectedTarget()
  168       {
  169           return this.injectionTarget;
  170       }
  171   
  172       /**
  173        * {@inheritDoc}
  174        */
  175       @Override
  176       public void setInjectedTarget(InjectionTarget<T> injectionTarget)
  177       {
  178           this.injectionTarget = injectionTarget;
  179           this.injectionTargetSet = true;
  180       }
  181   
  182       /**
  183        * {@inheritDoc}
  184        */
  185       @Override
  186       public void inject(T instance, CreationalContext<T> ctx)
  187       {
  188           this.injectionTarget.inject(instance, ctx);
  189       }
  190   
  191       /**
  192        * {@inheritDoc}
  193        */
  194       @Override
  195       public void postConstruct(T instance)
  196       {
  197           this.injectionTarget.postConstruct(instance);
  198       }
  199   
  200       /**
  201        * {@inheritDoc}
  202        */
  203       @Override
  204       public void preDestroy(T instance)
  205       {
  206           this.injectionTarget.preDestroy(instance);
  207       }
  208   
  209   }

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