1 /**
2 *
3 * Copyright 2003-2004 The Apache Software Foundation
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18 package org.apache.geronimo.security.remoting.jmx;
19
20 import java.io.IOException;
21 import java.io.ObjectInput;
22 import java.io.ObjectOutput;
23 import java.io.Externalizable;
24 import java.lang.reflect.Method;
25 import java.util.Map;
26 import java.util.HashMap;
27 import java.util.Iterator;
28
29 import org.apache.geronimo.interceptor.Invocation;
30 import org.apache.geronimo.interceptor.InvocationKey;
31
32 /**
33 * @version $Rev: 417891 $ $Date: 2006-06-28 15:45:07 -0700 (Wed, 28 Jun 2006) $
34 */
35 final public class SerializableInvocation implements Invocation, Externalizable {
36
37 private Map data;
38 private Method method;
39 private Object args[];
40 private Object proxy;
41
42 public SerializableInvocation() {
43 super();
44 }
45
46 public SerializableInvocation(Method method, Object[] args, Object proxy) {
47 super();
48 this.method = method;
49 this.args = args;
50 this.proxy = proxy;
51 }
52
53 public Object get(InvocationKey key) {
54 if(data==null) {
55 return null;
56 }
57 return data.get(key);
58 }
59
60 public void put(InvocationKey key, Object value) {
61 if(data==null)
62 data = new HashMap();
63 data.put(key, value);
64 }
65
66 public void writeExternal(ObjectOutput out) throws IOException {
67 if( data !=null ) {
68 Iterator iterator = data.keySet().iterator();
69 while(iterator.hasNext()) {
70 InvocationKey key = (InvocationKey) iterator.next();
71 if( key.isTransient() )
72 continue;
73 Object value = data.get(key);
74 out.writeObject(key);
75 out.writeObject(value);
76 }
77 }
78
79 out.writeObject(null);
80 out.writeObject(args);
81 out.writeObject(new MarshalledMethod(method));
82 }
83
84 public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
85
86 if( data!=null )
87 data.clear();
88
89 InvocationKey key = (InvocationKey) in.readObject();
90 while( key!=null ) {
91 Object value = in.readObject();
92 put(key,value);
93 key = (InvocationKey) in.readObject();
94 }
95 args = (Object[]) in.readObject();
96 method = ((MarshalledMethod) in.readObject()).getMethod();
97 }
98
99 public Method getMethod() {
100 return method;
101 }
102
103 public Object[] getArgs() {
104 return args;
105 }
106
107 }