KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jac > core > dist > corba > CORBARemoteContainer


1 /*
2   Renaud Pawlak, pawlak@cnam.fr, CEDRIC Laboratory, Paris, France.
3   Lionel Seinturier, Lionel.Seinturier@lip6.fr, LIP6, Paris, France.
4
5   JAC-Core is free software. You can redistribute it and/or modify it
6   under the terms of the GNU Library General Public License as
7   published by the Free Software Foundation.
8   
9   JAC-Core is distributed in the hope that it will be useful, but
10   WITHOUT ANY WARRANTY; without even the implied warranty of
11   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
13   This work uses the Javassist system - Copyright (c) 1999-2000
14   Shigeru Chiba, University of Tsukuba, Japan. All Rights Reserved. */

15
16 package org.objectweb.jac.core.dist.corba;
17
18 import org.objectweb.jac.core.utils.Lib;
19 import org.objectweb.jac.core.dist.RemoteContainer;
20
21 import java.util.Vector JavaDoc;
22
23
24 /**
25  * CORBARemoteContainer is a container for remote objects
26  * that can be accessed with CORBA.
27  *
28  * CORBARemoteContainer instances are created by CORBADistd.
29  *
30  * @author <a HREF="http://cedric.cnam.fr/~pawlak/index-english.html">Renaud Pawlak</a>
31  * @author <a HREF="http://www-src.lip6.fr/homepages/Lionel.Seinturier/index-eng.html">Lionel Seinturier</a>
32  */

33  
34 public class CORBARemoteContainer
35    extends RemoteContainer implements CORBARemoteContainerInterfOperations {
36
37    /**
38     * Create a new container.
39     *
40     * @param verbose true if information messages are to be printed.
41     */

42    
43    public CORBARemoteContainer( boolean verbose ) {
44       super(verbose);
45    }
46    
47    
48    /**
49     * Create a new container.
50     *
51     * @param className the name of a class to instantiate
52     * @param verbose true if information messages are to be printed.
53     */

54    
55    public CORBARemoteContainer( String JavaDoc className, boolean verbose ) {
56       super(className,verbose);
57    }
58    
59    
60    /**
61     * This method instantiates a className object.
62     * Clients call it to remotely instantiate an object.
63     * instantiates creates an object and returns its index.
64     * This method is part of the CORBARemoteContainerInterf interface.
65     *
66     * @param className the class name to instantiate
67     * @param args initialization arguments for the instantiation
68     * @param classes remote classes to load
69     * @param fields the object fields that are part of the state
70     * @param state the state to copy
71     * @return the index of the className object
72     */

73    
74    public int
75       instantiates(
76          String JavaDoc className, byte[][] args, byte[] classes,
77      String JavaDoc[] fields, byte[][] state
78       ) {
79
80       /**
81        * Transmitted empty arrays are transformed to null arrays.
82        * The issue may need to be investigated if we really want
83        * to transmit empty arrays.
84        * The problem stems from the fact that CORBA stubs do not deal with
85        * null arguments in a friendly way.
86        */

87       
88       Object JavaDoc[] argsObjects = null;
89       if ( args.length != 0 ) {
90          argsObjects = new Object JavaDoc[ args.length ];
91          for ( int i=0 ; i < args.length ; i++ )
92             argsObjects[i] = Lib.deserialize( args[i] );
93       }
94       
95       if ( fields.length == 0 ) fields = null;
96       
97       Object JavaDoc[] stateObjects = null;
98       if ( state.length != 0 ) {
99          stateObjects = new Object JavaDoc[ state.length ];
100          for ( int i=0 ; i < state.length ; i++ )
101             stateObjects[i] = Lib.deserialize( state[i] );
102       }
103       
104       return
105          super.instantiates(
106         className, args, (Vector JavaDoc) Lib.deserialize(classes),
107         fields, stateObjects
108          );
109    }
110
111
112    /**
113     * Copy a state into a base object.
114     *
115     * @param index the base object index (see org.objectweb.jac.core.JacObject)
116     * @param fields the object fields that are part of the state
117     * @param state the state to copy
118     */

119     
120    public void copy( int index, String JavaDoc[] fields, byte[][] state ) {
121
122       Object JavaDoc[] stateObjects = new Object JavaDoc[ state.length ];
123       for ( int i=0 ; i < state.length ; i++ )
124          stateObjects[i] = Lib.deserialize( state[i] );
125       
126       super.copy( index, fields, stateObjects );
127    }
128    
129    
130    /**
131     * Invoke a method on a base object.
132     * The base object is the remote counterpart of a local object
133     * that has been remotely instantiated by a remote container.
134     * This method is part of the CORBARemoteContainerInterf interface.
135     *
136     * @param index the callee index (see org.objectweb.jac.core.JacObject)
137     * @param methodName the callee method name
138     * @param methodArgs the callee method arguments
139     * @return the result
140     */

141    
142    public byte[] invoke( int index, String JavaDoc methodName, byte[][] methodArgs ) {
143       
144       Object JavaDoc[] methodArgsObjects = new Object JavaDoc[ methodArgs.length ];
145       for ( int i=0 ; i < methodArgs.length ; i++ )
146          methodArgsObjects[i] = Lib.deserialize( methodArgs[i] );
147       
148       Object JavaDoc result = super.invoke( index, methodName, methodArgsObjects );
149       
150       return Lib.serialize(result);
151    }
152
153
154    /**
155     * Get a client stub wrapping chain for a given object.
156     * This method is part of the CORBADistdInterf interface.
157     *
158     * This method is called whenever a daemon receives as a parameter
159     * a reference to a remote object, to get the wrapping chain
160     * (for instance an authentication wrapper, a verbose wrapper, ...)
161     * needed to create a client stub for this remote reference.
162     *
163     * CORBARemoteContainer.getClientStubWrappingChain2 has a different
164     * return type than RemoteContainer.getClientStubWrappingChain
165     * (byte[] instead of Vector).
166     * Nevertheless, the latter is supposed to be the super method of the former.
167     * But because polymorphism on return type is not handled in Java,
168     * The method is called getClientStubWrappingChain2 instead of
169     * getClientStubWrappingChain.
170     *
171     * @param index the base object index (see org.objectweb.jac.core.JacObject)
172     * @return the client stub wrapping chain as a serialized object
173     */

174    
175    public byte[] getClientStubWrappingChain2( int index ) {
176    
177       return Lib.serialize( super.getClientStubWrappingChain(index) );
178    }
179
180 }
181
Popular Tags