001    /* ObjectImpl.java --
002       Copyright (C) 2005, 2006 Free Software Foundation, Inc.
003    
004    This file is part of GNU Classpath.
005    
006    GNU Classpath is free software; you can redistribute it and/or modify
007    it under the terms of the GNU General Public License as published by
008    the Free Software Foundation; either version 2, or (at your option)
009    any later version.
010    
011    GNU Classpath is distributed in the hope that it will be useful, but
012    WITHOUT ANY WARRANTY; without even the implied warranty of
013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014    General Public License for more details.
015    
016    You should have received a copy of the GNU General Public License
017    along with GNU Classpath; see the file COPYING.  If not, write to the
018    Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
019    02110-1301 USA.
020    
021    Linking this library statically or dynamically with other modules is
022    making a combined work based on this library.  Thus, the terms and
023    conditions of the GNU General Public License cover the whole
024    combination.
025    
026    As a special exception, the copyright holders of this library give you
027    permission to link this library with independent modules to produce an
028    executable, regardless of the license terms of these independent
029    modules, and to copy and distribute the resulting executable under
030    terms of your choice, provided that you also meet, for each linked
031    independent module, the terms and conditions of the license of that
032    module.  An independent module is a module which is not derived from
033    or based on this library.  If you modify this library, you may extend
034    this exception to your version of the library, but you are not
035    obligated to do so.  If you do not wish to do so, delete this
036    exception statement from your version. */
037    
038    
039    package org.omg.CORBA.portable;
040    
041    import org.omg.CORBA.BAD_PARAM;
042    import org.omg.CORBA.Context;
043    import org.omg.CORBA.ContextList;
044    import org.omg.CORBA.DomainManager;
045    import org.omg.CORBA.ExceptionList;
046    import org.omg.CORBA.NVList;
047    import org.omg.CORBA.NamedValue;
048    import org.omg.CORBA.ORB;
049    import org.omg.CORBA.Policy;
050    import org.omg.CORBA.Request;
051    import org.omg.CORBA.SetOverrideType;
052    
053    /**
054     * The basic implementation of the CORBA Object. The most of the methods
055     * delegate the functionality to the {@link Delegate} that can be replaced
056     * by {@link #_set_delegate(Delegate)}.
057     *
058     * @author Audrius Meskauskas (AudriusA@Bioinformatics.org)
059     */
060    public abstract class ObjectImpl
061      implements org.omg.CORBA.Object
062    {
063      /**
064       * The delegate, responsible for the method implementations.
065       */
066      transient Delegate delegate;
067    
068      /**
069        * Create a request to invoke the method of this object, specifying
070        * context list and the list of the expected exception.
071        *
072        * @param context a list of additional properties.
073        * @param operation the name of method to be invoked.
074        * @param parameters the method parameters.
075        * @param returns the container for tge method returned value.
076        * @param exceptions the list of the possible exceptions that the method
077        * can throw.
078        * @param ctx_list the list of the context strings that need to be
079        * resolved and send as a context instance.
080        *
081        * @return the created reaquest.
082        */
083      public Request _create_request(Context context, String operation,
084                                     NVList parameters, NamedValue returns,
085                                     ExceptionList exceptions, ContextList ctx_list
086                                    )
087      {
088        return delegate.create_request(this, context, operation, parameters,
089                                       returns, exceptions, ctx_list
090                                      );
091      }
092    
093      /**
094       * Create a request to invoke the method of this object.
095       *
096       * @param context a list of additional properties.
097       * @param operation the name of method to be invoked.
098       * @param parameters the method parameters.
099       * @param returns the container for tge method returned value.
100       *
101       * @return the created reaquest.
102       */
103      public Request _create_request(Context context, String operation,
104                                     NVList parameters, NamedValue returns
105                                    )
106      {
107        return delegate.create_request(this, context, operation, parameters, returns);
108      }
109    
110      /**
111       * Duplicate the object reference. This does not make much sense for
112       * java platform and is just included for the sake of compliance with
113       * CORBA APIs.
114       *
115       * The method may return the object reference itself.
116       *
117       * @return as a rule, <code>this</code>.
118       */
119      public org.omg.CORBA.Object _duplicate()
120      {
121        return delegate.duplicate(this);
122      }
123    
124      /**
125       * Get vendor specific delegate, responsible for the implemented
126       * functionality.
127       */
128      public Delegate _get_delegate()
129      {
130        return delegate;
131      }
132    
133      /**
134       * Retrieve the domain managers for this object.
135       *
136       * @return the domain managers.
137       */
138      public DomainManager[] _get_domain_managers()
139      {
140        return delegate.get_domain_managers(this);
141      }
142    
143      /**
144       * Get the <code>InterfaceDef</code> for this Object.
145       */
146      public org.omg.CORBA.Object _get_interface_def()
147      {
148        return delegate.get_interface_def(this);
149      }
150    
151      /**
152       * Returns the {@link Policy}, applying to this object.
153       *
154       * @param a_policy_type a type of policy to be obtained.
155       * @return a corresponding Policy object.
156       *
157       * @throws BAD_PARAM if the policy of the given type is not
158       * associated with this object, or if it is not supported by this ORB.
159       */
160      public Policy _get_policy(int a_policy_type)
161      {
162        return delegate.get_policy(this, a_policy_type);
163      }
164    
165      /**
166       * Get the array of interface repository ids, defining this object.
167       */
168      public abstract String[] _ids();
169    
170      /**
171       * Get the hashcode this object reference. The same hashcode still
172       * does not means that the references are the same. From the other
173       * side, two different references may still refer to the same CORBA
174       * object. The returned value must not change during the object
175       * lifetime.
176       *
177       * @param max the maximal value to return.
178       *
179       * @return the hashcode.
180       */
181      public int _hash(int max)
182      {
183        return delegate.hash(this, max);
184      }
185    
186      /**
187       * Invoke the operation.
188       *
189       * @param output the stream, containing the written arguments.
190       *
191       * @return the stream, from where the input parameters could be read.
192       *
193       * @throws ApplicationException if the application throws an exception,
194       * defined as a part of its remote method definition.
195       *
196       * @throws RemarshalException if reading(remarshalling) fails.
197       */
198      public InputStream _invoke(OutputStream output)
199                          throws org.omg.CORBA.portable.ApplicationException,
200                                 org.omg.CORBA.portable.RemarshalException
201      {
202        return delegate.invoke(this, output);
203      }
204    
205      /**
206       * Check if this object can be referenced by the given repository id.
207       *
208       * @param idl_id the repository id.
209       *
210       * @return true if the passed parameter is a repository id of this
211       * CORBA object.
212       */
213      public boolean _is_a(String idl_id)
214      {
215        return delegate.is_a(this, idl_id);
216      }
217    
218      /**
219       * Return true if the other object references are equivalent, so far as
220       * it is possible to determine this easily.
221       *
222       * @param other the other object reference.
223       *
224       * @return true if both references refer the same object, false
225       * if they probably can refer different objects. Uses direct
226       * comparison if the delegate has not been set.
227       */
228      public boolean _is_equivalent(org.omg.CORBA.Object other)
229      {
230        return (delegate == null) ? this == other
231               : delegate.is_equivalent(this, other);
232      }
233    
234      /**
235       * Returns true if the object is local.
236       *
237       * @return false, always (following 1.4 specs). Override to get
238       * functionality.
239       */
240      public boolean _is_local()
241      {
242        return delegate.is_local(this);
243      }
244    
245      /**
246      * Determines if the server object for this reference has already
247      * been destroyed.
248      *
249      * @return true if the object has been destroyed, false otherwise.
250      */
251      public boolean _non_existent()
252      {
253        return delegate.non_existent(this);
254      }
255    
256      /**
257       * Provides the reference to ORB.
258       *
259       * @return the associated ORB.
260       */
261      public ORB _orb()
262      {
263        return delegate.orb(this);
264      }
265    
266      /**
267       * Free resoureces, occupied by this reference. The object implementation
268       * is not notified, and the other references to the same object are not
269       * affected.
270       */
271      public void _release()
272      {
273        delegate.release(this);
274      }
275    
276      /**
277       * Release the reply stream back to ORB after finishing reading the data
278       * from it.
279       *
280       * @param stream the stream, normally returned by {@link #_invoke} or
281       * {@link ApplicationException#getInputStream()}, can be null.
282       */
283      public void _releaseReply(InputStream stream)
284      {
285        if (delegate != null)
286          delegate.releaseReply(this, stream);
287      }
288    
289      /**
290       * Create a request to invoke the method of this CORBA object.
291       *
292       * @param method the name of the method to invoke.
293       *
294       * @return the request.
295       */
296      public Request _request(String method)
297      {
298        return delegate.request(this, method);
299      }
300    
301      /**
302       * Create a request to invoke the method of this CORBA object.
303       *
304       * @param method the name of the method to invoke.
305       * @param response_expected specifies if this is one way message or the
306       * response to the message is expected.
307       *
308       * @return the stream where the method arguments should be written.
309       */
310      public org.omg.CORBA.portable.OutputStream _request(String method,
311                                                          boolean response_expected
312                                                         )
313      {
314        return delegate.request(this, method, response_expected);
315      }
316    
317      /**
318       * This method is always called after invoking the operation on the
319       * local servant.
320       *
321       * The default method returns without action.
322       *
323       * @param servant the servant.
324       */
325      public void _servant_postinvoke(ServantObject servant)
326      {
327        delegate.servant_postinvoke(this, servant);
328      }
329    
330      /**
331       * Returns a servant that should be used for this request.
332       * The servant can also be casted to the expected type, calling the
333       * required method directly.
334       *
335       * @param method the operation
336       * @param expected_type the expected type of the servant.
337       *
338       * This implementation always returns null; override for different
339       * behavior.
340       *
341       * @return the servant or null if the servant is not an expected type
342       * of the method is not supported, for example, due security reasons.
343       */
344      public ServantObject _servant_preinvoke(String method, Class expected_type)
345      {
346        return delegate.servant_preinvoke(this, method, expected_type);
347      }
348    
349      /**
350       * Set the delegate, responsible for the implemented functionality.
351       *
352       * @param a_delegate a delegate, responsible for the implemented
353       * functionality.
354       */
355      public void _set_delegate(Delegate a_delegate)
356      {
357        delegate = a_delegate;
358      }
359    
360      /**
361       * Returns a new object with the new policies either replacing or
362       * extending the current policies, depending on the second parameter.
363       *
364       * @param policies the policy additions or replacements.
365       * @param how either {@link SetOverrideType#SET_OVERRIDE} to override the
366       * current policies of {@link SetOverrideType#ADD_OVERRIDE} to replace
367       * them.
368       */
369      public org.omg.CORBA.Object _set_policy_override(Policy[] policies,
370                                                       SetOverrideType how
371                                                      )
372      {
373        return delegate.set_policy_override(this, policies, how);
374      }
375    
376      /**
377       * Check if this object is equal to another object.
378       *
379       * @param other the other object to compare.
380       *
381       * @return true if the objects are equal.
382       */
383      public boolean equals(java.lang.Object other)
384      {
385        if (delegate == null)
386          return this == other;
387        else
388          return delegate.equals(this, other);
389      }
390    
391      /**
392       * Return the string representation of the passed object.
393       *
394       * @return the string representation.
395       */
396      public String toString()
397      {
398        return delegate.toString(this);
399      }
400    }