001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jboss.ejb3;
023:
024: import java.lang.reflect.Method;
025: import org.jboss.aop.Advisor;
026: import org.jboss.aop.MethodInfo;
027: import org.jboss.aop.advice.Interceptor;
028: import org.jboss.aop.joinpoint.Invocation;
029: import org.jboss.aop.joinpoint.MethodInvocation;
030:
031: /**
032: * Representation of an EJB invocation on the serverside
033: *
034: * @author <a href="mailto:bill@jboss.org">Bill Burke</a>
035: * @version $Revision: 60233 $
036: */
037: public class EJBContainerInvocation<A extends EJBContainer, T extends BeanContext>
038: extends MethodInvocation {
039: private static final long serialVersionUID = 4941832732679380382L;
040:
041: protected T ctx;
042: private BeanContextLifecycleCallback<T> callback;
043:
044: public EJBContainerInvocation(MethodInfo info) {
045: super (info, info.getInterceptors());
046: }
047:
048: public EJBContainerInvocation(Interceptor[] interceptors,
049: long methodHash, Method advisedMethod,
050: Method unadvisedMethod, Advisor advisor) {
051: super (interceptors, methodHash, advisedMethod, unadvisedMethod,
052: advisor);
053: }
054:
055: public EJBContainerInvocation() {
056: super (null, null);
057: }
058:
059: @SuppressWarnings("unchecked")
060: public A getAdvisor() {
061: return (A) super .getAdvisor();
062: }
063:
064: public T getBeanContext() {
065: return ctx;
066: }
067:
068: public void setBeanContext(T beanCtx) {
069: if (beanCtx != null) {
070: ctx = beanCtx;
071:
072: if (callback != null)
073: callback.attached(beanCtx);
074: } else {
075: if (callback != null)
076: callback.released(ctx);
077:
078: ctx = null;
079: }
080: }
081:
082: public Invocation getWrapper(Interceptor[] newchain) {
083: return new EJBContainerInvocationWrapper<A, T>(this , newchain);
084: }
085:
086: public Invocation copy() {
087: EJBContainerInvocation<A, T> wrapper = new EJBContainerInvocation<A, T>(
088: interceptors, methodHash, advisedMethod,
089: unadvisedMethod, advisor);
090: wrapper.metadata = this .metadata;
091: wrapper.currentInterceptor = this .currentInterceptor;
092: wrapper.setTargetObject(this .getTargetObject());
093: wrapper.setArguments(this .getArguments());
094: wrapper.setBeanContext(this .ctx);
095: wrapper.callback = this .callback;
096: return wrapper;
097: }
098:
099: public void setContextCallback(
100: BeanContextLifecycleCallback<T> callback) {
101: this.callback = callback;
102: }
103: }
|