PageRenderTime 40ms CodeModel.GetById 17ms 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. */
  22. package org.jboss.as.ejb3.component.session;
  23. import javax.ejb.SessionBean;
  24. import org.jboss.as.ee.component.ComponentInstance;
  25. import org.jboss.as.ee.component.interceptors.InvocationType;
  26. import org.jboss.invocation.ImmediateInterceptorFactory;
  27. import org.jboss.invocation.Interceptor;
  28. import org.jboss.invocation.InterceptorContext;
  29. import org.jboss.invocation.InterceptorFactory;
  30. /**
  31. * Interceptor that invokes the {@link SessionBean#setSessionContext(javax.ejb.SessionContext)} on session beans
  32. * which implement the {@link SessionBean} interface.
  33. *
  34. * @author Stuart Douglas
  35. */
  36. public class SessionBeanSetSessionContextMethodInvocationInterceptor implements Interceptor {
  37. public static final InterceptorFactory FACTORY = new ImmediateInterceptorFactory(new SessionBeanSetSessionContextMethodInvocationInterceptor());
  38. private SessionBeanSetSessionContextMethodInvocationInterceptor() {
  39. }
  40. @Override
  41. public Object processInvocation(final InterceptorContext context) throws Exception {
  42. SessionBeanComponentInstance instance = (SessionBeanComponentInstance) context.getPrivateData(ComponentInstance.class);
  43. final InvocationType invocationType = context.getPrivateData(InvocationType.class);
  44. try {
  45. context.putPrivateData(InvocationType.class, InvocationType.DEPENDENCY_INJECTION);
  46. ((SessionBean) context.getTarget()).setSessionContext(instance.getEjbContext());
  47. } finally {
  48. context.putPrivateData(InvocationType.class, invocationType);
  49. }
  50. return context.proceed();
  51. }
  52. }