/[classpath]/classpath/javax/rmi/CORBA/Util.java
ViewVC logotype

Diff of /classpath/javax/rmi/CORBA/Util.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.4 by mark, Sat Jul 2 20:32:46 2005 UTC revision 1.5 by audriusa, Sun Oct 2 19:58:01 2005 UTC
# Line 1  Line 1 
1  /* Util.java --  /* Util.java --
2     Copyright (C) 2002, 2004 Free Software Foundation, Inc.     Copyright (C) 2002, 2004, 2005 Free Software Foundation, Inc.
3    
4  This file is part of GNU Classpath.  This file is part of GNU Classpath.
5    
# Line 38  exception statement from your version. * Line 38  exception statement from your version. *
38    
39  package javax.rmi.CORBA;  package javax.rmi.CORBA;
40    
41    import org.omg.CORBA.Any;
42    import org.omg.CORBA.BAD_PARAM;
43    import org.omg.CORBA.COMM_FAILURE;
44    import org.omg.CORBA.CompletionStatus;
45    import org.omg.CORBA.INVALID_TRANSACTION;
46    import org.omg.CORBA.INV_OBJREF;
47    import org.omg.CORBA.MARSHAL;
48    import org.omg.CORBA.NO_PERMISSION;
49    import org.omg.CORBA.OBJECT_NOT_EXIST;
50    import org.omg.CORBA.OMGVMCID;
51    import org.omg.CORBA.ORB;
52    import org.omg.CORBA.SystemException;
53    import org.omg.CORBA.TRANSACTION_REQUIRED;
54    import org.omg.CORBA.TRANSACTION_ROLLEDBACK;
55    import org.omg.CORBA.TypeCode;
56    import org.omg.CORBA.portable.InputStream;
57    import org.omg.CORBA.portable.OutputStream;
58    
59  import gnu.javax.rmi.CORBA.DelegateFactory;  import gnu.javax.rmi.CORBA.DelegateFactory;
 import gnu.javax.rmi.CORBA.GetDelegateInstanceException;  
60    
61  import java.io.InputStream;  import java.rmi.AccessException;
62  import java.io.OutputStream;  import java.rmi.MarshalException;
63    import java.rmi.NoSuchObjectException;
64  import java.rmi.Remote;  import java.rmi.Remote;
65  import java.rmi.RemoteException;  import java.rmi.RemoteException;
66    import java.rmi.ServerError;
67    import java.rmi.ServerException;
68    import java.rmi.UnexpectedException;
69    import java.rmi.server.RMIClassLoader;
70    
71    import javax.transaction.InvalidTransactionException;
72    import javax.transaction.TransactionRequiredException;
73    import javax.transaction.TransactionRolledbackException;
74    
75    /**
76     * Provides utility methods used by stubs and ties to perform common operations.
77     * The functionality is forwarded to the enclosed UtilDelegate. This delegate
78     * can be altered by setting the system property "javax.rmi.CORBA.UtilClass" to
79     * the name of the alternative class that must implement {@link UtilDelegate}.
80     *
81     * @author Audrius Meskauskas (AudriusA@Bioinformatics.org)
82     */
83  public class Util  public class Util
84  {  {
85      /**
86    private static UtilDelegate delegate;     * The delegate, responsible for all functionality.
87    static     */
88    {    static UtilDelegate delegate = (UtilDelegate) DelegateFactory.getInstance(DelegateFactory.UTIL);
89      try  
90        {    /**
91          delegate = (UtilDelegate)DelegateFactory.getInstance("Util");     * Prevents this class from being instantiated.
92        }     */
     catch(GetDelegateInstanceException e)  
       {  
         delegate = null;  
       }  
   }  
   
93    private Util()    private Util()
94    {    {
95    }    }
96    
97    // XXX - javax.rmi.ORB -> org.omg.CORBA.ORB    /**
98    public static Object copyObject(Object obj, javax.rmi.ORB orb)     * Used by local stubs to create a copy of the object. The object must be
99       * Serializable for this operation to succeed. Strings are not copied and
100       * 1D-3D string arrays are only cloned.
101       */
102      public static java.lang.Object copyObject(java.lang.Object object, ORB orb)
103      throws RemoteException      throws RemoteException
104    {    {
105      if(delegate != null)      return delegate.copyObject(object, orb);
       return delegate.copyObject(obj, orb);  
     else  
       return null;  
106    }    }
107    
108    // XXX - javax.rmi.ORB -> org.omg.CORBA.ORB    /**
109    public static Object[] copyObjects(Object obj[], javax.rmi.ORB orb)     * Used by local stubs to create a multiple copies of the object, preserving
110       * sharing accross the parameters if necessary.
111       */
112      public static java.lang.Object[] copyObjects(java.lang.Object[] object,
113        ORB orb)
114      throws RemoteException      throws RemoteException
115    {    {
116      if(delegate != null)      return delegate.copyObjects(object, orb);
       return delegate.copyObjects(obj, orb);  
     else  
       return null;  
117    }    }
118        
119      /**
120       * Get the value handler that Serializes Java objects to and from CDR (GIOP)
121       * streams.
122       *
123       * When using the default Util implementation, the class of the returned
124       * handler can be altered by setting by setting the system property
125       * "javax.rmi.CORBA.ValueHandlerClass" to the name of the alternative class
126       * that must implement {@link ValueHandler}.
127       */
128    public static ValueHandler createValueHandler()    public static ValueHandler createValueHandler()
129    {    {
130      if(delegate != null)      return delegate.createValueHandler();
       return delegate.createValueHandler();  
     else  
       return null;  
131    }    }
132        
133      /**
134       * This call is finally delegated to {@link RMIClassLoader#getClassAnnotation};
135       */
136    public static String getCodebase(Class clz)    public static String getCodebase(Class clz)
137    {    {
138      if(delegate != null)      return delegate.getCodebase(clz);
       return delegate.getCodebase(clz);  
     else  
       return null;  
139    }    }
140        
141      /**
142       * Get the Tie that handles invocations on the given target. If the target/Tie
143       * pair has not been previously registered using {@link #registerTarget},
144       * this method tries to locate a tie class by the name pattern. If this
145       * succeeds, the tie-target pair is also registered.
146       *
147       * @return the Tie.
148       */
149    public static Tie getTie(Remote target)    public static Tie getTie(Remote target)
150    {    {
151      if(delegate != null)      return delegate.getTie(target);
       return delegate.getTie(target);  
     else  
       return null;  
152    }    }
153    
154      /**
155       * Checks if the given stub is local. The implementation it delegates call to
156       * {@link ObjectImpl#_is_local().
157       *
158       * @param stub a stub to check.
159       * @return true if the stub is local, false otherwise.
160       *
161       * @throws RemoteException if the {@link ObjectImpl#_is_local()} throws a
162       * {@link org.omg.CORBA.SystemException}.
163       */
164    public static boolean isLocal(Stub stub)    public static boolean isLocal(Stub stub)
165      throws RemoteException      throws RemoteException
166    {    {
167      if(delegate != null)      return delegate.isLocal(stub);
       return delegate.isLocal(stub);  
     else  
       return false;  
168    }    }
169    
170    public static Class loadClass(String className, String remoteCodebase, ClassLoader loader)    /**
171       * Load the class. The method uses class loaders from the call stact first. If
172       * this fails, the further behaviour depends on the System Property
173       * "java.rmi.server.useCodebaseOnly" with default value "false".
174       *
175       * <ul>
176       * <li>If remoteCodebase is non-null and useCodebaseOnly is "false" then call
177       * java.rmi.server.RMIClassLoader.loadClass (remoteCodebase, className)</li>
178       * <li> If remoteCodebase is null or useCodebaseOnly is true then call
179       * java.rmi.server.RMIClassLoader.loadClass(className)</li>
180       * <li>If a class is still not successfully loaded and the loader != null
181       * then try Class.forName(className, false, loader). </li>
182       * </ul>
183       *
184       * @param className the name of the class.
185       * @param remoteCodebase the codebase.
186       * @param loader the class loader.
187       * @return the loaded class.
188       *
189       * @throws ClassNotFoundException of the class cannot be loaded.
190       */
191      public static Class loadClass(String className, String remoteCodebase,
192        ClassLoader loader)
193      throws ClassNotFoundException      throws ClassNotFoundException
194    {    {
195      if(delegate != null)      return delegate.loadClass(className, remoteCodebase, loader);
       return delegate.loadClass(className, remoteCodebase, loader);  
     else  
       throw new ClassNotFoundException(className + ": delegate == null");  
196    }    }
197        
198      /**
199       * Converts CORBA {@link SystemException} into RMI {@link RemoteException}.
200       * The exception is converted as defined in the following table:
201       * <p>
202       * <table border = "1">
203       * <tr>
204       * <th>CORBA Exception</th>
205       * <th>RMI Exception</th>
206       * </tr>
207       * <tr>
208       * <td>{@link COMM_FAILURE}</td>
209       * <td>{@link MarshalException}</td>
210       * </tr>
211       * <tr>
212       * <td>{@link INV_OBJREF}</td>
213       * <td>{@link  NoSuchObjectException}</td>
214       * </tr>
215       * <tr>
216       * <td>{@link NO_PERMISSION}</td>
217       * <td>{@link  AccessException}</td>
218       * </tr>
219       * <tr>
220       * <td>{@link MARSHAL}</td>
221       * <td>{@link  MarshalException}</td>
222       * </tr>
223       * <tr>
224       * <td>{@link BAD_PARAM} (all other cases)</td>
225       * <td>{@link  MarshalException}</td>
226       * </tr>
227       * <tr>
228       * <td>{@link OBJECT_NOT_EXIST}</td>
229       * <td>{@link  NoSuchObjectException}</td>
230       * </tr>
231       * <tr>
232       * <td>{@link TRANSACTION_REQUIRED}</td>
233       * <td>{@link  TransactionRequiredException}</td>
234       * </tr>
235       * <tr>
236       * <td>{@link TRANSACTION_ROLLEDBACK}</td>
237       * <td>{@link  TransactionRolledbackException}</td>
238       * </tr>
239       * <tr>
240       * <td>{@link INVALID_TRANSACTION}</td>
241       * <td>{@link  InvalidTransactionException}</td>
242       * </tr>
243       * <tr>
244       * <td bgcolor="lightgray">Any other {@link SystemException}</td>
245       * <td bgcolor="lightgray">{@link RemoteException}</td>
246       * </tr>
247       * </table>
248       * </p>
249       * <p>
250       * The exception detailed message always consists of
251       * <ol>
252       * <li>the string "CORBA "</li>
253       * <li>the CORBA name of the system exception</li>
254       * <li>single space</li>
255       * <li>the hexadecimal value of the system exception's minor code, preceeded
256       * by 0x (higher bits contain {@link OMGVMCID}).</li>
257       * <li>single space</li>
258       * <li>the {@link CompletionStatus} of the exception: "Yes", "No" or "Maybe".</li>
259       * </ol>
260       * The subsequent content is not part of the official RMI-IIOP standart and is
261       * added for compatibility with Sun's implementation:
262       * <ol>
263       * <li>the phrase "<code>; nested exception is: <i>(line feed)(tab)</i></code>"</li>
264       * <li>the full name of the mapped SystemException, as returned by
265       * Class.getName().</li>
266       * <li>the ": ".
267       * <li>the value, returned by .getMessage() of the passed parameter.</li>
268       * </ol>
269       * <p>
270       * For instance, if the Internet connection was refused:
271       * </p><p>
272       * <code>CORBA COMM_FAILURE 0x535500C9 No</code>
273       * </p><p>
274       * The original CORBA exception is set as the cause of the RemoteException
275       * being created.
276       * </p>
277       */
278    public static RemoteException mapSystemException(SystemException ex)    public static RemoteException mapSystemException(SystemException ex)
279    {    {
280      if(delegate != null)      return delegate.mapSystemException(ex);
       return delegate.mapSystemException(ex);  
     else  
       return null;  
   }  
   
   public static Object readAny(InputStream in)  
   {  
     if(delegate != null)  
       return delegate.readAny(in);  
     else  
       return null;  
281    }    }
282    
283      /**
284       * Register the Tie-target pair. As the Tie is a Servant, it can potentially
285       * be connected to several objects and hence may be registered with several
286       * targets.
287       */
288    public static void registerTarget(Tie tie, Remote target)    public static void registerTarget(Tie tie, Remote target)
289    {    {
290      if(delegate != null)      delegate.registerTarget(tie, target);
       delegate.registerTarget(tie, target);  
291    }    }
292        
293      /**
294       * Deactivate the associated Tie, if it is found and is not connected to other
295       * registered targets. Independing from the POA policies, the transparent
296       * reactivation will not be possible.
297       */
298    public static void unexportObject(Remote target)    public static void unexportObject(Remote target)
299        throws NoSuchObjectException
300    {    {
301      if(delegate != null)      delegate.unexportObject(target);
       delegate.unexportObject(target);  
   }  
       
   public static RemoteException wrapException(Throwable orig)  
   {  
     if(delegate != null)  
       return delegate.wrapException(orig);  
     else  
       return null;  
   }  
       
   public static void writeAbstractObject(OutputStream out, Object obj)  
   {  
     if(delegate != null)  
       delegate.writeAbstractObject(out, obj);  
   }  
       
   public static void writeAny(OutputStream out, Object obj)  
   {  
     if(delegate != null)  
       delegate.writeAny(out, obj);  
302    }    }
303        
304    public static void writeRemoteObject(OutputStream out, Object obj)    /**
305       * Converts the exception that was thrown by the implementation method on a
306       * server side into RemoteException that can be transferred and re-thrown on a
307       * client side. The method converts exceptions as defined in the following
308       * table: <table border = "1">
309       * <tr>
310       * <th>Exception to map (or subclass)</th>
311       * <th>Maps into</th>
312       * </tr>
313       * <tr>
314       * <td>{@link Error}</td>
315       * <td>{@link ServerError}</td>
316       * </tr>
317       * <tr>
318       * <td>{@link RemoteException}</td>
319       * <td>{@link ServerException}</td>
320       * </tr>
321       * <tr>
322       * <td>{@link SystemException}</td>
323       * <td>wrapException({@link #mapSystemException})</td>
324       * </tr>
325       * <tr>
326       * <td>{@link RuntimeException}</td>
327       * <td><b>rethrows</b></td>
328       * </tr>
329       * <tr>
330       * <td>Any other exception</td>
331       * <td>{@link UnexpectedException}</td>
332       * </tr>
333       * </table>
334       *
335       * @param ex an exception that was thrown on a server side implementation.
336       *
337       * @return the corresponding RemoteException unless it is a RuntimeException.
338       *
339       * @throws RuntimeException the passed exception if it is an instance of
340       * RuntimeException.
341       *
342       * @specnote It is the same behavior, as in Suns implementations 1.4.0-1.5.0.
343       */
344      public static RemoteException wrapException(Throwable exception)
345      {
346        return delegate.wrapException(exception);
347      }
348    
349      /**
350       * Write abstract interface to the CORBA output stream. The write format is
351       * matching CORBA abstract interface. Remotes and CORBA objects are written as
352       * objects, other classes are supposed to be value types and are written as
353       * such. {@link Remote}s are processed as defined in
354       * {@link #writeRemoteObject}. The written data contains discriminator,
355       * defining, that was written. Another method that writes the same content is
356       * {@link org.omg.CORBA_2_3.portable.OutputStream#write_abstract_interface(java.lang.Object)}.
357       *
358       * @param output a stream to write to, must be
359       * {@link org.omg.CORBA_2_3.portable.OutputStream}.
360       *
361       * @param object an object to write, must be CORBA object, Remote
362       */
363      public static void writeAbstractObject(OutputStream output,
364        java.lang.Object object)
365      {
366        delegate.writeAbstractObject(output, object);
367      }
368    
369      /**
370       * Write the passed java object to the output stream in the form of the CORBA
371       * {@link Any}. This includes creating an writing the object {@link TypeCode}
372       * first. Such Any can be later read by a non-RMI-IIOP CORBA implementation
373       * and manipulated, for instance, by means, provided in
374       * {@link org.omg.DynamicAny.DynAny}. Depending from the passed value, this
375       * method writes CORBA object, value type or value box. For value types Null
376       * is written with the abstract interface, its typecode having repository id
377       * "IDL:omg.org/CORBA/AbstractBase:1.0" and the empty string name.
378       *
379       * @param output the object to write.
380       * @param object the java object that must be written in the form of the CORBA
381       * {@link Any}.
382       */
383      public static void writeAny(OutputStream output, java.lang.Object object)
384      {
385        delegate.writeAny(output, object);
386      }
387      
388      /**
389       * Read Any from the input stream.
390       */
391      public static java.lang.Object readAny(InputStream input)
392      {
393        return delegate.readAny(input);
394      }
395    
396      /**
397       * Write the passed parameter to the output stream as CORBA object. If the
398       * parameter is an instance of Remote and not an instance of Stub, the method
399       * instantiates a suitable Tie, connects the parameter to this Tie and then
400       * connects that Tie to the ORB that is requested from the output stream. Then
401       * the object reference is written to the stream, making remote invocations
402       * possible (the ORB is started and activated, if required). This method is
403       * used in write_value(..) method group in
404       * {@link org.omg.CORBA_2_3.portable.OutputStream} and also may be called
405       * directly from generated Stubs and Ties.
406       *
407       * @param output a stream to write to, must be
408       * org.omg.CORBA_2_3.portable.OutputStream
409       * @param object an object to write.
410       */
411      public static void writeRemoteObject(OutputStream output,
412        java.lang.Object object)
413    {    {
414      if(delegate != null)      delegate.writeRemoteObject(output, object);
       delegate.writeRemoteObject(out, obj);  
415    }    }
416    }
 }  

Legend:
Removed from v.1.4  
changed lines
  Added in v.1.5

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26