PageRenderTime 39ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/jboss-as-7.1.1.Final/ejb3/src/main/java/org/jboss/as/ejb3/component/stateful/StatefulSessionComponentCreateService.java

#
Java | 183 lines | 127 code | 26 blank | 30 comment | 3 complexity | d313adc79a9caf8699c989a2e35cacab MD5 | raw file
Possible License(s): LGPL-2.1, Apache-2.0
  1. /*
  2. * JBoss, Home of Professional Open Source.
  3. * Copyright 2011, Red Hat, Inc., and individual contributors
  4. * as indicated by the @author tags. See the copyright.txt file in the
  5. * distribution for a 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.stateful;
  23. import java.lang.reflect.Method;
  24. import java.util.Set;
  25. import org.jboss.as.clustering.ClassLoaderAwareClassResolver;
  26. import org.jboss.as.ee.component.BasicComponent;
  27. import org.jboss.as.ee.component.ComponentConfiguration;
  28. import org.jboss.as.ee.component.TCCLInterceptor;
  29. import org.jboss.as.ejb3.cache.CacheFactory;
  30. import org.jboss.as.ejb3.cache.CacheInfo;
  31. import org.jboss.as.ejb3.component.DefaultAccessTimeoutService;
  32. import org.jboss.as.ejb3.component.InvokeMethodOnTargetInterceptor;
  33. import org.jboss.as.ejb3.component.interceptors.CurrentInvocationContextInterceptor;
  34. import org.jboss.as.ejb3.component.session.SessionBeanComponentCreateService;
  35. import org.jboss.as.ejb3.deployment.ApplicationExceptions;
  36. import org.jboss.ejb.client.SessionID;
  37. import org.jboss.invocation.ImmediateInterceptorFactory;
  38. import org.jboss.invocation.InterceptorFactory;
  39. import org.jboss.invocation.Interceptors;
  40. import org.jboss.marshalling.MarshallingConfiguration;
  41. import org.jboss.marshalling.ModularClassResolver;
  42. import org.jboss.marshalling.reflect.ReflectiveCreator;
  43. import org.jboss.marshalling.reflect.SunReflectiveCreator;
  44. import org.jboss.msc.inject.Injector;
  45. import org.jboss.msc.value.InjectedValue;
  46. /**
  47. * @author Stuart Douglas
  48. */
  49. public class StatefulSessionComponentCreateService extends SessionBeanComponentCreateService {
  50. private final InterceptorFactory afterBegin;
  51. private final Method afterBeginMethod;
  52. private final InterceptorFactory afterCompletion;
  53. private final Method afterCompletionMethod;
  54. private final InterceptorFactory beforeCompletion;
  55. private final Method beforeCompletionMethod;
  56. private final InterceptorFactory prePassivate;
  57. private final InterceptorFactory postActivate;
  58. private final StatefulTimeoutInfo statefulTimeout;
  59. private final CacheInfo cache;
  60. private final MarshallingConfiguration marshallingConfiguration;
  61. private final InjectedValue<DefaultAccessTimeoutService> defaultAccessTimeoutService = new InjectedValue<DefaultAccessTimeoutService>();
  62. private final InterceptorFactory ejb2XRemoveMethod;
  63. @SuppressWarnings("rawtypes")
  64. private final InjectedValue<CacheFactory> cacheFactory = new InjectedValue<CacheFactory>();
  65. private final Set<Object> serializableInterceptorContextKeys;
  66. /**
  67. * Construct a new instance.
  68. *
  69. * @param componentConfiguration the component configuration
  70. */
  71. public StatefulSessionComponentCreateService(final ComponentConfiguration componentConfiguration, final ApplicationExceptions ejbJarConfiguration) {
  72. super(componentConfiguration, ejbJarConfiguration);
  73. final StatefulComponentDescription componentDescription = (StatefulComponentDescription) componentConfiguration.getComponentDescription();
  74. final InterceptorFactory tcclInterceptorFactory = new ImmediateInterceptorFactory(new TCCLInterceptor(componentConfiguration.getModuleClassLoader()));
  75. final InterceptorFactory namespaceContextInterceptorFactory = componentConfiguration.getNamespaceContextInterceptorFactory();
  76. this.afterBeginMethod = componentDescription.getAfterBegin();
  77. this.afterBegin = (this.afterBeginMethod != null) ? Interceptors.getChainedInterceptorFactory(tcclInterceptorFactory, namespaceContextInterceptorFactory, CurrentInvocationContextInterceptor.FACTORY, invokeMethodOnTarget(this.afterBeginMethod)) : null;
  78. this.afterCompletionMethod = componentDescription.getAfterCompletion();
  79. this.afterCompletion = (this.afterCompletionMethod != null) ? Interceptors.getChainedInterceptorFactory(tcclInterceptorFactory, namespaceContextInterceptorFactory, CurrentInvocationContextInterceptor.FACTORY, invokeMethodOnTarget(this.afterCompletionMethod)) : null;
  80. this.beforeCompletionMethod = componentDescription.getBeforeCompletion();
  81. this.beforeCompletion = (this.beforeCompletionMethod != null) ? Interceptors.getChainedInterceptorFactory(tcclInterceptorFactory, namespaceContextInterceptorFactory, CurrentInvocationContextInterceptor.FACTORY, invokeMethodOnTarget(this.beforeCompletionMethod)) : null;
  82. this.prePassivate = Interceptors.getChainedInterceptorFactory(componentConfiguration.getPrePassivateInterceptors());
  83. this.postActivate = Interceptors.getChainedInterceptorFactory(componentConfiguration.getPostActivateInterceptors());
  84. this.statefulTimeout = componentDescription.getStatefulTimeout();
  85. //the interceptor chain for EJB e.x remove methods
  86. this.ejb2XRemoveMethod = Interceptors.getChainedInterceptorFactory(StatefulSessionSynchronizationInterceptor.factory(componentDescription.getTransactionManagementType()), new ImmediateInterceptorFactory(new StatefulRemoveInterceptor(false)), Interceptors.getTerminalInterceptorFactory());
  87. this.cache = componentDescription.getCache();
  88. this.marshallingConfiguration = new MarshallingConfiguration();
  89. this.marshallingConfiguration.setSerializedCreator(new SunReflectiveCreator());
  90. this.marshallingConfiguration.setExternalizerCreator(new ReflectiveCreator());
  91. this.marshallingConfiguration.setClassResolver(new ClassLoaderAwareClassResolver(ModularClassResolver.getInstance(componentConfiguration.getModuleLoader()), componentConfiguration.getModuleClassLoader()));
  92. this.marshallingConfiguration.setSerializabilityChecker(new StatefulSessionBeanSerializabilityChecker(componentConfiguration.getComponentClass()));
  93. this.marshallingConfiguration.setClassTable(new StatefulSessionBeanClassTable());
  94. this.serializableInterceptorContextKeys = componentConfiguration.getInterceptorContextKeys();
  95. }
  96. private static InterceptorFactory invokeMethodOnTarget(final Method method) {
  97. method.setAccessible(true);
  98. return InvokeMethodOnTargetInterceptor.factory(method);
  99. }
  100. @Override
  101. protected BasicComponent createComponent() {
  102. return new StatefulSessionComponent(this);
  103. }
  104. public InterceptorFactory getAfterBegin() {
  105. return afterBegin;
  106. }
  107. public InterceptorFactory getAfterCompletion() {
  108. return afterCompletion;
  109. }
  110. public InterceptorFactory getBeforeCompletion() {
  111. return beforeCompletion;
  112. }
  113. public InterceptorFactory getPrePassivate() {
  114. return this.prePassivate;
  115. }
  116. public InterceptorFactory getPostActivate() {
  117. return this.postActivate;
  118. }
  119. public Method getAfterBeginMethod() {
  120. return afterBeginMethod;
  121. }
  122. public Method getAfterCompletionMethod() {
  123. return afterCompletionMethod;
  124. }
  125. public Method getBeforeCompletionMethod() {
  126. return beforeCompletionMethod;
  127. }
  128. public StatefulTimeoutInfo getStatefulTimeout() {
  129. return statefulTimeout;
  130. }
  131. public CacheInfo getCache() {
  132. return this.cache;
  133. }
  134. public MarshallingConfiguration getMarshallingConfiguration() {
  135. return this.marshallingConfiguration;
  136. }
  137. public DefaultAccessTimeoutService getDefaultAccessTimeoutService() {
  138. return defaultAccessTimeoutService.getValue();
  139. }
  140. Injector<DefaultAccessTimeoutService> getDefaultAccessTimeoutInjector() {
  141. return this.defaultAccessTimeoutService;
  142. }
  143. public InterceptorFactory getEjb2XRemoveMethod() {
  144. return ejb2XRemoveMethod;
  145. }
  146. public Set<Object> getSerializableInterceptorContextKeys() {
  147. return serializableInterceptorContextKeys;
  148. }
  149. @SuppressWarnings("unchecked")
  150. public CacheFactory<SessionID, StatefulSessionComponentInstance> getCacheFactory() {
  151. return (CacheFactory<SessionID, StatefulSessionComponentInstance>) this.cacheFactory.getValue();
  152. }
  153. @SuppressWarnings("rawtypes")
  154. Injector<CacheFactory> getCacheFactoryInjector() {
  155. return this.cacheFactory;
  156. }
  157. }