KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > aop > joinpoint > InvocationResponse


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.aop.joinpoint;
23  
24 import java.io.IOException JavaDoc;
25 import java.util.HashMap JavaDoc;
26 import java.util.Iterator JavaDoc;
27 import java.util.Map JavaDoc;
28
29 /**
30  * Allows interceptors to communicate information back down the chain
31  * @see <related>
32  * @author <a HREF="mailto:bill@jboss.org">Bill Burke</a>
33  * @version $Revision: 37406 $
34  * Revisions:
35  *
36  * <p><b>Revisions:</b>
37  *
38  */

39 public class InvocationResponse
40    implements java.io.Externalizable JavaDoc
41 {
42    // Constants -----------------------------------------------------
43

44    private static final long serialVersionUID = 2974596986988236395L;
45
46    public Map JavaDoc getContextInfo()
47    {
48       return contextInfo;
49    }
50
51    public void setContextInfo(Map JavaDoc contextInfo)
52    {
53       this.contextInfo = contextInfo;
54    }
55
56    // The Map of methods used by this Invocation
57
protected Map JavaDoc contextInfo = null;
58    protected Object JavaDoc response = null;
59
60    // Constructors --------------------------------------------------
61
public InvocationResponse()
62    {
63    }
64    public InvocationResponse(Object JavaDoc obj)
65    {
66       if (obj instanceof InvocationResponse)
67       {
68          new Exception JavaDoc().printStackTrace();
69          throw new RuntimeException JavaDoc("Stuffing an InvocationResponse within an InvocationResponse!!!!");
70       }
71       this.response = obj;
72    }
73
74    public Object JavaDoc getResponse() { return response; }
75    public void setResponse(Object JavaDoc obj)
76    {
77       if (obj instanceof InvocationResponse)
78       {
79          new Exception JavaDoc().printStackTrace();
80          throw new RuntimeException JavaDoc("Stuffing an InvocationResponse within an InvocationResponse!!!!");
81       }
82       response = obj;
83    }
84
85    public void addAttachment(Object JavaDoc key, Object JavaDoc val)
86    {
87       if (contextInfo == null) contextInfo = new HashMap JavaDoc(1);
88       contextInfo.put(key, val);
89    }
90
91    public Object JavaDoc getAttachment(Object JavaDoc key)
92    {
93       if (contextInfo == null) return null;
94       return contextInfo.get(key);
95    }
96    
97    // Externalizable implementation ---------------------------------
98
public void writeExternal(java.io.ObjectOutput JavaDoc out)
99    throws IOException JavaDoc
100    {
101       out.writeObject(response);
102       if (contextInfo == null)
103       {
104          out.writeInt(0);
105       }
106       else
107       {
108          out.writeInt(contextInfo.size());
109          Iterator JavaDoc keys = contextInfo.keySet().iterator();
110          while (keys.hasNext())
111          {
112             Object JavaDoc currentKey = keys.next();
113             out.writeObject(currentKey);
114             out.writeObject(contextInfo.get(currentKey));
115          }
116       }
117    }
118    
119    public void readExternal(java.io.ObjectInput JavaDoc in)
120    throws IOException JavaDoc, ClassNotFoundException JavaDoc
121    {
122       response = in.readObject();
123
124       // contextInfo
125
int size = in.readInt();
126       if (size == 0)
127       {
128          contextInfo = null;
129       }
130       else
131       {
132          contextInfo = new HashMap JavaDoc(size);
133          for (int i = 0; i < size; i++)
134          {
135             Object JavaDoc key = in.readObject();
136             Object JavaDoc value = in.readObject();
137             contextInfo.put(key, value);
138          }
139       }
140    }
141 }
142
Popular Tags