Home » apache-openwebbeans-1.0.0-incubating-M3-sources » org.apache.webbeans.decorator » [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.decorator;
   15   
   16   import java.lang.annotation.Annotation;
   17   import java.lang.reflect.Type;
   18   import java.util.ArrayList;
   19   import java.util.Collections;
   20   import java.util.HashSet;
   21   import java.util.Iterator;
   22   import java.util.List;
   23   import java.util.Set;
   24   
   25   import javax.enterprise.inject.spi.Decorator;
   26   
   27   import org.apache.webbeans.annotation.CurrentLiteral;
   28   import org.apache.webbeans.component.AbstractBean;
   29   import org.apache.webbeans.container.BeanManagerImpl;
   30   import org.apache.webbeans.decorator.xml.WebBeansXMLDecorator;
   31   import org.apache.webbeans.inject.xml.XMLInjectionPointModel;
   32   import org.apache.webbeans.logger.WebBeansLogger;
   33   
   34   public final class WebBeansDecoratorConfig
   35   {
   36       private static WebBeansLogger logger = WebBeansLogger.getLogger(WebBeansDecoratorConfig.class);
   37   
   38       private WebBeansDecoratorConfig()
   39       {
   40   
   41       }
   42   
   43       public static <T> void configureDecoratorClass(AbstractBean<T> delegate)
   44       {
   45           logger.info("Configuring the Web Beans Annoatated Decorator Class : " + delegate.getReturnType().getName() + " started");
   46   
   47           WebBeansDecorator<T> decorator = new WebBeansDecorator<T>(delegate);
   48   
   49           logger.info("Configuring the Web Beans Annotated Decorator Class : " + delegate.getReturnType() + " ended");
   50   
   51           BeanManagerImpl.getManager().addDecorator(decorator);
   52       }
   53   
   54       public static <T> void configureXMLDecoratorClass(AbstractBean<T> delegate, XMLInjectionPointModel model)
   55       {
   56           logger.info("Configuring the Web Beans XML based Decorator Class : " + delegate.getReturnType().getName() + " started");
   57   
   58           WebBeansXMLDecorator<T> decorator = new WebBeansXMLDecorator<T>(delegate, model);
   59   
   60           logger.info("Configuring the Web Beans XML based Decorator Class : " + delegate.getReturnType() + " ended");
   61   
   62           BeanManagerImpl.getManager().addDecorator(decorator);
   63       }
   64   
   65       public static void configureDecarotors(AbstractBean<?> component, Object instance)
   66       {
   67           Set<Annotation> qualifiers = component.getQualifiers();
   68           Annotation[] anns = new Annotation[qualifiers.size()];
   69           anns = qualifiers.toArray(anns);
   70   
   71           List<Decorator<?>> decoratorList = BeanManagerImpl.getManager().resolveDecorators(component.getTypes(), anns);
   72           Iterator<Decorator<?>> itList = decoratorList.iterator();
   73   
   74           while (itList.hasNext())
   75           {
   76               WebBeansDecorator<?> decorator = (WebBeansDecorator<?>) itList.next();
   77   
   78               Object decoratorInstance = BeanManagerImpl.getManager().getInstance(decorator);
   79   
   80               decorator.setInjections(decoratorInstance);
   81               decorator.setDelegate(decoratorInstance, instance);
   82   
   83               component.getDecoratorStack().add(decoratorInstance);
   84           }
   85       }
   86   
   87       private static Set<Decorator<?>> getWebBeansDecorators()
   88       {
   89           return Collections.unmodifiableSet(BeanManagerImpl.getManager().getDecorators());
   90       }
   91   
   92       public static Set<Decorator<?>> findDeployedWebBeansDecorator(Set<Type> apiType, Annotation... anns)
   93       {
   94           Set<Decorator<?>> set = new HashSet<Decorator<?>>();
   95   
   96           Iterator<Decorator<?>> it = getWebBeansDecorators().iterator();
   97           WebBeansDecorator<?> decorator = null;
   98   
   99           List<Class<? extends Annotation>> bindingTypes = new ArrayList<Class<? extends Annotation>>();
  100           Set<Annotation> listAnnot = new HashSet<Annotation>();
  101           for (Annotation ann : anns)
  102           {
  103               bindingTypes.add(ann.annotationType());
  104               listAnnot.add(ann);
  105           }
  106   
  107           if (listAnnot.isEmpty())
  108           {
  109               listAnnot.add(new CurrentLiteral());
  110           }
  111   
  112           while (it.hasNext())
  113           {
  114               decorator = (WebBeansDecorator<?>) it.next();
  115   
  116               if (decorator.isDecoratorMatch(apiType, listAnnot))
  117               {
  118                   set.add(decorator);
  119               }
  120           }
  121   
  122           return set;
  123   
  124       }
  125   
  126   }

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