KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > security > remoting > jmx > SerializableInvocation


1 /**
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. 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 JavaDoc;
21 import java.io.ObjectInput JavaDoc;
22 import java.io.ObjectOutput JavaDoc;
23 import java.io.Externalizable JavaDoc;
24 import java.lang.reflect.Method JavaDoc;
25 import java.util.Map JavaDoc;
26 import java.util.HashMap JavaDoc;
27 import java.util.Iterator JavaDoc;
28
29 import org.apache.geronimo.interceptor.Invocation;
30 import org.apache.geronimo.interceptor.InvocationKey;
31
32 /**
33  * @version $Rev: 476049 $ $Date: 2006-11-16 23:35:17 -0500 (Thu, 16 Nov 2006) $
34  */

35 final public class SerializableInvocation implements Invocation, Externalizable JavaDoc {
36
37     private Map JavaDoc data;
38     private Method JavaDoc method;
39     private Object JavaDoc args[];
40     private Object JavaDoc proxy;
41
42     public SerializableInvocation() {
43         super();
44     }
45
46     public SerializableInvocation(Method JavaDoc method, Object JavaDoc[] args, Object JavaDoc proxy) {
47         super();
48         this.method = method;
49         this.args = args;
50         this.proxy = proxy;
51     }
52
53     public Object JavaDoc 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 JavaDoc value) {
61         if(data==null)
62             data = new HashMap JavaDoc();
63         data.put(key, value);
64     }
65
66     public void writeExternal(ObjectOutput JavaDoc out) throws IOException JavaDoc {
67         if( data !=null ) {
68             Iterator JavaDoc iterator = data.keySet().iterator();
69             while(iterator.hasNext()) {
70                 InvocationKey key = (InvocationKey) iterator.next();
71                 if( key.isTransient() )
72                     continue; // don't serialize this item.
73
Object JavaDoc value = data.get(key);
74                 out.writeObject(key);
75                 out.writeObject(value);
76             }
77         }
78         // write end of list terminator.
79
out.writeObject(null);
80         out.writeObject(args);
81         out.writeObject(new MarshalledMethod(method));
82     }
83
84     public void readExternal(ObjectInput JavaDoc in) throws IOException JavaDoc, ClassNotFoundException JavaDoc {
85
86         if( data!=null )
87             data.clear();
88
89         InvocationKey key = (InvocationKey) in.readObject();
90         while( key!=null ) {
91             Object JavaDoc value = in.readObject();
92             put(key,value);
93             key = (InvocationKey) in.readObject();
94         }
95         args = (Object JavaDoc[]) in.readObject();
96         method = ((MarshalledMethod) in.readObject()).getMethod();
97     }
98
99     public Method JavaDoc getMethod() {
100         return method;
101     }
102
103     public Object JavaDoc[] getArgs() {
104         return args;
105     }
106
107 }
108
Popular Tags