KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > core > service > SimpleInvocation


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.core.service;
19
20 import java.io.Externalizable JavaDoc;
21 import java.io.IOException JavaDoc;
22 import java.io.ObjectInput JavaDoc;
23 import java.io.ObjectOutput JavaDoc;
24 import java.util.HashMap JavaDoc;
25 import java.util.Iterator JavaDoc;
26 import java.util.Map JavaDoc;
27
28 /**
29  *
30  *
31  *
32  * @version $Rev: 71492 $ $Date: 2004-11-14 21:31:50 -0800 (Sun, 14 Nov 2004) $
33  */

34 public class SimpleInvocation implements Invocation, Externalizable JavaDoc {
35     
36     private Map JavaDoc data;
37
38     public Object JavaDoc get(InvocationKey key) {
39         if(data==null)
40             return null;
41         return data.get(key);
42     }
43
44     public void put(InvocationKey key, Object JavaDoc value) {
45         if(data==null)
46             data = new HashMap JavaDoc();
47         data.put(key, value);
48     }
49
50     /* (non-Javadoc)
51      * @see java.io.Externalizable#writeExternal(java.io.ObjectOutput)
52      */

53     public void writeExternal(ObjectOutput JavaDoc out) throws IOException JavaDoc {
54         if( data !=null ) {
55             Iterator JavaDoc iterator = data.keySet().iterator();
56             while(iterator.hasNext()) {
57                 InvocationKey key = (InvocationKey) iterator.next();
58                 if( key.isTransient() )
59                     continue; // don't serialize this item.
60
Object JavaDoc value = data.get(key);
61                 out.writeObject(key);
62                 out.writeObject(value);
63             }
64         }
65         // write end of list terminator.
66
out.writeObject(null);
67     }
68
69     /**
70      * @see java.io.Externalizable#readExternal(java.io.ObjectInput)
71      */

72     public void readExternal(ObjectInput JavaDoc in) throws IOException JavaDoc, ClassNotFoundException JavaDoc {
73         
74         if( data!=null )
75             data.clear();
76             
77         InvocationKey key = (InvocationKey) in.readObject();
78         while( key!=null ) {
79             Object JavaDoc value = in.readObject();
80             put(key,value);
81             key = (InvocationKey) in.readObject();
82         }
83         
84     }
85
86
87 }
88
Popular Tags