Save This Page
Home » apache-openwebbeans-1.0.0-incubating-M3-sources » org.apache.webbeans.component » [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;
   15   
   16   import java.lang.annotation.Annotation;
   17   import java.lang.reflect.Constructor;
   18   import java.lang.reflect.Type;
   19   import java.util.Set;
   20   
   21   import javax.enterprise.context.spi.CreationalContext;
   22   
   23   import org.apache.webbeans.exception.WebBeansException;
   24   
   25   /**
   26    * Implicit observable bean definition.
   27    * 
   28    * @version $Rev: 811507 $ $Date: 2009-09-04 21:18:41 +0300 (Fri, 04 Sep 2009) $
   29    */
   30   public class EventBean<T> extends AbstractBean<T>
   31   {
   32       private Type eventType = null;
   33   
   34       /**
   35        * Creates a new instance of event bean.
   36        * 
   37        * @param returnType Event class
   38        * @param eventType event type
   39        * @param definedType webbeans type
   40        */
   41       public EventBean(Class<T> returnType, Type eventType, WebBeansType definedType)
   42       {
   43           super(definedType,returnType);
   44           this.eventType = eventType;
   45       }
   46       
   47       /**
   48        * {@inheritDoc}
   49        */
   50       @Override
   51       protected T createInstance(CreationalContext<T> creationalContext)
   52       {
   53           Set<Annotation> setQualifiers = getQualifiers();
   54           Annotation[] qualifiers = new Annotation[setQualifiers.size()];
   55   
   56           qualifiers = setQualifiers.toArray(qualifiers);
   57   
   58           T instance = null;
   59   
   60           try
   61           {
   62               Constructor<T> constructor = null;
   63               constructor = returnType.getConstructor(new Class<?>[] { Annotation[].class, Type.class });
   64   
   65               instance = constructor.newInstance(new Object[] { qualifiers, eventType });
   66           }
   67           catch (Exception e)
   68           {
   69               throw new WebBeansException("Exception in creating Event implicit component for event type : " + eventType);
   70           }
   71   
   72           return instance;
   73   
   74       }
   75   
   76       /**
   77        * Returns the event type.
   78        * 
   79        * @return the eventType
   80        */
   81       public Type getEventType()
   82       {
   83           return eventType;
   84       }
   85   }

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