Source for org.omg.CORBA.portable.ObjectImpl

   1: /* ObjectImpl.java --
   2:    Copyright (C) 2005 Free Software Foundation, Inc.
   3: 
   4: This file is part of GNU Classpath.
   5: 
   6: GNU Classpath is free software; you can redistribute it and/or modify
   7: it under the terms of the GNU General Public License as published by
   8: the Free Software Foundation; either version 2, or (at your option)
   9: any later version.
  10: 
  11: GNU Classpath is distributed in the hope that it will be useful, but
  12: WITHOUT ANY WARRANTY; without even the implied warranty of
  13: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  14: General Public License for more details.
  15: 
  16: You should have received a copy of the GNU General Public License
  17: along with GNU Classpath; see the file COPYING.  If not, write to the
  18: Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  19: 02110-1301 USA.
  20: 
  21: Linking this library statically or dynamically with other modules is
  22: making a combined work based on this library.  Thus, the terms and
  23: conditions of the GNU General Public License cover the whole
  24: combination.
  25: 
  26: As a special exception, the copyright holders of this library give you
  27: permission to link this library with independent modules to produce an
  28: executable, regardless of the license terms of these independent
  29: modules, and to copy and distribute the resulting executable under
  30: terms of your choice, provided that you also meet, for each linked
  31: independent module, the terms and conditions of the license of that
  32: module.  An independent module is a module which is not derived from
  33: or based on this library.  If you modify this library, you may extend
  34: this exception to your version of the library, but you are not
  35: obligated to do so.  If you do not wish to do so, delete this
  36: exception statement from your version. */
  37: 
  38: 
  39: package org.omg.CORBA.portable;
  40: 
  41: import org.omg.CORBA.Context;
  42: import org.omg.CORBA.ContextList;
  43: import org.omg.CORBA.DomainManager;
  44: import org.omg.CORBA.ExceptionList;
  45: import org.omg.CORBA.NVList;
  46: import org.omg.CORBA.NamedValue;
  47: import org.omg.CORBA.ORB;
  48: import org.omg.CORBA.Policy;
  49: import org.omg.CORBA.Request;
  50: import org.omg.CORBA.SetOverrideType;
  51: 
  52: /**
  53:  * The basic implementation of the CORBA Object. The most of the methods
  54:  * delegate the functionality to the {@link Delegate} that can be replaced
  55:  * by {@link #_set_delegate(Delegate)}.
  56:  *
  57:  * @author Audrius Meskauskas (AudriusA@Bioinformatics.org)
  58:  */
  59: public abstract class ObjectImpl
  60:   implements org.omg.CORBA.Object
  61: {
  62:   /**
  63:    * The delegate, responsible for the method implementations.
  64:    */
  65:   transient Delegate delegate;
  66: 
  67:   /**
  68:     * Create a request to invoke the method of this object, specifying
  69:     * context list and the list of the expected exception.
  70:     *
  71:     * @param context a list of additional properties.
  72:     * @param operation the name of method to be invoked.
  73:     * @param parameters the method parameters.
  74:     * @param returns the container for tge method returned value.
  75:     * @param exceptions the list of the possible exceptions that the method
  76:     * can throw.
  77:     * @param ctx_list the list of the context strings that need to be
  78:     * resolved and send as a context instance.
  79:     *
  80:     * @return the created reaquest.
  81:     */
  82:   public Request _create_request(Context context, String operation,
  83:                                  NVList parameters, NamedValue returns,
  84:                                  ExceptionList exceptions, ContextList ctx_list
  85:                                 )
  86:   {
  87:     return delegate.create_request(this, context, operation, parameters,
  88:                                    returns, exceptions, ctx_list
  89:                                   );
  90:   }
  91: 
  92:   /**
  93:    * Create a request to invoke the method of this object.
  94:    *
  95:    * @param context a list of additional properties.
  96:    * @param operation the name of method to be invoked.
  97:    * @param parameters the method parameters.
  98:    * @param returns the container for tge method returned value.
  99:    *
 100:    * @return the created reaquest.
 101:    */
 102:   public Request _create_request(Context context, String operation,
 103:                                  NVList parameters, NamedValue returns
 104:                                 )
 105:   {
 106:     return delegate.create_request(this, context, operation, parameters, returns);
 107:   }
 108: 
 109:   /**
 110:    * Duplicate the object reference. This does not make much sense for
 111:    * java platform and is just included for the sake of compliance with
 112:    * CORBA APIs.
 113:    *
 114:    * The method may return the object reference itself.
 115:    *
 116:    * @return as a rule, <code>this</code>.
 117:    */
 118:   public org.omg.CORBA.Object _duplicate()
 119:   {
 120:     return delegate.duplicate(this);
 121:   }
 122: 
 123:   /**
 124:    * Get vendor specific delegate, responsible for the implemented
 125:    * functionality.
 126:    */
 127:   public Delegate _get_delegate()
 128:   {
 129:     return delegate;
 130:   }
 131: 
 132:   /**
 133:    * Retrieve the domain managers for this object.
 134:    *
 135:    * @return the domain managers.
 136:    */
 137:   public DomainManager[] _get_domain_managers()
 138:   {
 139:     return delegate.get_domain_managers(this);
 140:   }
 141: 
 142:   /**
 143:    * Get the <code>InterfaceDef</code> for this Object.
 144:    */
 145:   public org.omg.CORBA.Object _get_interface_def()
 146:   {
 147:     return delegate.get_interface_def(this);
 148:   }
 149: 
 150:   /**
 151:    * Returns the {@link Policy}, applying to this object.
 152:    *
 153:    * @param a_policy_type a type of policy to be obtained.
 154:    * @return a corresponding Policy object.
 155:    *
 156:    * @throws BAD_PARAM if the policy of the given type is not
 157:    * associated with this object, or if it is not supported by this ORB.
 158:    */
 159:   public Policy _get_policy(int type)
 160:   {
 161:     return delegate.get_policy(this, type);
 162:   }
 163: 
 164:   /**
 165:    * Get the array of interface repository ids, defining this object.
 166:    */
 167:   public abstract String[] _ids();
 168: 
 169:   /**
 170:    * Get the hashcode this object reference. The same hashcode still
 171:    * does not means that the references are the same. From the other
 172:    * side, two different references may still refer to the same CORBA
 173:    * object. The returned value must not change during the object
 174:    * lifetime.
 175:    *
 176:    * @param maximum the maximal value to return.
 177:    *
 178:    * @return the hashcode.
 179:    */
 180:   public int _hash(int max)
 181:   {
 182:     return delegate.hash(this, max);
 183:   }
 184: 
 185:   /**
 186:    * Invoke the operation.
 187:    *
 188:    * @param output the stream, containing the written arguments.
 189:    *
 190:    * @return the stream, from where the input parameters could be read.
 191:    *
 192:    * @throws ApplicationException if the application throws an exception,
 193:    * defined as a part of its remote method definition.
 194:    *
 195:    * @throws RemarshalException if reading(remarshalling) fails.
 196:    */
 197:   public InputStream _invoke(OutputStream output)
 198:                       throws org.omg.CORBA.portable.ApplicationException,
 199:                              org.omg.CORBA.portable.RemarshalException
 200:   {
 201:     return delegate.invoke(this, output);
 202:   }
 203: 
 204:   /**
 205:    * Check if this object can be referenced by the given repository id.
 206:    *
 207:    * @param repositoryIdentifer the repository id.
 208:    *
 209:    * @return true if the passed parameter is a repository id of this
 210:    * CORBA object.
 211:    */
 212:   public boolean _is_a(String idl_id)
 213:   {
 214:     return delegate.is_a(this, idl_id);
 215:   }
 216: 
 217:   /**
 218:    * Return true if the other object references are equivalent, so far as
 219:    * it is possible to determine this easily.
 220:    *
 221:    * @param other the other object reference.
 222:    *
 223:    * @return true if both references refer the same object, false
 224:    * if they probably can refer different objects. Uses direct
 225:    * comparison if the delegate has not been set.
 226:    */
 227:   public boolean _is_equivalent(org.omg.CORBA.Object other)
 228:   {
 229:     return (delegate == null) ? this == other
 230:            : delegate.is_equivalent(this, other);
 231:   }
 232: 
 233:   /**
 234:    * Returns true if the object is local.
 235:    *
 236:    * @param self the object to check.
 237:    *
 238:    * @return false, always (following 1.4 specs). Override to get
 239:    * functionality.
 240:    */
 241:   public boolean _is_local()
 242:   {
 243:     return delegate.is_local(this);
 244:   }
 245: 
 246:   /**
 247:   * Determines if the server object for this reference has already
 248:   * been destroyed.
 249:   *
 250:   * @return true if the object has been destroyed, false otherwise.
 251:   */
 252:   public boolean _non_existent()
 253:   {
 254:     return delegate.non_existent(this);
 255:   }
 256: 
 257:   /**
 258:    * Provides the reference to ORB.
 259:    *
 260:    * @return the associated ORB.
 261:    */
 262:   public ORB _orb()
 263:   {
 264:     return delegate.orb(this);
 265:   }
 266: 
 267:   /**
 268:    * Free resoureces, occupied by this reference. The object implementation
 269:    * is not notified, and the other references to the same object are not
 270:    * affected.
 271:    */
 272:   public void _release()
 273:   {
 274:     delegate.release(this);
 275:   }
 276: 
 277:   /**
 278:    * Release the reply stream back to ORB after finishing reading the data
 279:    * from it.
 280:    *
 281:    * @param input the stream, normally returned by {@link #invoke} or
 282:    * {@link ApplicationException#getInputStream()}, can be null.
 283:    *
 284:    * @throws NO_IMPLEMENT, always (following the 1.4 specification).
 285:    */
 286:   public void _releaseReply(InputStream stream)
 287:   {
 288:     if (delegate != null)
 289:       delegate.releaseReply(this, stream);
 290:   }
 291: 
 292:   /**
 293:    * Create a request to invoke the method of this CORBA object.
 294:    *
 295:    * @param operation the name of the method to invoke.
 296:    *
 297:    * @return the request.
 298:    */
 299:   public Request _request(String method)
 300:   {
 301:     return delegate.request(this, method);
 302:   }
 303: 
 304:   /**
 305:    * Create a request to invoke the method of this CORBA object.
 306:    *
 307:    * @param operation the name of the method to invoke.
 308:    * @param response_expected specifies if this is one way message or the
 309:    * response to the message is expected.
 310:    *
 311:    * @return the stream where the method arguments should be written.
 312:    */
 313:   public org.omg.CORBA.portable.OutputStream _request(String method,
 314:                                                       boolean response_expected
 315:                                                      )
 316:   {
 317:     return delegate.request(this, method, response_expected);
 318:   }
 319: 
 320:   /**
 321:    * This method is always called after invoking the operation on the
 322:    * local servant.
 323:    *
 324:    * The default method returns without action.
 325:    *
 326:    * @param self the object.
 327:    * @param servant the servant.
 328:    */
 329:   public void _servant_postinvoke(ServantObject servant)
 330:   {
 331:     delegate.servant_postinvoke(this, servant);
 332:   }
 333: 
 334:   /**
 335:    * Returns a servant that should be used for this request.
 336:    * The servant can also be casted to the expected type, calling the
 337:    * required method directly.
 338:    *
 339:    * @param self the object
 340:    * @param operation the operation
 341:    * @param expectedType the expected type of the servant.
 342:    *
 343:    * This implementation always returns null; override for different
 344:    * behavior.
 345:    *
 346:    * @return the servant or null if the servant is not an expected type
 347:    * of the method is not supported, for example, due security reasons.
 348:    */
 349:   public ServantObject _servant_preinvoke(String method, Class expected_type)
 350:   {
 351:     return delegate.servant_preinvoke(this, method, expected_type);
 352:   }
 353: 
 354:   /**
 355:    * Set the delegate, responsible for the implemented functionality.
 356:    *
 357:    * @param a_delegate a delegate, responsible for the implemented
 358:    * functionality.
 359:    */
 360:   public void _set_delegate(Delegate a_delegate)
 361:   {
 362:     delegate = a_delegate;
 363:   }
 364: 
 365:   /**
 366:    * Returns a new object with the new policies either replacing or
 367:    * extending the current policies, depending on the second parameter.
 368:    *
 369:    * @param policies the policy additions or replacements.
 370:    * @param how either {@link SetOverrideType#SET_OVERRIDE} to override the
 371:    * current policies of {@link SetOverrideType#ADD_OVERRIDE} to replace
 372:    * them.
 373:    */
 374:   public org.omg.CORBA.Object _set_policy_override(Policy[] policies,
 375:                                                    SetOverrideType set_add
 376:                                                   )
 377:   {
 378:     return delegate.set_policy_override(this, policies, set_add);
 379:   }
 380: 
 381:   /**
 382:    * Check if this object is equal to another object.
 383:    *
 384:    * @param other the other object to compare.
 385:    *
 386:    * @return true if the objects are equal.
 387:    */
 388:   public boolean equals(java.lang.Object other)
 389:   {
 390:     if (delegate == null)
 391:       return this == other;
 392:     else
 393:       return delegate.equals(this, other);
 394:   }
 395: 
 396:   /**
 397:    * Return the string representation of the passed object.
 398:    *
 399:    * @return the string representation.
 400:    */
 401:   public String toString()
 402:   {
 403:     return delegate.toString(this);
 404:   }