PageRenderTime 48ms CodeModel.GetById 31ms app.highlight 16ms RepoModel.GetById 0ms app.codeStats 0ms

/jboss-as-7.1.1.Final/ejb3/src/main/java/org/jboss/as/ejb3/component/session/SessionBeanSetSessionContextMethodInvocationInterceptor.java

#
Java | 58 lines | 25 code | 6 blank | 27 comment | 0 complexity | 5c9966f5ba93aed6acabe04f90695e83 MD5 | raw file
Possible License(s): LGPL-2.1, Apache-2.0
 1/*
 2 * JBoss, Home of Professional Open Source
 3 * Copyright 2010, Red Hat Inc., and individual contributors as indicated
 4 * by the @authors tag. See the copyright.txt in the distribution for a
 5 * full listing of individual contributors.
 6 *
 7 * This is free software; you can redistribute it and/or modify it
 8 * under the terms of the GNU Lesser General Public License as
 9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this software; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 */
22package org.jboss.as.ejb3.component.session;
23
24import javax.ejb.SessionBean;
25
26import org.jboss.as.ee.component.ComponentInstance;
27import org.jboss.as.ee.component.interceptors.InvocationType;
28import org.jboss.invocation.ImmediateInterceptorFactory;
29import org.jboss.invocation.Interceptor;
30import org.jboss.invocation.InterceptorContext;
31import org.jboss.invocation.InterceptorFactory;
32
33/**
34 * Interceptor that invokes the {@link SessionBean#setSessionContext(javax.ejb.SessionContext)} on session beans
35 * which implement the {@link SessionBean} interface.
36 *
37 * @author Stuart Douglas
38 */
39public class SessionBeanSetSessionContextMethodInvocationInterceptor implements Interceptor {
40
41    public static final InterceptorFactory FACTORY = new ImmediateInterceptorFactory(new SessionBeanSetSessionContextMethodInvocationInterceptor());
42
43    private SessionBeanSetSessionContextMethodInvocationInterceptor() {
44    }
45
46    @Override
47    public Object processInvocation(final InterceptorContext context) throws Exception {
48        SessionBeanComponentInstance instance = (SessionBeanComponentInstance) context.getPrivateData(ComponentInstance.class);
49        final InvocationType invocationType = context.getPrivateData(InvocationType.class);
50        try {
51            context.putPrivateData(InvocationType.class, InvocationType.DEPENDENCY_INJECTION);
52            ((SessionBean) context.getTarget()).setSessionContext(instance.getEjbContext());
53        } finally {
54            context.putPrivateData(InvocationType.class, invocationType);
55        }
56        return context.proceed();
57    }
58}