001 /**
002 *
003 * Copyright 2003-2004 The Apache Software Foundation
004 *
005 * Licensed under the Apache License, Version 2.0 (the "License");
006 * you may not use this file except in compliance with the License.
007 * You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017
018 package org.apache.geronimo.security.remoting.jmx;
019
020 import java.io.IOException;
021 import java.io.ObjectInput;
022 import java.io.ObjectOutput;
023 import java.io.Externalizable;
024 import java.lang.reflect.Method;
025 import java.util.Map;
026 import java.util.HashMap;
027 import java.util.Iterator;
028
029 import org.apache.geronimo.interceptor.Invocation;
030 import org.apache.geronimo.interceptor.InvocationKey;
031
032 /**
033 * @version $Rev: 417891 $ $Date: 2006-06-28 15:45:07 -0700 (Wed, 28 Jun 2006) $
034 */
035 final public class SerializableInvocation implements Invocation, Externalizable {
036
037 private Map data;
038 private Method method;
039 private Object args[];
040 private Object proxy;
041
042 public SerializableInvocation() {
043 super();
044 }
045
046 public SerializableInvocation(Method method, Object[] args, Object proxy) {
047 super();
048 this.method = method;
049 this.args = args;
050 this.proxy = proxy;
051 }
052
053 public Object get(InvocationKey key) {
054 if(data==null) {
055 return null;
056 }
057 return data.get(key);
058 }
059
060 public void put(InvocationKey key, Object value) {
061 if(data==null)
062 data = new HashMap();
063 data.put(key, value);
064 }
065
066 public void writeExternal(ObjectOutput out) throws IOException {
067 if( data !=null ) {
068 Iterator iterator = data.keySet().iterator();
069 while(iterator.hasNext()) {
070 InvocationKey key = (InvocationKey) iterator.next();
071 if( key.isTransient() )
072 continue; // don't serialize this item.
073 Object value = data.get(key);
074 out.writeObject(key);
075 out.writeObject(value);
076 }
077 }
078 // write end of list terminator.
079 out.writeObject(null);
080 out.writeObject(args);
081 out.writeObject(new MarshalledMethod(method));
082 }
083
084 public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
085
086 if( data!=null )
087 data.clear();
088
089 InvocationKey key = (InvocationKey) in.readObject();
090 while( key!=null ) {
091 Object value = in.readObject();
092 put(key,value);
093 key = (InvocationKey) in.readObject();
094 }
095 args = (Object[]) in.readObject();
096 method = ((MarshalledMethod) in.readObject()).getMethod();
097 }
098
099 public Method getMethod() {
100 return method;
101 }
102
103 public Object[] getArgs() {
104 return args;
105 }
106
107 }