Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
   * JBoss, Home of Professional Open Source
   * Copyright 2012, Red Hat, Inc., and individual contributors
   * by the @authors tag. See the copyright.txt in the distribution for a
   * full listing of individual contributors.
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
 package org.jboss.weld.injection.producer.ejb;
 import java.util.List;
 import java.util.Set;
 public class SessionBeanInjectionTarget<T> extends BeanInjectionTarget<T> {
     public static <T> SessionBeanInjectionTarget<T> of(EnhancedAnnotatedType<T> typeSessionBean<T> beanBeanManagerImpl beanManager) {
         LifecycleCallbackInvoker<T> invoker = DefaultLifecycleCallbackInvoker.of(type);
         Injector<T> injector;
         if (bean.getEjbDescriptor().isStateless()) {
             injector = new StatelessSessionBeanInjector<T>(typebeanbeanManager);
         } else {
             injector = new DefaultInjector<T>(typebeanbeanManager);
         return new SessionBeanInjectionTarget<T>(typebeanbeanManagerinjectorinvoker);
     private final SessionBean<T> bean;
     private SessionBeanInjectionTarget(EnhancedAnnotatedType<T> typeSessionBean<T> beanBeanManagerImpl beanManagerInjector<T> injectorLifecycleCallbackInvoker<T> invoker) {
         this. = bean;
     public SessionBean<T> getBean() {
         return ;
     protected Instantiator<T> initInstantiator(EnhancedAnnotatedType<T> typeBean<T> beanBeanManagerImpl beanManagerSet<InjectionPointinjectionPoints) {
         if (bean instanceof SessionBean<?>) {
             EnhancedAnnotatedType<T> implementationClass = Beans.getEjbImplementationClass((SessionBean<T>) bean);
             AbstractInstantiator<T> instantiator = null;
             if (type.equals(implementationClass)) {
                 instantiator = new DefaultInstantiator<T>(typebeanbeanManager);
             } else {
                 // Session bean subclassed by the EJB container
                 instantiator = SubclassedComponentInstantiator.forSubclassedEjb(typeimplementationClassbeanbeanManager);
             return instantiator;
         } else {
             throw new IllegalArgumentException("Cannot create SessionBeanInjectionTarget for " + bean);
     public void initializeAfterBeanDiscovery(EnhancedAnnotatedType<T> annotatedType) {
         List<Decorator<?>> decorators = .resolveDecorators(getBean().getTypes(), getBean().getQualifiers());
        if (!decorators.isEmpty()) {
            Instantiator<T> instantiator = getInstantiator();
            EnhancedAnnotatedType<T> implementationClass = Beans.getEjbImplementationClass(getBean());
            instantiator = SubclassedComponentInstantiator.forInterceptedDecoratedBean(implementationClassgetBean(), (AbstractInstantiator<T>) instantiator);
            instantiator = new SubclassDecoratorApplyingInstantiator<T>(getBeanManager().getContextId(), instantiatorgetBean(), decoratorsimplementationClass.getJavaClass());
         * We only take care of @AroundConstructor interception. The EJB container deals with the other types of interception.
    protected void buildInterceptionModel(EnhancedAnnotatedType<T> annotatedTypeAbstractInstantiator<T> instantiator) {
         * instantiator.getConstructorInjectionPoint() may represent the constructor of the SessionBean subclass which may not have annotations applied
         * Therefore, use the component class constructor instead of the one from subclass.
        EnhancedAnnotatedConstructor<T> constructor = annotatedType.getDeclaredEnhancedConstructor(instantiator.getConstructorInjectionPoint().getSignature());
        new InterceptionModelInitializer<T>(annotatedTypeconstructorgetBean()).init();
    public T produce(CreationalContext<T> ctx) {
        T result = super.produce(ctx);
        if (result instanceof ProxyObject) {
            // if decorators are applied, use SessionBeanViewMethodHandler
            ProxyObject proxy = (ProxyObjectresult;
        return result;
    public void inject(T instanceCreationalContext<T> ctx) {
        // explicitly use bean's AnnotatedType, not InjectionPoint's as this.getAnnotated()
        // may represent the annotated type for the EJB-container subclass (see SubclassedComponentDescriptor)
        getInjector().inject(instancectx.getAnnotated(), this);

This org.jboss.weld.bean.proxy.MethodHandler assures that any method invoked on a decorated org.jboss.weld.bean.SessionBean is a method that belongs to a bean type of the bean. If the methods belongs to the bean implementation and the bean implementation is not a bean type the handler tries to replace the method with the equivalent method defined on a bean type.

Jozef Hartinger
        private static final long serialVersionUID = -8038819529432133787L;
        private final Set<Class<?>> beanTypes;
            this. = Types.getRawTypes(types);
        public Object invoke(Object selfMethod thisMethodMethod proceedObject[] argsthrows Throwable {
            if (.contains(thisMethod.getDeclaringClass())) {
                return super.invoke(selfthisMethodproceedargs);
            } else {
                Method decoratedTypeMethod = getBeanTypeMethod(thisMethod);
                return super.invoke(selfdecoratedTypeMethodproceedargs);
        private Method getBeanTypeMethod(Method method) {
            for (Class<?> c : ) {
                try {
                    return c.getMethod(method.getName(), method.getParameterTypes());
                } catch (NoSuchMethodException e) {
            return method;
New to GrepCode? Check out our FAQ X