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 java.util.Map;
026: import org.jboss.aop.advice.Interceptor;
027: import org.jboss.aop.joinpoint.Invocation;
028: import org.jboss.aop.metadata.SimpleMetaData;
029: import org.jboss.logging.Logger;
030:
031: /**
032: * This wrapper class allows you to insert a chain of interceptors into the middle of a call stack.
033: *
034: * @author <a href="mailto:bill@jboss.org">Bill Burke</a>
035: * @version $Revision: 60233 $
036: */
037: public class EJBContainerInvocationWrapper<A extends EJBContainer, T extends BeanContext>
038: extends EJBContainerInvocation<A, T> {
039: private static final long serialVersionUID = 5402917625526438235L;
040:
041: private static final Logger log = Logger
042: .getLogger(EJBContainerInvocationWrapper.class);
043:
044: protected EJBContainerInvocation<A, T> wrapped;
045:
046: public EJBContainerInvocationWrapper(
047: EJBContainerInvocation<A, T> wrapped,
048: Interceptor[] interceptors) {
049: this .wrapped = wrapped;
050: this .interceptors = interceptors;
051: }
052:
053: public Object invokeNext() throws Throwable {
054: if (currentInterceptor < interceptors.length) {
055: try {
056: return interceptors[currentInterceptor++].invoke(this );
057: } finally {
058: // so that interceptors like clustering can reinvoke down the chain
059: currentInterceptor--;
060: }
061: }
062: try {
063: return wrapped.invokeNext();
064: } finally {
065: responseContextInfo = wrapped.getResponseContextInfo();
066: }
067: }
068:
069: public Method getMethod() {
070: return wrapped.getMethod();
071: }
072:
073: public long getMethodHash() {
074: return wrapped.getMethodHash();
075: }
076:
077: public Object getTargetObject() {
078: return wrapped.getTargetObject();
079: }
080:
081: public void setTargetObject(Object targetObject) {
082: wrapped.setTargetObject(targetObject);
083: }
084:
085: public Object[] getArguments() {
086: return wrapped.getArguments();
087: }
088:
089: public void setArguments(Object[] args) {
090: wrapped.setArguments(args);
091: }
092:
093: public Object resolveClassAnnotation(Class annotation) {
094: return wrapped.resolveClassAnnotation(annotation);
095: }
096:
097: public Object resolveAnnotation(Class annotation) {
098: return wrapped.resolveAnnotation(annotation);
099: }
100:
101: public Object getMetaData(Object key, Object attr) {
102: return wrapped.getMetaData(key, attr);
103: }
104:
105: public Invocation getWrapper(Interceptor[] newchain) {
106: return wrapped.getWrapper(newchain);
107: }
108:
109: public Invocation copy() {
110: return wrapped.copy();
111: }
112:
113: public Map getResponseContextInfo() {
114: return wrapped.getResponseContextInfo();
115: }
116:
117: public void setResponseContextInfo(Map responseContextInfo) {
118: wrapped.setResponseContextInfo(responseContextInfo);
119: }
120:
121: public void addResponseAttachment(Object key, Object val) {
122: wrapped.addResponseAttachment(key, val);
123: }
124:
125: public Object getResponseAttachment(Object key) {
126: return wrapped.getResponseAttachment(key);
127: }
128:
129: public SimpleMetaData getMetaData() {
130: return wrapped.getMetaData();
131: }
132:
133: public void setMetaData(SimpleMetaData data) {
134: wrapped.setMetaData(data);
135: }
136:
137: public Object resolveClassMetaData(Object key, Object attr) {
138: return wrapped.resolveClassMetaData(key, attr);
139: }
140:
141: public Object invokeNext(Interceptor[] newInterceptors)
142: throws Throwable {
143: return wrapped.invokeNext(newInterceptors);
144: }
145:
146: public A getAdvisor() {
147: return wrapped.getAdvisor();
148: }
149: }
|