PageRenderTime 35ms CodeModel.GetById 17ms app.highlight 16ms RepoModel.GetById 0ms 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
 23package org.jboss.as.ejb3.component.stateful;
 24
 25import java.lang.reflect.Method;
 26import java.util.Set;
 27
 28import org.jboss.as.clustering.ClassLoaderAwareClassResolver;
 29import org.jboss.as.ee.component.BasicComponent;
 30import org.jboss.as.ee.component.ComponentConfiguration;
 31import org.jboss.as.ee.component.TCCLInterceptor;
 32import org.jboss.as.ejb3.cache.CacheFactory;
 33import org.jboss.as.ejb3.cache.CacheInfo;
 34import org.jboss.as.ejb3.component.DefaultAccessTimeoutService;
 35import org.jboss.as.ejb3.component.InvokeMethodOnTargetInterceptor;
 36import org.jboss.as.ejb3.component.interceptors.CurrentInvocationContextInterceptor;
 37import org.jboss.as.ejb3.component.session.SessionBeanComponentCreateService;
 38import org.jboss.as.ejb3.deployment.ApplicationExceptions;
 39import org.jboss.ejb.client.SessionID;
 40import org.jboss.invocation.ImmediateInterceptorFactory;
 41import org.jboss.invocation.InterceptorFactory;
 42import org.jboss.invocation.Interceptors;
 43import org.jboss.marshalling.MarshallingConfiguration;
 44import org.jboss.marshalling.ModularClassResolver;
 45import org.jboss.marshalling.reflect.ReflectiveCreator;
 46import org.jboss.marshalling.reflect.SunReflectiveCreator;
 47import org.jboss.msc.inject.Injector;
 48import org.jboss.msc.value.InjectedValue;
 49
 50/**
 51 * @author Stuart Douglas
 52 */
 53public class StatefulSessionComponentCreateService extends SessionBeanComponentCreateService {
 54    private final InterceptorFactory afterBegin;
 55    private final Method afterBeginMethod;
 56    private final InterceptorFactory afterCompletion;
 57    private final Method afterCompletionMethod;
 58    private final InterceptorFactory beforeCompletion;
 59    private final Method beforeCompletionMethod;
 60    private final InterceptorFactory prePassivate;
 61    private final InterceptorFactory postActivate;
 62    private final StatefulTimeoutInfo statefulTimeout;
 63    private final CacheInfo cache;
 64    private final MarshallingConfiguration marshallingConfiguration;
 65    private final InjectedValue<DefaultAccessTimeoutService> defaultAccessTimeoutService = new InjectedValue<DefaultAccessTimeoutService>();
 66    private final InterceptorFactory ejb2XRemoveMethod;
 67    @SuppressWarnings("rawtypes")
 68    private final InjectedValue<CacheFactory> cacheFactory = new InjectedValue<CacheFactory>();
 69    private final Set<Object> serializableInterceptorContextKeys;
 70
 71    /**
 72     * Construct a new instance.
 73     *
 74     * @param componentConfiguration the component configuration
 75     */
 76    public StatefulSessionComponentCreateService(final ComponentConfiguration componentConfiguration, final ApplicationExceptions ejbJarConfiguration) {
 77        super(componentConfiguration, ejbJarConfiguration);
 78
 79        final StatefulComponentDescription componentDescription = (StatefulComponentDescription) componentConfiguration.getComponentDescription();
 80        final InterceptorFactory tcclInterceptorFactory = new ImmediateInterceptorFactory(new TCCLInterceptor(componentConfiguration.getModuleClassLoader()));
 81        final InterceptorFactory namespaceContextInterceptorFactory = componentConfiguration.getNamespaceContextInterceptorFactory();
 82
 83        this.afterBeginMethod = componentDescription.getAfterBegin();
 84        this.afterBegin = (this.afterBeginMethod != null) ? Interceptors.getChainedInterceptorFactory(tcclInterceptorFactory, namespaceContextInterceptorFactory, CurrentInvocationContextInterceptor.FACTORY, invokeMethodOnTarget(this.afterBeginMethod)) : null;
 85        this.afterCompletionMethod = componentDescription.getAfterCompletion();
 86        this.afterCompletion = (this.afterCompletionMethod != null) ? Interceptors.getChainedInterceptorFactory(tcclInterceptorFactory, namespaceContextInterceptorFactory, CurrentInvocationContextInterceptor.FACTORY, invokeMethodOnTarget(this.afterCompletionMethod)) : null;
 87        this.beforeCompletionMethod = componentDescription.getBeforeCompletion();
 88        this.beforeCompletion = (this.beforeCompletionMethod != null) ? Interceptors.getChainedInterceptorFactory(tcclInterceptorFactory, namespaceContextInterceptorFactory, CurrentInvocationContextInterceptor.FACTORY, invokeMethodOnTarget(this.beforeCompletionMethod)) : null;
 89        this.prePassivate = Interceptors.getChainedInterceptorFactory(componentConfiguration.getPrePassivateInterceptors());
 90        this.postActivate = Interceptors.getChainedInterceptorFactory(componentConfiguration.getPostActivateInterceptors());
 91        this.statefulTimeout = componentDescription.getStatefulTimeout();
 92        //the interceptor chain for EJB e.x remove methods
 93        this.ejb2XRemoveMethod = Interceptors.getChainedInterceptorFactory(StatefulSessionSynchronizationInterceptor.factory(componentDescription.getTransactionManagementType()), new ImmediateInterceptorFactory(new StatefulRemoveInterceptor(false)), Interceptors.getTerminalInterceptorFactory());
 94        this.cache = componentDescription.getCache();
 95        this.marshallingConfiguration = new MarshallingConfiguration();
 96        this.marshallingConfiguration.setSerializedCreator(new SunReflectiveCreator());
 97        this.marshallingConfiguration.setExternalizerCreator(new ReflectiveCreator());
 98        this.marshallingConfiguration.setClassResolver(new ClassLoaderAwareClassResolver(ModularClassResolver.getInstance(componentConfiguration.getModuleLoader()), componentConfiguration.getModuleClassLoader()));
 99        this.marshallingConfiguration.setSerializabilityChecker(new StatefulSessionBeanSerializabilityChecker(componentConfiguration.getComponentClass()));
100        this.marshallingConfiguration.setClassTable(new StatefulSessionBeanClassTable());
101        this.serializableInterceptorContextKeys = componentConfiguration.getInterceptorContextKeys();
102    }
103
104    private static InterceptorFactory invokeMethodOnTarget(final Method method) {
105        method.setAccessible(true);
106        return InvokeMethodOnTargetInterceptor.factory(method);
107    }
108
109    @Override
110    protected BasicComponent createComponent() {
111        return new StatefulSessionComponent(this);
112    }
113
114    public InterceptorFactory getAfterBegin() {
115        return afterBegin;
116    }
117
118    public InterceptorFactory getAfterCompletion() {
119        return afterCompletion;
120    }
121
122    public InterceptorFactory getBeforeCompletion() {
123        return beforeCompletion;
124    }
125
126    public InterceptorFactory getPrePassivate() {
127        return this.prePassivate;
128    }
129
130    public InterceptorFactory getPostActivate() {
131        return this.postActivate;
132    }
133
134    public Method getAfterBeginMethod() {
135        return afterBeginMethod;
136    }
137
138    public Method getAfterCompletionMethod() {
139        return afterCompletionMethod;
140    }
141
142    public Method getBeforeCompletionMethod() {
143        return beforeCompletionMethod;
144    }
145
146    public StatefulTimeoutInfo getStatefulTimeout() {
147        return statefulTimeout;
148    }
149
150    public CacheInfo getCache() {
151        return this.cache;
152    }
153
154    public MarshallingConfiguration getMarshallingConfiguration() {
155        return this.marshallingConfiguration;
156    }
157
158    public DefaultAccessTimeoutService getDefaultAccessTimeoutService() {
159        return defaultAccessTimeoutService.getValue();
160    }
161
162    Injector<DefaultAccessTimeoutService> getDefaultAccessTimeoutInjector() {
163        return this.defaultAccessTimeoutService;
164    }
165
166    public InterceptorFactory getEjb2XRemoveMethod() {
167        return ejb2XRemoveMethod;
168    }
169
170    public Set<Object> getSerializableInterceptorContextKeys() {
171        return serializableInterceptorContextKeys;
172    }
173
174    @SuppressWarnings("unchecked")
175    public CacheFactory<SessionID, StatefulSessionComponentInstance> getCacheFactory() {
176        return (CacheFactory<SessionID, StatefulSessionComponentInstance>) this.cacheFactory.getValue();
177    }
178
179    @SuppressWarnings("rawtypes")
180    Injector<CacheFactory> getCacheFactoryInjector() {
181        return this.cacheFactory;
182    }
183}