Source code: jac/core/dist/corba/CORBARemoteContainerStub.java
1 /*
2 JAC-Core version 0.8.1
3
4 Renaud Pawlak, pawlak@cnam.fr, CEDRIC Laboratory, Paris, France.
5 Lionel Seinturier, Lionel.Seinturier@lip6.fr, LIP6, Paris, France.
6
7 JAC-Core is free software. You can redistribute it and/or modify it
8 under the terms of the GNU Library General Public License as
9 published by the Free Software Foundation.
10
11 JAC-Core is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14
15 This work uses the Javassist system - Copyright (c) 1999-2000
16 Shigeru Chiba, University of Tsukuba, Japan. All Rights Reserved. */
17
18 package jac.core.dist.corba;
19
20 import jac.core.utils.Lib;
21 import jac.core.dist.RemoteContainer;
22
23 import java.io.Serializable;
24 import java.util.Vector;
25
26
27 /**
28 * CORBARemoteContainerStub acts as a client stub to access a remote container.
29 *
30 * CORBARemoteContainerStub holds a CORBARemoteContainerInterf instance.
31 * This is the client stub of the remote CORBARemoteContainer object
32 * that owns as a delegate the container that is to be accessed.
33 *
34 * <p>
35 * Note: what we need is an instance of something that extends RemoteContainer.
36 * But we can't have an object that is both a client stub for a remote CORBA
37 * object and a RemoteContainer (no multiple inheritance in Java).
38 * So we implemented this delegating scheme where:
39 * <ul>
40 * <li> CORBARemoteContainerStub (which is a RemoteContainer) delegates
41 * its job to a CORBARemoteContainer client stub </li>
42 * <li> which itself transmits it to a remote CORBARemoteContainer object, </li>
43 * </ul>
44 * </p>
45 *
46 * @see jac.core.dist.corba.CORBARemoteContainer
47 *
48 * @version 0.8.1
49 * @author <a href="http://cedric.cnam.fr/~pawlak/index-english.html">Renaud Pawlak</a>
50 * @author <a href="http://www-src.lip6.fr/homepages/Lionel.Seinturier/index-eng.html">Lionel Seinturier</a>
51 */
52
53 public class CORBARemoteContainerStub
54 extends RemoteContainer implements Serializable {
55
56 /** The CORBA stub where the job is to be delegated. */
57
58 protected CORBARemoteContainerInterf delegate;
59
60
61 /**
62 * Create a new remote container stub.
63 *
64 * @param delegate the stub where the job is to be delegated
65 */
66
67 public CORBARemoteContainerStub( CORBARemoteContainerInterf delegate ) {
68 this.delegate = delegate;
69 }
70
71
72 /**
73 * This method instantiates a className object.
74 * Clients call it to remotely instantiate an object.
75 * instantiates creates an object and returns its index.
76 * This method is part of the RMIDistdInterf interface.
77 *
78 * @param className the class name to instantiate
79 * @param args initialization arguments for the instantiation
80 * @param classes remote classes to load
81 * @param fields the object fields that are part of the state
82 * @param state the state to copy
83 * @return the index of the className object
84 */
85
86 public int
87 instantiates(
88 String className, Object[] args, Vector classes,
89 String[] fields, Object[] state
90 ) {
91
92 /**
93 * null array arguments are transmitted empty arrays.
94 * The issue may need to be investigated if we really want
95 * to transmit empty arrays.
96 * The problem stems from the fact that CORBA stubs do not deal with
97 * null arguments in a friendly way.
98 */
99
100 byte[][] argsBytes = new byte[0][0];
101 if ( args != null ) {
102 argsBytes = new byte[args.length][];
103 for ( int i=0 ; i < args.length ; i++ )
104 argsBytes[i] = Lib.serialize( args[i] );
105 }
106
107 if ( fields == null ) fields = new String[0];
108
109 byte[][] stateBytes = new byte[0][0];
110 if ( state != null ) {
111 stateBytes = new byte[state.length][];
112 for ( int i=0 ; i < state.length ; i++ )
113 stateBytes[i] = Lib.serialize( state[i] );
114 }
115
116 return
117 delegate.instantiates(
118 className, argsBytes, Lib.serialize(classes),
119 fields, stateBytes
120 );
121 }
122
123
124 /**
125 * Copy a state into a base object.
126 *
127 * @param index the callee index (see jac.core.JacObject)
128 * @param fields the object fields that are part of the state
129 * @param state the state to copy
130 */
131
132 public void copy( int index, String[] fields, Object[] state ) {
133
134 byte[][] stateBytes = new byte[state.length][];
135 for ( int i=0 ; i < state.length ; i++ )
136 stateBytes[i] = Lib.serialize( state[i] );
137
138 delegate.copy( index, fields, stateBytes );
139 }
140
141
142 /**
143 * Invoke a method on a base object.
144 *
145 * The base object is the remote counterpart of a local object
146 * that has been remotely instantiated by the jac.dist.Distd daemon.
147 *
148 * @param index the callee index (see jac.core.JacObject)
149 * @param methodName the callee method name
150 * @param methodArgs the callee method arguments
151 * @return the result
152 */
153
154 public Object invoke( int index, String methodName, Object[] methodArgs ) {
155
156 byte[][] methodArgsBytes = new byte[methodArgs.length][];
157 for ( int i=0 ; i < methodArgs.length ; i++ )
158 methodArgsBytes[i] = Lib.serialize( methodArgs[i] );
159
160 return
161 Lib.deserialize( delegate.invoke(index,methodName,methodArgsBytes) );
162 }
163
164
165 /**
166 * Get a client stub wrapping chain for a given object.
167 *
168 * This method is called whenever a daemon receives as a parameter
169 * a reference to a remote object, to get the wrapping chain
170 * (for instance an authentication wrapper, a verbose wrapper, ...)
171 * needed to create a client stub for this remote reference.
172 *
173 * @param index the base object index (see jac.core.JacObject)
174 * @return the client stub wrapping chain as a serialized object
175 */
176
177 public Vector getClientStubWrappingChain( int index ) {
178
179 return
180 (Vector) Lib.deserialize(delegate.getClientStubWrappingChain2(index));
181 }
182
183 }