KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > omg > CORBA > portable > ObjectImpl


1 /*
2  * @(#)ObjectImpl.java 1.37 03/12/19
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7 package org.omg.CORBA.portable;
8
9 import org.omg.CORBA.Request JavaDoc;
10 import org.omg.CORBA.NamedValue JavaDoc;
11 import org.omg.CORBA.NVList JavaDoc;
12 import org.omg.CORBA.ExceptionList JavaDoc;
13 import org.omg.CORBA.ContextList JavaDoc;
14 import org.omg.CORBA.Context JavaDoc;
15 import org.omg.CORBA.TypeCode JavaDoc;
16 import org.omg.CORBA.BAD_OPERATION JavaDoc;
17 import org.omg.CORBA.SystemException JavaDoc;
18
19
20 /**
21  * The common base class for all stub classes; provides default implementations
22  * of the <code>org.omg.CORBA.Object</code> methods. All method implementations are
23  * forwarded to a <code>Delegate</code> object stored in the <code>ObjectImpl</code>
24  * instance. <code>ObjectImpl</code> allows for portable stubs because the
25  * <code>Delegate</code> can be implemented by a different vendor-specific ORB.
26  */

27
28 abstract public class ObjectImpl implements org.omg.CORBA.Object JavaDoc
29 {
30
31     /**
32      * The field that stores the <code>Delegate</code> instance for
33      * this <code>ObjectImpl</code> object. This <code>Delegate</code>
34      * instance can be implemented by a vendor-specific ORB. Stub classes,
35      * which are derived from this <code>ObjectImpl</code> class, can be
36      * portable because they delegate all of the methods called on them to this
37      * <code>Delegate</code> object.
38      */

39     private transient Delegate JavaDoc __delegate;
40
41
42     /**
43      * Retrieves the reference to the vendor-specific <code>Delegate</code>
44      * object to which this <code>ObjectImpl</code> object delegates all
45      * methods invoked on it.
46      *
47      * @return the Delegate contained in this ObjectImpl instance
48      * @throws BAD_OPERATION if the delegate has not been set
49      * @see #_set_delegate
50      */

51     public Delegate JavaDoc _get_delegate() {
52         if (__delegate == null)
53         throw new BAD_OPERATION JavaDoc("The delegate has not been set!");
54         return __delegate;
55     }
56
57
58     /**
59      * Sets the Delegate for this <code>ObjectImpl</code> instance to the given
60      * <code>Delegate</code> object. All method invocations on this
61      * <code>ObjectImpl</code> object will be forwarded to this delegate.
62      *
63      * @param delegate the <code>Delegate</code> instance to which
64      * all method calls on this <code>ObjectImpl</code> object
65      * will be delegated; may be implemented by a third-party ORB
66      * @see #_get_delegate
67      */

68     public void _set_delegate(Delegate JavaDoc delegate) {
69         __delegate = delegate;
70     }
71
72     /**
73      * Retrieves a string array containing the repository identifiers
74      * supported by this <code>ObjectImpl</code> object. For example,
75      * for a stub, this method returns information about all the
76      * interfaces supported by the stub.
77      *
78      * @return the array of all repository identifiers supported by this
79      * <code>ObjectImpl</code> instance
80      */

81     public abstract String JavaDoc[] _ids();
82
83
84     /**
85      * Returns a duplicate of this <code>ObjectImpl</code> object.
86      *
87      * @return an <code>orb.omg.CORBA.Object</code> object that is
88      * a duplicate of this object
89      */

90     public org.omg.CORBA.Object JavaDoc _duplicate() {
91         return _get_delegate().duplicate(this);
92     }
93
94     /**
95      * Releases the resources associated with this <code>ObjectImpl</code> object.
96      */

97     public void _release() {
98         _get_delegate().release(this);
99     }
100
101     /**
102      * Checks whether the object identified by the given repository
103      * identifier is an <code>ObjectImpl</code> object.
104      *
105      * @param repository_id a <code>String</code> object with the repository
106      * identifier to check
107      * @return <code>true</code> if the object identified by the given
108      * repository id is an instance of <code>ObjectImpl</code>;
109      * <code>false</code> otherwise
110      */

111     public boolean _is_a(String JavaDoc repository_id) {
112         return _get_delegate().is_a(this, repository_id);
113     }
114
115     /**
116      * Checks whether the the given <code>ObjectImpl</code> object is
117      * equivalent to this <code>ObjectImpl</code> object.
118      *
119      * @param that an instance of <code>ObjectImpl</code> to compare with
120      * this <code>ObjectImpl</code> object
121      * @return <code>true</code> if the given object is equivalent
122      * to this <code>ObjectImpl</code> object;
123      * <code>false</code> otherwise
124      */

125     public boolean _is_equivalent(org.omg.CORBA.Object JavaDoc that) {
126         return _get_delegate().is_equivalent(this, that);
127     }
128
129     /**
130      * Checks whether the server object for this <code>ObjectImpl</code>
131      * object has been destroyed.
132      *
133      * @return <code>true</code> if the ORB knows authoritatively that the
134      * server object does not exist; <code>false</code> otherwise
135      */

136     public boolean _non_existent() {
137         return _get_delegate().non_existent(this);
138     }
139
140     /**
141      * Retrieves the hash code that serves as an ORB-internal identifier for
142      * this <code>ObjectImpl</code> object.
143      *
144      * @param maximum an <code>int</code> indicating the upper bound on the hash
145      * value returned by the ORB
146      * @return an <code>int</code> representing the hash code for this
147      * <code>ObjectImpl</code> object
148      */

149     public int _hash(int maximum) {
150         return _get_delegate().hash(this, maximum);
151     }
152
153     /**
154      * Creates a <code>Request</code> object containing the given method
155      * that can be used with the Dynamic Invocation Interface.
156      *
157      * @param operation the method to be invoked by the new <code>Request</code>
158      * object
159      * @return a new <code>Request</code> object initialized with the
160      * given method
161      */

162     public Request JavaDoc _request(String JavaDoc operation) {
163         return _get_delegate().request(this, operation);
164     }
165
166     /**
167      * Creates a <code>Request</code> object that contains the given context,
168      * method, argument list, and container for the result.
169      *
170      * @param ctx the Context for the request
171      * @param operation the method that the new <code>Request</code>
172      * object will invoke
173      * @param arg_list the arguments for the method; an <code>NVList</code>
174      * in which each argument is a <code>NamedValue</code> object
175      * @param result a <code>NamedValue</code> object to be used for
176      * returning the result of executing the request's method
177      * @return a new <code>Request</code> object initialized with the
178      * given context, method, argument list, and container for the
179      * return value
180      */

181     public Request JavaDoc _create_request(Context JavaDoc ctx,
182                    String JavaDoc operation,
183                    NVList JavaDoc arg_list,
184                    NamedValue JavaDoc result) {
185         return _get_delegate().create_request(this,
186                           ctx,
187                           operation,
188                           arg_list,
189                           result);
190     }
191
192     /**
193      * Creates a <code>Request</code> object that contains the given context,
194      * method, argument list, container for the result, exceptions, and
195      * list of property names to be used in resolving the context strings.
196      * This <code>Request</code> object is for use in the Dynamic
197      * Invocation Interface.
198      *
199      * @param ctx the <code>Context</code> object that contains the
200      * context strings that must be resolved before they are
201      * sent along with the request
202      * @param operation the method that the new <code>Request</code>
203      * object will invoke
204      * @param arg_list the arguments for the method; an <code>NVList</code>
205      * in which each argument is a <code>NamedValue</code> object
206      * @param result a <code>NamedValue</code> object to be used for
207      * returning the result of executing the request's method
208      * @param exceptions a list of the exceptions that the given method
209      * throws
210      * @param contexts a list of the properties that are needed to
211      * resolve the contexts in <i>ctx</i>; the strings in
212      * <i>contexts</i> are used as arguments to the method
213      * <code>Context.get_values</code>,
214      * which returns the value associated with the given property
215      * @return a new <code>Request</code> object initialized with the
216      * given context strings to resolve, method, argument list,
217      * container for the result, exceptions, and list of property
218      * names to be used in resolving the context strings
219      */

220     public Request JavaDoc _create_request(Context JavaDoc ctx,
221                    String JavaDoc operation,
222                    NVList JavaDoc arg_list,
223                    NamedValue JavaDoc result,
224                    ExceptionList JavaDoc exceptions,
225                    ContextList JavaDoc contexts) {
226         return _get_delegate().create_request(this,
227                           ctx,
228                           operation,
229                           arg_list,
230                           result,
231                           exceptions,
232                           contexts);
233     }
234
235     /**
236      * Retrieves the interface definition for this <code>ObjectImpl</code>
237      * object.
238      *
239      * @return the <code>org.omg.CORBA.Object</code> instance that is the
240      * interface definition for this <code>ObjectImpl</code> object
241      */

242     public org.omg.CORBA.Object JavaDoc _get_interface_def()
243     {
244     // First try to call the delegate implementation class's
245
// "Object get_interface_def(..)" method (will work for JDK1.2 ORBs).
246
// Else call the delegate implementation class's
247
// "InterfaceDef get_interface(..)" method using reflection
248
// (will work for pre-JDK1.2 ORBs).
249

250         org.omg.CORBA.portable.Delegate JavaDoc delegate = _get_delegate();
251         try {
252         // If the ORB's delegate class does not implement
253
// "Object get_interface_def(..)", this will call
254
// get_interface_def(..) on portable.Delegate.
255
return delegate.get_interface_def(this);
256         }
257     catch( org.omg.CORBA.NO_IMPLEMENT JavaDoc ex ) {
258         // Call "InterfaceDef get_interface(..)" method using reflection.
259
try {
260         Class JavaDoc[] argc = { org.omg.CORBA.Object JavaDoc.class };
261             java.lang.reflect.Method JavaDoc meth =
262             delegate.getClass().getMethod("get_interface", argc);
263         Object JavaDoc[] argx = { this };
264                 return (org.omg.CORBA.Object JavaDoc)meth.invoke(delegate, argx);
265         }
266             catch( java.lang.reflect.InvocationTargetException JavaDoc exs ) {
267                 Throwable JavaDoc t = exs.getTargetException();
268                 if (t instanceof Error JavaDoc) {
269                     throw (Error JavaDoc) t;
270                 }
271                 else if (t instanceof RuntimeException JavaDoc) {
272                     throw (RuntimeException JavaDoc) t;
273                 }
274                 else {
275                     throw new org.omg.CORBA.NO_IMPLEMENT JavaDoc();
276                 }
277             } catch( RuntimeException JavaDoc rex ) {
278         throw rex;
279         } catch( Exception JavaDoc exr ) {
280                 throw new org.omg.CORBA.NO_IMPLEMENT JavaDoc();
281             }
282         }
283     }
284
285     /**
286      * Returns a reference to the ORB associated with this object and
287      * its delegate. This is the <code>ORB</code> object that created
288      * the delegate.
289      *
290      * @return the <code>ORB</code> instance that created the
291      * <code>Delegate</code> object contained in this
292      * <code>ObjectImpl</code> object
293      */

294     public org.omg.CORBA.ORB JavaDoc _orb() {
295         return _get_delegate().orb(this);
296     }
297
298
299     /**
300      * Retrieves the <code>Policy</code> object for this
301      * <code>ObjectImpl</code> object that has the given
302      * policy type.
303      *
304      * @param policy_type an int indicating the policy type
305      * @return the <code>Policy</code> object that is the specified policy type
306      * and that applies to this <code>ObjectImpl</code> object
307      * @see org.omg.CORBA.PolicyOperations#policy_type
308      */

309     public org.omg.CORBA.Policy JavaDoc _get_policy(int policy_type) {
310         return _get_delegate().get_policy(this, policy_type);
311     }
312
313     /**
314      * Retrieves a list of the domain managers for this
315      * <code>ObjectImpl</code> object.
316      *
317      * @return an array containing the <code>DomainManager</code>
318      * objects for this instance of <code>ObjectImpl</code>
319      */

320     public org.omg.CORBA.DomainManager JavaDoc[] _get_domain_managers() {
321         return _get_delegate().get_domain_managers(this);
322     }
323
324     /**
325      * Sets this <code>ObjectImpl</code> object's override type for
326      * the given policies to the given instance of
327      * <code>SetOverrideType</code>.
328      *
329      * @param policies an array of <code>Policy</code> objects with the
330      * policies that will replace the current policies or be
331      * added to the current policies
332      * @param set_add either <code>SetOverrideType.SET_OVERRIDE</code>,
333      * indicating that the given policies will replace any existing
334      * ones, or <code>SetOverrideType.ADD_OVERRIDE</code>, indicating
335      * that the given policies should be added to any existing ones
336      * @return an <code>Object</code> with the given policies replacing or
337      * added to its previous policies
338      */

339     public org.omg.CORBA.Object JavaDoc
340     _set_policy_override(org.omg.CORBA.Policy JavaDoc[] policies,
341                  org.omg.CORBA.SetOverrideType JavaDoc set_add) {
342     return _get_delegate().set_policy_override(this, policies,
343                            set_add);
344     }
345
346     /**
347      * Checks whether this <code>ObjectImpl</code> object is implemented
348      * by a local servant. If so, local invocation API's may be used.
349      *
350      * @return <code>true</code> if this object is implemented by a local
351      * servant; <code>false</code> otherwise
352      */

353     public boolean _is_local() {
354         return _get_delegate().is_local(this);
355     }
356
357     /**
358      * Returns a Java reference to the local servant that should be used for sending
359      * a request for the method specified. If this <code>ObjectImpl</code>
360      * object is a local stub, it will invoke the <code>_servant_preinvoke</code>
361      * method before sending a request in order to obtain the
362      * <code>ServantObject</code> instance to use.
363      * <P>
364      * If a <code>ServantObject</code> object is returned, its <code>servant</code>
365      * field has been set to an object of the expected type (Note: the object may
366      * or may not be the actual servant instance). The local stub may cast
367      * the servant field to the expected type, and then invoke the operation
368      * directly. The <code>ServantRequest</code> object is valid for only one
369      * invocation and cannot be used for more than one invocation.
370      *
371      * @param operation a <code>String</code> containing the name of the method
372      * to be invoked. This name should correspond to the method name as
373      * it would be encoded in a GIOP request.
374      *
375      * @param expectedType a <code>Class</code> object representing the
376      * expected type of the servant that is returned. This expected
377      * type is the <code>Class</code> object associated with the
378      * operations class for the stub's interface. For example, a
379      * stub for an interface <code>Foo</code> would pass the
380      * <code>Class</code> object for the <code>FooOperations</code>
381      * interface.
382      *
383      * @return (1) a <code>ServantObject</code> object, which may or may
384      * not be the actual servant instance, or (2) <code>null</code> if
385      * (a) the servant is not local or (b) the servant has ceased to
386      * be local due to a ForwardRequest from a POA ServantManager
387      * @throws org.omg.CORBA.BAD_PARAM if the servant is not the expected type
388      */

389     public ServantObject JavaDoc _servant_preinvoke(String JavaDoc operation,
390                                             Class JavaDoc expectedType) {
391         return _get_delegate().servant_preinvoke(this, operation,
392                          expectedType);
393     }
394
395     /**
396      * Is called by the local stub after it has invoked an operation
397      * on the local servant that was previously retrieved from a
398      * call to the method <code>_servant_preinvoke</code>.
399      * The <code>_servant_postinvoke</code> method must be called
400      * if the <code>_servant_preinvoke</code>
401      * method returned a non-null value, even if an exception was thrown
402      * by the method invoked by the servant. For this reason, the call
403      * to the method <code>_servant_postinvoke</code> should be placed
404      * in a Java <code>finally</code> clause.
405      *
406      * @param servant the instance of the <code>ServantObject</code>
407      * returned by the <code>_servant_preinvoke</code> method
408      */

409     public void _servant_postinvoke(ServantObject JavaDoc servant) {
410         _get_delegate().servant_postinvoke(this, servant);
411     }
412
413     /*
414      * The following methods were added by orbos/98-04-03: Java to IDL
415      * Mapping. These are used by RMI over IIOP.
416      */

417
418     /**
419      * Returns an <code>OutputStream</code> object to use for marshalling
420      * the arguments of the given method. This method is called by a stub,
421      * which must indicate if a response is expected, that is, whether or not
422      * the call is oneway.
423      *
424      * @param operation a String giving the name of the method.
425      * @param responseExpected a boolean -- <code>true</code> if the
426      * request is not one way, that is, a response is expected
427      * @return an <code>OutputStream</code> object for dispatching the request
428      */

429     public OutputStream JavaDoc _request(String JavaDoc operation,
430                  boolean responseExpected) {
431     return _get_delegate().request(this, operation, responseExpected);
432     }
433
434     /**
435      * Invokes an operation and returns an <code>InputStream</code>
436      * object for reading the response. The stub provides the
437      * <code>OutputStream</code> object that was previously returned by a
438      * call to the <code>_request</code> method. The method specified
439      * as an argument to <code>_request</code> when it was
440      * called previously is the method that this method invokes.
441      * <P>
442      * If an exception occurs, the <code>_invoke</code> method may throw an
443      * <code>ApplicationException</code> object that contains an InputStream from
444      * which the user exception state may be unmarshalled.
445      *
446      * @param output an OutputStream object for dispatching the request
447      * @return an <code>InputStream</code> object containing the marshalled
448      * response to the method invoked
449      * @throws ApplicationException if the invocation
450      * meets application-defined exception
451      * @throws RemarshalException if the invocation leads
452      * to a remarshalling error
453      * @see #_request
454      */

455     public InputStream JavaDoc _invoke(OutputStream JavaDoc output)
456     throws ApplicationException JavaDoc, RemarshalException JavaDoc {
457     return _get_delegate().invoke(this, output);
458     }
459
460     /**
461      * Releases the given
462      * reply stream back to the ORB when unmarshalling has
463      * completed after a call to the method <code>_invoke</code>.
464      * Calling this method is optional for the stub.
465      *
466      * @param input the <code>InputStream</code> object that was returned
467      * by the <code>_invoke</code> method or the
468      * <code>ApplicationException.getInputStream</code> method;
469      * may be <code>null</code>, in which case this method does
470      * nothing
471      * @see #_invoke
472      */

473     public void _releaseReply(InputStream JavaDoc input) {
474     _get_delegate().releaseReply(this, input);
475     }
476
477     /**
478      * Returns a <code>String</code> object that represents this
479      * <code>ObjectImpl</code> object.
480      *
481      * @return the <code>String</code> representation of this object
482      */

483     public String JavaDoc toString() {
484         if ( __delegate != null )
485            return __delegate.toString(this);
486         else
487            return getClass().getName() + ": no delegate set";
488     }
489
490     /**
491      * Returns the hash code for this <code>ObjectImpl</code> object.
492      *
493      * @return the hash code for this object
494      */

495     public int hashCode() {
496         if ( __delegate != null )
497            return __delegate.hashCode(this);
498         else
499            return System.identityHashCode(this);
500     }
501
502     /**
503      * Compares this <code>ObjectImpl</code> object with the given one
504      * for equality.
505      *
506      *@param obj the object with which to compare this object
507      *@return <code>true</code> if the two objects are equal;
508      * <code>false</code> otherwise
509      */

510     public boolean equals(java.lang.Object JavaDoc obj) {
511         if ( __delegate != null )
512            return __delegate.equals(this, obj);
513         else
514            return (this==obj);
515     }
516 }
517
518
Popular Tags