Home » apache-openwebbeans-1.0.0-incubating-M3-sources » org.apache.webbeans.portable.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.portable.creation;
   15   
   16   import java.util.Set;
   17   
   18   import javax.enterprise.context.spi.CreationalContext;
   19   import javax.enterprise.inject.spi.InjectionPoint;
   20   import javax.enterprise.inject.spi.Producer;
   21   
   22   import org.apache.webbeans.component.AbstractBean;
   23   
   24   /**
   25    * Abstract implementation of {@link Producer} contract.
   26    * 
   27    * @version $Rev: 791166 $ $Date: 2009-07-04 22:00:12 +0300 (Sat, 04 Jul 2009) $
   28    *
   29    * @param <T> bean type info
   30    */
   31   public abstract class AbstractProducer<T> implements Producer<T> 
   32   {
   33       /**Bean instance*/
   34       private AbstractBean<T> bean;
   35   
   36       /**
   37        * Create a new producer with given bean.
   38        * 
   39        * @param bean bean instance
   40        */
   41       protected AbstractProducer(AbstractBean<T> bean)
   42       {
   43           this.bean = bean;
   44       }
   45   
   46       /**
   47        * {@inheritDoc}
   48        */
   49       @Override
   50       public Set<InjectionPoint> getInjectionPoints()
   51       {
   52           return bean.getInjectionPoints();
   53       }
   54       
   55       /**
   56        * {@inheritDoc}
   57        */
   58       @Override
   59       public T produce(CreationalContext<T> creationalContext)
   60       {
   61           return bean.create(creationalContext);
   62       }
   63       
   64       /**
   65        * {@inheritDoc}
   66        */
   67       public void dispose(T instance)
   68       {
   69           //Do nothing as default
   70       }
   71   
   72       /**
   73        * Returns actual bean instance.
   74        * 
   75        * @param <X> bean type info
   76        * @param clazz bean type class
   77        * @return actual bean
   78        */
   79       protected <X> X getBean(Class<X> clazz)
   80       {
   81           return clazz.cast(this.bean);
   82       }
   83   }

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