KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > interop > adapter > CorbaAdapter


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.adapter;
19
20 import org.apache.geronimo.interop.rmi.iiop.RemoteInterface;
21 import org.apache.geronimo.interop.rmi.iiop.ObjectRef;
22 import org.apache.geronimo.interop.naming.NameService;
23 import org.apache.commons.logging.Log;
24 import org.apache.commons.logging.LogFactory;
25
26 public class CorbaAdapter extends Adapter {
27
28     private final Log log = LogFactory.getLog(CorbaAdapter.class);
29
30     private ClassLoader JavaDoc classLoader;
31
32     private NameService nameService = NameService.getInstance();
33
34     private String JavaDoc bindNames[];
35     private String JavaDoc ids[];
36     private String JavaDoc remoteClassName;
37     private String JavaDoc remoteInterfaceClassName;
38
39     private Class JavaDoc remoteClassClass;
40     private Class JavaDoc remoteInterfaceClass;
41     private RemoteInterface remoteInterfaceObject;
42     private Object JavaDoc remoteClassObject;
43
44     public CorbaAdapter( String JavaDoc[] bindNames, String JavaDoc[] ids, String JavaDoc remoteClassName,
45                          String JavaDoc remoteInterfaceName, ClassLoader JavaDoc classLoader ) {
46         this.bindNames = bindNames;
47         this.ids = ids;
48         this.remoteClassName = remoteClassName;
49         this.remoteInterfaceClassName = remoteInterfaceName;
50         this.classLoader = classLoader;
51
52         this.remoteInterfaceClassName += "_Skeleton";
53
54         loadRemoteInterface();
55         loadRemoteObject();
56     }
57
58     public Object JavaDoc getAdapterID()
59     {
60         return "CorbaAdapter";
61     }
62
63     /*
64      * BindName is the name that will be registered with the INS (Inter-operable Name Service)
65      * These are the names from the EJBContainer.
66      */

67     public String JavaDoc[] getBindNames() {
68         return bindNames;
69     }
70
71     /*
72      * The classloader that will load any dependancies of the adapter or corba skel interfaces.
73      * Its should be set by the ejb container
74      */

75     public ClassLoader JavaDoc getClassLoader() {
76         return classLoader;
77     }
78
79     /*
80      * The classloader that will load any dependancies of the adapter or corba skel interfaces.
81      * Its should be set by the ejb container
82      */

83     public void setClassLoader(ClassLoader JavaDoc cl) {
84         this.classLoader = cl;
85     }
86
87     /*
88      * Invoke method from the IIOP Message Handler. The adapter is bound to the INS name service.
89      * When an RMI/IIOP message is processed by the server, the message handler will perform a lookup
90      * on the name service to get the HomeAdapter, then the invocation will be passed to the adapter
91      * The adapter will obtain the object key and then determine which object instance to pass the
92      * invocation to.
93      */

94     public void invoke(java.lang.String JavaDoc methodName, byte[] objectKey, org.apache.geronimo.interop.rmi.iiop.ObjectInputStream input, org.apache.geronimo.interop.rmi.iiop.ObjectOutputStream output) {
95         if (remoteInterfaceObject != null) {
96             remoteInterfaceObject.invoke(methodName, objectKey, this, input, output);
97         } else {
98             throw new org.omg.CORBA.OBJECT_NOT_EXIST JavaDoc(new String JavaDoc(objectKey));
99         }
100     }
101
102     public void start()
103     {
104         log.info( "Starting CorbaAdapter: " );
105         nameService.bindAdapter( this );
106     }
107
108     public void stop()
109     {
110         log.info( "Stopping CorbaAdapter: " );
111         nameService.unbindAdapter( this );
112     }
113
114     public ObjectRef getObjectRef()
115     {
116         return remoteInterfaceObject.getObjectRef();
117         //org.apache.geronimo.interop.rmi.iiop.ObjectRef or = new ObjectRef();
118
//or.$setID("RMI:org.apache.geronimo.interop.CosNaming.NamingContext:0000000000000000");
119
//or.$setObjectKey("org.apache.geronimo.interop.CosNaming.NamingContext");
120
//return or;
121
}
122
123     protected void loadRemoteInterface()
124     {
125         remoteInterfaceClass = loadClass( remoteInterfaceClassName, classLoader );
126
127         if (remoteInterfaceClass != null)
128         {
129             remoteInterfaceObject = null;
130             try {
131                 remoteInterfaceObject = (RemoteInterface)remoteInterfaceClass.newInstance();
132             } catch (IllegalAccessException JavaDoc e) {
133                 e.printStackTrace();
134             } catch (InstantiationException JavaDoc e) {
135                 e.printStackTrace();
136             }
137         }
138     }
139
140     protected void loadRemoteObject()
141     {
142         remoteClassClass = loadClass( remoteClassName, classLoader );
143
144         if (remoteClassClass != null)
145         {
146             remoteClassObject = null;
147             try {
148                 remoteClassObject = remoteClassClass.newInstance();
149             } catch (IllegalAccessException JavaDoc e) {
150                 e.printStackTrace();
151             } catch (InstantiationException JavaDoc e) {
152                 e.printStackTrace();
153             }
154         }
155     }
156
157     public Object JavaDoc getServant()
158     {
159         return remoteClassObject;
160     }
161
162     public Object JavaDoc getEJBContainer()
163     {
164         return null; //To change body of implemented methods use File | Settings | File Templates.
165
}
166
167     public Object JavaDoc getEJBHome()
168     {
169         return null; //To change body of implemented methods use File | Settings | File Templates.
170
}
171
172 }
173
Popular Tags