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.InvocationTargetException;
025: import java.lang.reflect.Method;
026: import java.util.HashMap;
027: import java.util.Map;
028: import org.jboss.aop.advice.Interceptor;
029: import org.jboss.aop.joinpoint.Invocation;
030: import org.jboss.aop.metadata.SimpleMetaData;
031: import org.jboss.aop.metadata.ThreadMetaData;
032: import org.jboss.logging.Logger;
033:
034: /**
035: * Comment
036: *
037: * @author <a href="mailto:bill@jboss.org">Bill Burke</a>
038: * @version $Revision: 57207 $
039: */
040: public abstract class EJBInvocation implements Invocation {
041: private static final Logger log = Logger
042: .getLogger(EJBInvocation.class);
043:
044: protected transient Interceptor[] interceptors;
045: protected long methodHash;
046: protected transient int currentInterceptor = 0;
047: protected transient Method method;
048: protected Object[] arguments;
049: protected SimpleMetaData metadata = null;
050: protected transient Map responseContextInfo = null;
051:
052: protected EJBInvocation(Method method, long methodHash,
053: Object[] arguments, Interceptor[] interceptors) {
054: this .method = method;
055: this .methodHash = methodHash;
056: this .arguments = arguments;
057: this .interceptors = interceptors;
058: }
059:
060: protected EJBInvocation() {
061: }
062:
063: public Object invokeNext() throws Throwable {
064: if (currentInterceptor < interceptors.length) {
065: try {
066: return interceptors[currentInterceptor++].invoke(this );
067: } finally {
068: // so that interceptors like clustering can reinvoke down the chain
069: currentInterceptor--;
070: }
071: }
072: try {
073: return method.invoke(getTargetObject(), getArguments());
074: } catch (InvocationTargetException e) {
075: throw e.getTargetException();
076: }
077: }
078:
079: public Method getMethod() {
080: return method;
081: }
082:
083: public long getMethodHash() {
084: return methodHash;
085: }
086:
087: public Interceptor[] getInterceptors() {
088: return interceptors;
089: }
090:
091: public void setInterceptors(Interceptor[] interceptors) {
092: this .interceptors = interceptors;
093: }
094:
095: public Object[] getArguments() {
096: return arguments;
097: }
098:
099: public void setArguments(Object[] args) {
100: this .arguments = args;
101: }
102:
103: public Object getMetaData(Object key, Object attr) {
104: // todo: set up the chain for metadata resolving
105: Object value = null;
106: if (metadata != null)
107: value = metadata.getMetaData(key, attr);
108: if (value != null)
109: return value;
110: value = ThreadMetaData.instance().getMetaData(key, attr);
111: return value;
112: }
113:
114: public Map getResponseContextInfo() {
115: return responseContextInfo;
116: }
117:
118: public void setResponseContextInfo(Map responseContextInfo) {
119: this .responseContextInfo = responseContextInfo;
120: }
121:
122: public void addResponseAttachment(Object key, Object val) {
123: if (responseContextInfo == null)
124: responseContextInfo = new HashMap();
125: responseContextInfo.put(key, val);
126: }
127:
128: public Object getResponseAttachment(Object key) {
129: if (responseContextInfo == null)
130: return null;
131: return responseContextInfo.get(key);
132: }
133:
134: public SimpleMetaData getMetaData() {
135: if (metadata == null)
136: metadata = new SimpleMetaData();
137: return metadata;
138: }
139:
140: public void setMetaData(SimpleMetaData data) {
141: this .metadata = data;
142: }
143:
144: public Object invokeNext(Interceptor[] newInterceptors)
145: throws Throwable {
146: throw new RuntimeException("NOT IMPLEMENTED");
147: }
148: }
|