KickJava   Java API By Example, From Geeks To Geeks.

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


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.io.Serializable JavaDoc;
22 import java.util.Vector JavaDoc;
23
24
25 /**
26  * CORBARemoteContainerStub acts as a client stub to access a remote container.
27  *
28  * CORBARemoteContainerStub holds a CORBARemoteContainerInterf instance.
29  * This is the client stub of the remote CORBARemoteContainer object
30  * that owns as a delegate the container that is to be accessed.
31  *
32  * <p>
33  * Note: what we need is an instance of something that extends RemoteContainer.
34  * But we can't have an object that is both a client stub for a remote CORBA
35  * object and a RemoteContainer (no multiple inheritance in Java).
36  * So we implemented this delegating scheme where:
37  * <ul>
38  * <li> CORBARemoteContainerStub (which is a RemoteContainer) delegates
39  * its job to a CORBARemoteContainer client stub </li>
40  * <li> which itself transmits it to a remote CORBARemoteContainer object, </li>
41  * </ul>
42  * </p>
43  *
44  * @see org.objectweb.jac.core.dist.corba.CORBARemoteContainer
45  *
46  * @author <a HREF="http://cedric.cnam.fr/~pawlak/index-english.html">Renaud Pawlak</a>
47  * @author <a HREF="http://www-src.lip6.fr/homepages/Lionel.Seinturier/index-eng.html">Lionel Seinturier</a>
48  */

49  
50 public class CORBARemoteContainerStub
51    extends RemoteContainer implements Serializable JavaDoc {
52
53    /** The CORBA stub where the job is to be delegated. */
54    
55    protected CORBARemoteContainerInterf delegate;
56    
57
58    /**
59     * Create a new remote container stub.
60     *
61     * @param delegate the stub where the job is to be delegated
62     */

63    
64    public CORBARemoteContainerStub( CORBARemoteContainerInterf delegate ) {
65       this.delegate = delegate;
66    }
67    
68
69    /**
70     * This method instantiates a className object.
71     * Clients call it to remotely instantiate an object.
72     * instantiates creates an object and returns its index.
73     * This method is part of the RMIDistdInterf interface.
74     *
75     * @param className the class name to instantiate
76     * @param args initialization arguments for the instantiation
77     * @param classes remote classes to load
78     * @param fields the object fields that are part of the state
79     * @param state the state to copy
80     * @return the index of the className object
81     */

82    
83    public int
84       instantiates(
85          String JavaDoc className, Object JavaDoc[] args, Vector JavaDoc classes,
86      String JavaDoc[] fields, Object JavaDoc[] state
87       ) {
88       
89       /**
90        * null array arguments are transmitted empty arrays.
91        * The issue may need to be investigated if we really want
92        * to transmit empty arrays.
93        * The problem stems from the fact that CORBA stubs do not deal with
94        * null arguments in a friendly way.
95        */

96       
97       byte[][] argsBytes = new byte[0][0];
98       if ( args != null ) {
99          argsBytes = new byte[args.length][];
100          for ( int i=0 ; i < args.length ; i++ )
101             argsBytes[i] = Lib.serialize( args[i] );
102       }
103       
104       if ( fields == null ) fields = new String JavaDoc[0];
105       
106       byte[][] stateBytes = new byte[0][0];
107       if ( state != null ) {
108          stateBytes = new byte[state.length][];
109          for ( int i=0 ; i < state.length ; i++ )
110             stateBytes[i] = Lib.serialize( state[i] );
111       }
112       
113       return
114          delegate.instantiates(
115         className, argsBytes, Lib.serialize(classes),
116         fields, stateBytes
117      );
118    }
119
120
121    /**
122     * Copy a state into a base object.
123     *
124     * @param index the callee index (see org.objectweb.jac.core.JacObject)
125     * @param fields the object fields that are part of the state
126     * @param state the state to copy
127     */

128     
129    public void copy( int index, String JavaDoc[] fields, Object JavaDoc[] state ) {
130    
131       byte[][] stateBytes = new byte[state.length][];
132       for ( int i=0 ; i < state.length ; i++ )
133          stateBytes[i] = Lib.serialize( state[i] );
134
135       delegate.copy( index, fields, stateBytes );
136    }
137    
138    
139    /**
140     * Invoke a method on a base object.
141     *
142     * The base object is the remote counterpart of a local object
143     * that has been remotely instantiated by the org.objectweb.jac.dist.Distd daemon.
144     *
145     * @param index the callee index (see org.objectweb.jac.core.JacObject)
146     * @param methodName the callee method name
147     * @param methodArgs the callee method arguments
148     * @return the result
149     */

150    
151    public Object JavaDoc invoke( int index, String JavaDoc methodName, Object JavaDoc[] methodArgs ) {
152       
153       byte[][] methodArgsBytes = new byte[methodArgs.length][];
154       for ( int i=0 ; i < methodArgs.length ; i++ )
155          methodArgsBytes[i] = Lib.serialize( methodArgs[i] );
156
157       return
158          Lib.deserialize( delegate.invoke(index,methodName,methodArgsBytes) );
159    }
160
161
162    /**
163     * Get a client stub wrapping chain for a given object.
164     *
165     * This method is called whenever a daemon receives as a parameter
166     * a reference to a remote object, to get the wrapping chain
167     * (for instance an authentication wrapper, a verbose wrapper, ...)
168     * needed to create a client stub for this remote reference.
169     *
170     * @param index the base object index (see org.objectweb.jac.core.JacObject)
171     * @return the client stub wrapping chain as a serialized object
172     */

173    
174    public Vector JavaDoc getClientStubWrappingChain( int index ) {
175    
176       return
177          (Vector JavaDoc) Lib.deserialize(delegate.getClientStubWrappingChain2(index));
178    }
179
180 }
181
Popular Tags