KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > ejb > containers > interceptors > CallbackInvocationContext


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 package com.sun.ejb.containers.interceptors;
25
26 import java.lang.reflect.Method JavaDoc;
27 import javax.interceptor.InvocationContext;
28 import javax.ejb.EJBContext JavaDoc;
29
30 import com.sun.ejb.EJBUtils;
31 import com.sun.ejb.Invocation.InterceptorChain;
32 import com.sun.ejb.containers.EJBContextImpl;
33
34 import java.util.Map JavaDoc;
35 import java.util.HashMap JavaDoc;
36 import java.util.logging.Level JavaDoc;
37 import java.util.logging.Logger JavaDoc;
38
39
40 /**
41  * Concrete InvocationContext implementation passed to callback methods
42  * defined in interceptor classes.
43  */

44 public class CallbackInvocationContext implements InvocationContext {
45
46     private EJBContextImpl ejbContext;
47     private Map JavaDoc contextData;
48     private int callbackIndex = 0;
49     private CallbackChainImpl callbackChain;
50
51     public CallbackInvocationContext(EJBContextImpl ejbContextImpl,
52                                      CallbackChainImpl chain) {
53         ejbContext = ejbContextImpl;
54         callbackChain = chain;
55     }
56
57     public Object JavaDoc getTarget() {
58         return ejbContext.getEJB();
59     }
60
61     public Method JavaDoc getMethod() {
62         return null;
63     }
64     
65     public Object JavaDoc[] getParameters() {
66         throw new IllegalStateException JavaDoc("not applicable to Callback methods");
67     }
68
69     public void setParameters(Object JavaDoc[] params) {
70         throw new IllegalStateException JavaDoc("not applicable to Callback methods");
71     }
72
73     public EJBContext JavaDoc getEJBContext() {
74         return ejbContext;
75     }
76
77     public Map JavaDoc<String JavaDoc, Object JavaDoc> getContextData() {
78         if( contextData == null ) {
79             contextData = new HashMap JavaDoc();
80         }
81
82         return contextData;
83     }
84     
85     public Object JavaDoc proceed() throws Exception JavaDoc {
86         try {
87             callbackIndex++;
88             return callbackChain.invokeNext(callbackIndex, this);
89         } catch (Exception JavaDoc ex) {
90             throw ex;
91         } catch (Throwable JavaDoc th) {
92             throw new Exception JavaDoc(th);
93         }
94     }
95
96 }
97
98
Popular Tags