KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > invocation > InvocationContext


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2005, JBoss Inc., and individual contributors as indicated
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * 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 package org.jboss.invocation;
23
24 import java.util.Map JavaDoc;
25 import java.util.HashMap JavaDoc;
26
27 import org.jboss.invocation.Invoker;
28
29 /**
30  * The Invocation Context
31  *
32  * <p>Describes the context in which this Invocation is being executed in
33  * the interceptors
34  *
35  * <p>The heart of it is the payload map that can contain anything we then
36  * put readers on them. The first "reader" is this "Invocation" object that
37  * can interpret the data in it.
38  *
39  * <p>Essentially we can carry ANYTHING from the client to the server, we
40  * keep a series of redifined variables and method calls to get at the
41  * pointers. But really it is just a repository of objects.
42  *
43  * @author <a HREF="mailto:marc@jboss.org">Marc Fleury</a>
44  * @version $Revision: 37459 $
45  */

46 public class InvocationContext
47    implements java.io.Serializable JavaDoc
48 {
49    /** Serial Version Identifier. @since 1.5 */
50    private static final long serialVersionUID = 7679468692447241311L;
51
52    // Context is a map
53
public Map JavaDoc context;
54
55    /**
56     * Exposed for externalization only.
57     */

58    public InvocationContext() {
59       context = new HashMap JavaDoc();
60    }
61    
62    /**
63     * Invocation creation
64     */

65    public InvocationContext(final Map JavaDoc context) {
66       this.context = context;
67    }
68       
69    //
70
// The generic getter and setter is really all that one needs to talk to
71
// this object. We introduce typed getters and setters for convenience
72
// and code readability in the codebase
73
//
74

75    /**
76     * The generic store of variables
77     */

78    public void setValue(Object JavaDoc key, Object JavaDoc value) {
79       context.put(key,value);
80    }
81    
82    /**
83     * Get a value from the stores.
84     */

85    public Object JavaDoc getValue(Object JavaDoc key)
86    {
87       return context.get(key);
88    }
89    
90    /**
91     * A container for server side association.
92     */

93    public void setObjectName(Object JavaDoc objectName) {
94       context.put(InvocationKey.OBJECT_NAME, objectName);
95    }
96    
97    public Object JavaDoc getObjectName() {
98       return context.get(InvocationKey.OBJECT_NAME);
99    }
100    
101    /**
102     * Return the invocation target ID. Can be used to identify a cached object.
103     */

104    public void setCacheId(Object JavaDoc id) {
105       context.put(InvocationKey.CACHE_ID, id);
106    }
107    
108    public Object JavaDoc getCacheId() {
109       return context.get(InvocationKey.CACHE_ID);
110    }
111    
112    public void setInvoker(Invoker invoker) {
113       context.put(InvocationKey.INVOKER, invoker);
114    }
115    
116    public Invoker getInvoker() {
117       return (Invoker) context.get(InvocationKey.INVOKER);
118    }
119    
120    public void setInvokerProxyBinding(String JavaDoc binding) {
121       context.put(InvocationKey.INVOKER_PROXY_BINDING, binding);
122    }
123    
124    public String JavaDoc getInvokerProxyBinding() {
125       return (String JavaDoc) context.get(InvocationKey.INVOKER_PROXY_BINDING);
126    }
127 }
128
Popular Tags