KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > interop > rmi > iiop > RemoteObject


1 /**
2  *
3  * Copyright 2004-2005 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  *
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18 package org.apache.geronimo.interop.rmi.iiop;
19
20 import java.util.HashMap JavaDoc;
21
22 public abstract class RemoteObject {
23
24     protected HashMap JavaDoc methods = new HashMap JavaDoc(10);
25
26     public RemoteObject( ) {
27         registerMethods();
28     }
29
30     protected void registerMethods() {
31         registerMethod("_is_a", -1);
32     }
33
34     protected void registerMethod( String JavaDoc methodName, int id )
35     {
36         methods.put( methodName, new Integer JavaDoc(id) );
37     }
38
39     protected Integer JavaDoc getMethodId( String JavaDoc methodName )
40     {
41         return (Integer JavaDoc)methods.get( methodName );
42     }
43
44     public void invoke(int id, byte[] objectKey, Object JavaDoc instance, ObjectInputStream input, ObjectOutputStream output) {
45         switch (id) {
46             case -1:
47                 {
48                     output.writeBoolean(_is_a(objectKey));
49                     break;
50                 }
51         }
52     }
53
54     public boolean _is_a(byte[] objectKey) {
55         String JavaDoc ids[] = getIds();
56         boolean isa = false;
57
58         String JavaDoc id = new String JavaDoc(objectKey);
59
60         if (ids != null && ids.length > 0) {
61             int i;
62             for (i = 0; i < ids.length && !isa; i++) {
63                 isa = ids[i].equals(id);
64
65             }
66         }
67
68         return isa;
69     }
70
71     public abstract String JavaDoc[] getIds();
72 }
73
Popular Tags