Home » apache-openwebbeans-1.0.0-incubating-M3-sources » org.apache.webbeans.ejb.util » [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.ejb.util;
   15   
   16   import java.lang.annotation.Annotation;
   17   
   18   import javax.decorator.Decorator;
   19   import javax.enterprise.context.ApplicationScoped;
   20   import javax.enterprise.context.Dependent;
   21   import javax.enterprise.inject.spi.SessionBeanType;
   22   import javax.interceptor.Interceptor;
   23   
   24   import org.apache.webbeans.ejb.EjbConstants;
   25   import org.apache.webbeans.ejb.component.EjbBean;
   26   import org.apache.webbeans.exception.WebBeansConfigurationException;
   27   import org.apache.webbeans.util.AnnotationUtil;
   28   import org.apache.webbeans.util.Asserts;
   29   import org.apache.webbeans.util.ClassUtil;
   30   
   31   /**
   32    * Validates session beans.
   33    * 
   34    * @version $Rev: 811507 $ $Date: 2009-09-04 21:18:41 +0300 (Fri, 04 Sep 2009) $
   35    */
   36   public final class EjbValidator
   37   {
   38       // No-instaniate
   39       private EjbValidator()
   40       {
   41           // Empty
   42       }
   43   
   44       /**
   45        * Validates session bean's scope.
   46        * 
   47        * @param ejbBean ejb bean
   48        */
   49       public static void validateEjbScopeType(EjbBean<?> ejbBean)
   50       {
   51           Asserts.assertNotNull(ejbBean, "Session Bean can not be null");
   52   
   53           if (ejbBean.getScope() == null)
   54           {
   55               throw new NullPointerException("Session Bean scope can not be null");
   56           }
   57   
   58           if (ejbBean.getEjbType() == null)
   59           {
   60               throw new NullPointerException("Session Bean type can not be null. It must be one of @Stateless, @Stateful, @Singleton");
   61           }
   62   
   63           if (ejbBean.getEjbType().equals(SessionBeanType.STATELESS))
   64           {
   65               if (!ejbBean.getScope().equals(Dependent.class))
   66               {
   67                   throw new WebBeansConfigurationException("Stateless Session Bean class : " + ejbBean.getReturnType() + " " + "can not define scope other than @Dependent");
   68               }
   69           }
   70           else if (ejbBean.getEjbType().equals(SessionBeanType.SINGLETON))
   71           {
   72               if (!(ejbBean.getScope().equals(Dependent.class) || ejbBean.getScope().equals(ApplicationScoped.class)))
   73               {
   74                   throw new WebBeansConfigurationException("Singleton Session Bean class : " + ejbBean.getReturnType() + " " + "can not define scope other than @Dependent or @ApplicationScoped");
   75               }
   76           }
   77       }
   78   
   79       /**
   80        * Validates session bean decorator/interceptor conditions.
   81        * 
   82        * @param ejbClass ejb bean class
   83        */
   84       public static void validateDecoratorOrInterceptor(Class<?> ejbClass)
   85       {
   86           Asserts.assertNotNull(ejbClass, "ejbClass parameter can not be null");
   87   
   88           if (AnnotationUtil.isAnnotationExistOnClass(ejbClass, Decorator.class))
   89           {
   90               throw new WebBeansConfigurationException(EjbConstants.EJB_WEBBEANS_ERROR_CLASS_PREFIX + ejbClass.getName() + " can not annotated with @Decorator");
   91   
   92           }
   93   
   94           if (AnnotationUtil.isAnnotationExistOnClass(ejbClass, Interceptor.class))
   95           {
   96               throw new WebBeansConfigurationException(EjbConstants.EJB_WEBBEANS_ERROR_CLASS_PREFIX + ejbClass.getName() + " can not annotated with @Interceptor");
   97           }
   98       }
   99       
  100       /**
  101        * Check generic type conditions.
  102        * @param ejbClass ebj class
  103        * @param scopeType scope type
  104        */
  105       public static void validateGenericBeanType(Class<?> ejbClass, Class<? extends Annotation> scopeType)
  106       {
  107           Asserts.assertNotNull(ejbClass, "ejbClass parameter can not be null");
  108           Asserts.assertNotNull(ejbClass, "scopeType parameter can not be null");
  109           
  110           if(ClassUtil.isDefinitionConstainsTypeVariables(ejbClass))
  111           {
  112               if(!scopeType.equals(Dependent.class))
  113               {
  114                   throw new WebBeansConfigurationException("Ejb generic bean class : " + ejbClass.getName() + "scope must be @Dependent");
  115               }
  116           }
  117       }
  118   
  119   }

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