Source code: jac/core/dist/corba/CORBARemoteContainer.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.util.Vector;
24
25
26 /**
27 * CORBARemoteContainer is a container for remote objects
28 * that can be accessed with CORBA.
29 *
30 * CORBARemoteContainer instances are created by CORBADistd.
31 *
32 * @version 0.8.1
33 * @author <a href="http://cedric.cnam.fr/~pawlak/index-english.html">Renaud Pawlak</a>
34 * @author <a href="http://www-src.lip6.fr/homepages/Lionel.Seinturier/index-eng.html">Lionel Seinturier</a>
35 */
36
37 public class CORBARemoteContainer
38 extends RemoteContainer implements CORBARemoteContainerInterfOperations {
39
40 /**
41 * Create a new container.
42 *
43 * @param verbose true if information messages are to be printed.
44 */
45
46 public CORBARemoteContainer( boolean verbose ) {
47 super(verbose);
48 }
49
50
51 /**
52 * Create a new container.
53 *
54 * @param className the name of a class to instantiate
55 * @param verbose true if information messages are to be printed.
56 */
57
58 public CORBARemoteContainer( String className, boolean verbose ) {
59 super(className,verbose);
60 }
61
62
63 /**
64 * This method instantiates a className object.
65 * Clients call it to remotely instantiate an object.
66 * instantiates creates an object and returns its index.
67 * This method is part of the CORBARemoteContainerInterf interface.
68 *
69 * @param className the class name to instantiate
70 * @param args initialization arguments for the instantiation
71 * @param classes remote classes to load
72 * @param fields the object fields that are part of the state
73 * @param state the state to copy
74 * @return the index of the className object
75 */
76
77 public int
78 instantiates(
79 String className, byte[][] args, byte[] classes,
80 String[] fields, byte[][] state
81 ) {
82
83 /**
84 * Transmitted empty arrays are transformed to null arrays.
85 * The issue may need to be investigated if we really want
86 * to transmit empty arrays.
87 * The problem stems from the fact that CORBA stubs do not deal with
88 * null arguments in a friendly way.
89 */
90
91 Object[] argsObjects = null;
92 if ( args.length != 0 ) {
93 argsObjects = new Object[ args.length ];
94 for ( int i=0 ; i < args.length ; i++ )
95 argsObjects[i] = Lib.deserialize( args[i] );
96 }
97
98 if ( fields.length == 0 ) fields = null;
99
100 Object[] stateObjects = null;
101 if ( state.length != 0 ) {
102 stateObjects = new Object[ state.length ];
103 for ( int i=0 ; i < state.length ; i++ )
104 stateObjects[i] = Lib.deserialize( state[i] );
105 }
106
107 return
108 super.instantiates(
109 className, args, (Vector) Lib.deserialize(classes),
110 fields, stateObjects
111 );
112 }
113
114
115 /**
116 * Copy a state into a base object.
117 *
118 * @param index the base object index (see jac.core.JacObject)
119 * @param fields the object fields that are part of the state
120 * @param state the state to copy
121 */
122
123 public void copy( int index, String[] fields, byte[][] state ) {
124
125 Object[] stateObjects = new Object[ state.length ];
126 for ( int i=0 ; i < state.length ; i++ )
127 stateObjects[i] = Lib.deserialize( state[i] );
128
129 super.copy( index, fields, stateObjects );
130 }
131
132
133 /**
134 * Invoke a method on a base object.
135 * The base object is the remote counterpart of a local object
136 * that has been remotely instantiated by a remote container.
137 * This method is part of the CORBARemoteContainerInterf interface.
138 *
139 * @param index the callee index (see jac.core.JacObject)
140 * @param methodName the callee method name
141 * @param methodArgs the callee method arguments
142 * @return the result
143 */
144
145 public byte[] invoke( int index, String methodName, byte[][] methodArgs ) {
146
147 Object[] methodArgsObjects = new Object[ methodArgs.length ];
148 for ( int i=0 ; i < methodArgs.length ; i++ )
149 methodArgsObjects[i] = Lib.deserialize( methodArgs[i] );
150
151 Object result = super.invoke( index, methodName, methodArgsObjects );
152
153 return Lib.serialize(result);
154 }
155
156
157 /**
158 * Get a client stub wrapping chain for a given object.
159 * This method is part of the CORBADistdInterf interface.
160 *
161 * This method is called whenever a daemon receives as a parameter
162 * a reference to a remote object, to get the wrapping chain
163 * (for instance an authentication wrapper, a verbose wrapper, ...)
164 * needed to create a client stub for this remote reference.
165 *
166 * CORBARemoteContainer.getClientStubWrappingChain2 has a different
167 * return type than RemoteContainer.getClientStubWrappingChain
168 * (byte[] instead of Vector).
169 * Nevertheless, the latter is supposed to be the super method of the former.
170 * But because polymorphism on return type is not handled in Java,
171 * The method is called getClientStubWrappingChain2 instead of
172 * getClientStubWrappingChain.
173 *
174 * @param index the base object index (see jac.core.JacObject)
175 * @return the client stub wrapping chain as a serialized object
176 */
177
178 public byte[] getClientStubWrappingChain2( int index ) {
179
180 return Lib.serialize( super.getClientStubWrappingChain(index) );
181 }
182
183 }