0N/A/*
157N/A * Copyright (c) 1997, 2006, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
157N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
157N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
157N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
157N/A * or visit www.oracle.com if you need additional information or have any
157N/A * questions.
0N/A */
0N/Apackage org.omg.CORBA.portable;
0N/A
0N/Aimport org.omg.CORBA.Request;
0N/Aimport org.omg.CORBA.NamedValue;
0N/Aimport org.omg.CORBA.NVList;
0N/Aimport org.omg.CORBA.ExceptionList;
0N/Aimport org.omg.CORBA.ContextList;
0N/Aimport org.omg.CORBA.Context;
0N/Aimport org.omg.CORBA.TypeCode;
0N/Aimport org.omg.CORBA.BAD_OPERATION;
0N/Aimport org.omg.CORBA.SystemException;
0N/A
0N/A
0N/A/**
0N/A * The common base class for all stub classes; provides default implementations
0N/A * of the <code>org.omg.CORBA.Object</code> methods. All method implementations are
0N/A * forwarded to a <code>Delegate</code> object stored in the <code>ObjectImpl</code>
0N/A * instance. <code>ObjectImpl</code> allows for portable stubs because the
0N/A * <code>Delegate</code> can be implemented by a different vendor-specific ORB.
0N/A */
0N/A
0N/Aabstract public class ObjectImpl implements org.omg.CORBA.Object
0N/A{
0N/A
0N/A /**
0N/A * The field that stores the <code>Delegate</code> instance for
0N/A * this <code>ObjectImpl</code> object. This <code>Delegate</code>
0N/A * instance can be implemented by a vendor-specific ORB. Stub classes,
0N/A * which are derived from this <code>ObjectImpl</code> class, can be
0N/A * portable because they delegate all of the methods called on them to this
0N/A * <code>Delegate</code> object.
0N/A */
0N/A private transient Delegate __delegate;
0N/A
0N/A
0N/A /**
0N/A * Retrieves the reference to the vendor-specific <code>Delegate</code>
0N/A * object to which this <code>ObjectImpl</code> object delegates all
0N/A * methods invoked on it.
0N/A *
0N/A * @return the Delegate contained in this ObjectImpl instance
0N/A * @throws BAD_OPERATION if the delegate has not been set
0N/A * @see #_set_delegate
0N/A */
0N/A public Delegate _get_delegate() {
0N/A if (__delegate == null)
0N/A throw new BAD_OPERATION("The delegate has not been set!");
0N/A return __delegate;
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Sets the Delegate for this <code>ObjectImpl</code> instance to the given
0N/A * <code>Delegate</code> object. All method invocations on this
0N/A * <code>ObjectImpl</code> object will be forwarded to this delegate.
0N/A *
0N/A * @param delegate the <code>Delegate</code> instance to which
0N/A * all method calls on this <code>ObjectImpl</code> object
0N/A * will be delegated; may be implemented by a third-party ORB
0N/A * @see #_get_delegate
0N/A */
0N/A public void _set_delegate(Delegate delegate) {
0N/A __delegate = delegate;
0N/A }
0N/A
0N/A /**
0N/A * Retrieves a string array containing the repository identifiers
0N/A * supported by this <code>ObjectImpl</code> object. For example,
0N/A * for a stub, this method returns information about all the
0N/A * interfaces supported by the stub.
0N/A *
0N/A * @return the array of all repository identifiers supported by this
0N/A * <code>ObjectImpl</code> instance
0N/A */
0N/A public abstract String[] _ids();
0N/A
0N/A
0N/A /**
0N/A * Returns a duplicate of this <code>ObjectImpl</code> object.
0N/A *
0N/A * @return an <code>orb.omg.CORBA.Object</code> object that is
0N/A * a duplicate of this object
0N/A */
0N/A public org.omg.CORBA.Object _duplicate() {
0N/A return _get_delegate().duplicate(this);
0N/A }
0N/A
0N/A /**
0N/A * Releases the resources associated with this <code>ObjectImpl</code> object.
0N/A */
0N/A public void _release() {
0N/A _get_delegate().release(this);
0N/A }
0N/A
0N/A /**
0N/A * Checks whether the object identified by the given repository
0N/A * identifier is an <code>ObjectImpl</code> object.
0N/A *
0N/A * @param repository_id a <code>String</code> object with the repository
0N/A * identifier to check
0N/A * @return <code>true</code> if the object identified by the given
0N/A * repository id is an instance of <code>ObjectImpl</code>;
0N/A * <code>false</code> otherwise
0N/A */
0N/A public boolean _is_a(String repository_id) {
0N/A return _get_delegate().is_a(this, repository_id);
0N/A }
0N/A
0N/A /**
0N/A * Checks whether the the given <code>ObjectImpl</code> object is
0N/A * equivalent to this <code>ObjectImpl</code> object.
0N/A *
0N/A * @param that an instance of <code>ObjectImpl</code> to compare with
0N/A * this <code>ObjectImpl</code> object
0N/A * @return <code>true</code> if the given object is equivalent
0N/A * to this <code>ObjectImpl</code> object;
0N/A * <code>false</code> otherwise
0N/A */
0N/A public boolean _is_equivalent(org.omg.CORBA.Object that) {
0N/A return _get_delegate().is_equivalent(this, that);
0N/A }
0N/A
0N/A /**
0N/A * Checks whether the server object for this <code>ObjectImpl</code>
0N/A * object has been destroyed.
0N/A *
0N/A * @return <code>true</code> if the ORB knows authoritatively that the
0N/A * server object does not exist; <code>false</code> otherwise
0N/A */
0N/A public boolean _non_existent() {
0N/A return _get_delegate().non_existent(this);
0N/A }
0N/A
0N/A /**
0N/A * Retrieves the hash code that serves as an ORB-internal identifier for
0N/A * this <code>ObjectImpl</code> object.
0N/A *
0N/A * @param maximum an <code>int</code> indicating the upper bound on the hash
0N/A * value returned by the ORB
0N/A * @return an <code>int</code> representing the hash code for this
0N/A * <code>ObjectImpl</code> object
0N/A */
0N/A public int _hash(int maximum) {
0N/A return _get_delegate().hash(this, maximum);
0N/A }
0N/A
0N/A /**
0N/A * Creates a <code>Request</code> object containing the given method
0N/A * that can be used with the Dynamic Invocation Interface.
0N/A *
0N/A * @param operation the method to be invoked by the new <code>Request</code>
0N/A * object
0N/A * @return a new <code>Request</code> object initialized with the
0N/A * given method
0N/A */
0N/A public Request _request(String operation) {
0N/A return _get_delegate().request(this, operation);
0N/A }
0N/A
0N/A /**
0N/A * Creates a <code>Request</code> object that contains the given context,
0N/A * method, argument list, and container for the result.
0N/A *
0N/A * @param ctx the Context for the request
0N/A * @param operation the method that the new <code>Request</code>
0N/A * object will invoke
0N/A * @param arg_list the arguments for the method; an <code>NVList</code>
0N/A * in which each argument is a <code>NamedValue</code> object
0N/A * @param result a <code>NamedValue</code> object to be used for
0N/A * returning the result of executing the request's method
0N/A * @return a new <code>Request</code> object initialized with the
0N/A * given context, method, argument list, and container for the
0N/A * return value
0N/A */
0N/A public Request _create_request(Context ctx,
0N/A String operation,
0N/A NVList arg_list,
0N/A NamedValue result) {
0N/A return _get_delegate().create_request(this,
0N/A ctx,
0N/A operation,
0N/A arg_list,
0N/A result);
0N/A }
0N/A
0N/A /**
0N/A * Creates a <code>Request</code> object that contains the given context,
0N/A * method, argument list, container for the result, exceptions, and
0N/A * list of property names to be used in resolving the context strings.
0N/A * This <code>Request</code> object is for use in the Dynamic
0N/A * Invocation Interface.
0N/A *
0N/A * @param ctx the <code>Context</code> object that contains the
0N/A * context strings that must be resolved before they are
0N/A * sent along with the request
0N/A * @param operation the method that the new <code>Request</code>
0N/A * object will invoke
0N/A * @param arg_list the arguments for the method; an <code>NVList</code>
0N/A * in which each argument is a <code>NamedValue</code> object
0N/A * @param result a <code>NamedValue</code> object to be used for
0N/A * returning the result of executing the request's method
0N/A * @param exceptions a list of the exceptions that the given method
0N/A * throws
0N/A * @param contexts a list of the properties that are needed to
0N/A * resolve the contexts in <i>ctx</i>; the strings in
0N/A * <i>contexts</i> are used as arguments to the method
0N/A * <code>Context.get_values</code>,
0N/A * which returns the value associated with the given property
0N/A * @return a new <code>Request</code> object initialized with the
0N/A * given context strings to resolve, method, argument list,
0N/A * container for the result, exceptions, and list of property
0N/A * names to be used in resolving the context strings
0N/A */
0N/A public Request _create_request(Context ctx,
0N/A String operation,
0N/A NVList arg_list,
0N/A NamedValue result,
0N/A ExceptionList exceptions,
0N/A ContextList contexts) {
0N/A return _get_delegate().create_request(this,
0N/A ctx,
0N/A operation,
0N/A arg_list,
0N/A result,
0N/A exceptions,
0N/A contexts);
0N/A }
0N/A
0N/A /**
0N/A * Retrieves the interface definition for this <code>ObjectImpl</code>
0N/A * object.
0N/A *
0N/A * @return the <code>org.omg.CORBA.Object</code> instance that is the
0N/A * interface definition for this <code>ObjectImpl</code> object
0N/A */
0N/A public org.omg.CORBA.Object _get_interface_def()
0N/A {
0N/A // First try to call the delegate implementation class's
0N/A // "Object get_interface_def(..)" method (will work for JDK1.2 ORBs).
0N/A // Else call the delegate implementation class's
0N/A // "InterfaceDef get_interface(..)" method using reflection
0N/A // (will work for pre-JDK1.2 ORBs).
0N/A
0N/A org.omg.CORBA.portable.Delegate delegate = _get_delegate();
0N/A try {
0N/A // If the ORB's delegate class does not implement
0N/A // "Object get_interface_def(..)", this will call
0N/A // get_interface_def(..) on portable.Delegate.
0N/A return delegate.get_interface_def(this);
0N/A }
0N/A catch( org.omg.CORBA.NO_IMPLEMENT ex ) {
0N/A // Call "InterfaceDef get_interface(..)" method using reflection.
0N/A try {
0N/A Class[] argc = { org.omg.CORBA.Object.class };
0N/A java.lang.reflect.Method meth =
0N/A delegate.getClass().getMethod("get_interface", argc);
0N/A Object[] argx = { this };
0N/A return (org.omg.CORBA.Object)meth.invoke(delegate, argx);
0N/A }
0N/A catch( java.lang.reflect.InvocationTargetException exs ) {
0N/A Throwable t = exs.getTargetException();
0N/A if (t instanceof Error) {
0N/A throw (Error) t;
0N/A }
0N/A else if (t instanceof RuntimeException) {
0N/A throw (RuntimeException) t;
0N/A }
0N/A else {
0N/A throw new org.omg.CORBA.NO_IMPLEMENT();
0N/A }
0N/A } catch( RuntimeException rex ) {
0N/A throw rex;
0N/A } catch( Exception exr ) {
0N/A throw new org.omg.CORBA.NO_IMPLEMENT();
0N/A }
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Returns a reference to the ORB associated with this object and
0N/A * its delegate. This is the <code>ORB</code> object that created
0N/A * the delegate.
0N/A *
0N/A * @return the <code>ORB</code> instance that created the
0N/A * <code>Delegate</code> object contained in this
0N/A * <code>ObjectImpl</code> object
0N/A */
0N/A public org.omg.CORBA.ORB _orb() {
0N/A return _get_delegate().orb(this);
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Retrieves the <code>Policy</code> object for this
0N/A * <code>ObjectImpl</code> object that has the given
0N/A * policy type.
0N/A *
0N/A * @param policy_type an int indicating the policy type
0N/A * @return the <code>Policy</code> object that is the specified policy type
0N/A * and that applies to this <code>ObjectImpl</code> object
0N/A * @see org.omg.CORBA.PolicyOperations#policy_type
0N/A */
0N/A public org.omg.CORBA.Policy _get_policy(int policy_type) {
0N/A return _get_delegate().get_policy(this, policy_type);
0N/A }
0N/A
0N/A /**
0N/A * Retrieves a list of the domain managers for this
0N/A * <code>ObjectImpl</code> object.
0N/A *
0N/A * @return an array containing the <code>DomainManager</code>
0N/A * objects for this instance of <code>ObjectImpl</code>
0N/A */
0N/A public org.omg.CORBA.DomainManager[] _get_domain_managers() {
0N/A return _get_delegate().get_domain_managers(this);
0N/A }
0N/A
0N/A /**
0N/A * Sets this <code>ObjectImpl</code> object's override type for
0N/A * the given policies to the given instance of
0N/A * <code>SetOverrideType</code>.
0N/A *
0N/A * @param policies an array of <code>Policy</code> objects with the
0N/A * policies that will replace the current policies or be
0N/A * added to the current policies
0N/A * @param set_add either <code>SetOverrideType.SET_OVERRIDE</code>,
0N/A * indicating that the given policies will replace any existing
0N/A * ones, or <code>SetOverrideType.ADD_OVERRIDE</code>, indicating
0N/A * that the given policies should be added to any existing ones
0N/A * @return an <code>Object</code> with the given policies replacing or
0N/A * added to its previous policies
0N/A */
0N/A public org.omg.CORBA.Object
0N/A _set_policy_override(org.omg.CORBA.Policy[] policies,
0N/A org.omg.CORBA.SetOverrideType set_add) {
0N/A return _get_delegate().set_policy_override(this, policies,
0N/A set_add);
0N/A }
0N/A
0N/A /**
0N/A * Checks whether this <code>ObjectImpl</code> object is implemented
0N/A * by a local servant. If so, local invocation API's may be used.
0N/A *
0N/A * @return <code>true</code> if this object is implemented by a local
0N/A * servant; <code>false</code> otherwise
0N/A */
0N/A public boolean _is_local() {
0N/A return _get_delegate().is_local(this);
0N/A }
0N/A
0N/A /**
0N/A * Returns a Java reference to the local servant that should be used for sending
0N/A * a request for the method specified. If this <code>ObjectImpl</code>
0N/A * object is a local stub, it will invoke the <code>_servant_preinvoke</code>
0N/A * method before sending a request in order to obtain the
0N/A * <code>ServantObject</code> instance to use.
0N/A * <P>
0N/A * If a <code>ServantObject</code> object is returned, its <code>servant</code>
0N/A * field has been set to an object of the expected type (Note: the object may
0N/A * or may not be the actual servant instance). The local stub may cast
0N/A * the servant field to the expected type, and then invoke the operation
0N/A * directly. The <code>ServantRequest</code> object is valid for only one
0N/A * invocation and cannot be used for more than one invocation.
0N/A *
0N/A * @param operation a <code>String</code> containing the name of the method
0N/A * to be invoked. This name should correspond to the method name as
0N/A * it would be encoded in a GIOP request.
0N/A *
0N/A * @param expectedType a <code>Class</code> object representing the
0N/A * expected type of the servant that is returned. This expected
0N/A * type is the <code>Class</code> object associated with the
0N/A * operations class for the stub's interface. For example, a
0N/A * stub for an interface <code>Foo</code> would pass the
0N/A * <code>Class</code> object for the <code>FooOperations</code>
0N/A * interface.
0N/A *
0N/A * @return (1) a <code>ServantObject</code> object, which may or may
0N/A * not be the actual servant instance, or (2) <code>null</code> if
0N/A * (a) the servant is not local or (b) the servant has ceased to
0N/A * be local due to a ForwardRequest from a POA ServantManager
0N/A * @throws org.omg.CORBA.BAD_PARAM if the servant is not the expected type
0N/A */
0N/A public ServantObject _servant_preinvoke(String operation,
0N/A Class expectedType) {
0N/A return _get_delegate().servant_preinvoke(this, operation,
0N/A expectedType);
0N/A }
0N/A
0N/A /**
0N/A * Is called by the local stub after it has invoked an operation
0N/A * on the local servant that was previously retrieved from a
0N/A * call to the method <code>_servant_preinvoke</code>.
0N/A * The <code>_servant_postinvoke</code> method must be called
0N/A * if the <code>_servant_preinvoke</code>
0N/A * method returned a non-null value, even if an exception was thrown
0N/A * by the method invoked by the servant. For this reason, the call
0N/A * to the method <code>_servant_postinvoke</code> should be placed
0N/A * in a Java <code>finally</code> clause.
0N/A *
0N/A * @param servant the instance of the <code>ServantObject</code>
0N/A * returned by the <code>_servant_preinvoke</code> method
0N/A */
0N/A public void _servant_postinvoke(ServantObject servant) {
0N/A _get_delegate().servant_postinvoke(this, servant);
0N/A }
0N/A
0N/A /*
0N/A * The following methods were added by orbos/98-04-03: Java to IDL
0N/A * Mapping. These are used by RMI over IIOP.
0N/A */
0N/A
0N/A /**
0N/A * Returns an <code>OutputStream</code> object to use for marshalling
0N/A * the arguments of the given method. This method is called by a stub,
0N/A * which must indicate if a response is expected, that is, whether or not
0N/A * the call is oneway.
0N/A *
0N/A * @param operation a String giving the name of the method.
0N/A * @param responseExpected a boolean -- <code>true</code> if the
0N/A * request is not one way, that is, a response is expected
0N/A * @return an <code>OutputStream</code> object for dispatching the request
0N/A */
0N/A public OutputStream _request(String operation,
0N/A boolean responseExpected) {
0N/A return _get_delegate().request(this, operation, responseExpected);
0N/A }
0N/A
0N/A /**
0N/A * Invokes an operation and returns an <code>InputStream</code>
0N/A * object for reading the response. The stub provides the
0N/A * <code>OutputStream</code> object that was previously returned by a
0N/A * call to the <code>_request</code> method. The method specified
0N/A * as an argument to <code>_request</code> when it was
0N/A * called previously is the method that this method invokes.
0N/A * <P>
0N/A * If an exception occurs, the <code>_invoke</code> method may throw an
0N/A * <code>ApplicationException</code> object that contains an InputStream from
0N/A * which the user exception state may be unmarshalled.
0N/A *
0N/A * @param output an OutputStream object for dispatching the request
0N/A * @return an <code>InputStream</code> object containing the marshalled
0N/A * response to the method invoked
0N/A * @throws ApplicationException if the invocation
0N/A * meets application-defined exception
0N/A * @throws RemarshalException if the invocation leads
0N/A * to a remarshalling error
0N/A * @see #_request
0N/A */
0N/A public InputStream _invoke(OutputStream output)
0N/A throws ApplicationException, RemarshalException {
0N/A return _get_delegate().invoke(this, output);
0N/A }
0N/A
0N/A /**
0N/A * Releases the given
0N/A * reply stream back to the ORB when unmarshalling has
0N/A * completed after a call to the method <code>_invoke</code>.
0N/A * Calling this method is optional for the stub.
0N/A *
0N/A * @param input the <code>InputStream</code> object that was returned
0N/A * by the <code>_invoke</code> method or the
0N/A * <code>ApplicationException.getInputStream</code> method;
0N/A * may be <code>null</code>, in which case this method does
0N/A * nothing
0N/A * @see #_invoke
0N/A */
0N/A public void _releaseReply(InputStream input) {
0N/A _get_delegate().releaseReply(this, input);
0N/A }
0N/A
0N/A /**
0N/A * Returns a <code>String</code> object that represents this
0N/A * <code>ObjectImpl</code> object.
0N/A *
0N/A * @return the <code>String</code> representation of this object
0N/A */
0N/A public String toString() {
0N/A if ( __delegate != null )
0N/A return __delegate.toString(this);
0N/A else
0N/A return getClass().getName() + ": no delegate set";
0N/A }
0N/A
0N/A /**
0N/A * Returns the hash code for this <code>ObjectImpl</code> object.
0N/A *
0N/A * @return the hash code for this object
0N/A */
0N/A public int hashCode() {
0N/A if ( __delegate != null )
0N/A return __delegate.hashCode(this);
0N/A else
0N/A return super.hashCode();
0N/A }
0N/A
0N/A /**
0N/A * Compares this <code>ObjectImpl</code> object with the given one
0N/A * for equality.
0N/A *
0N/A *@param obj the object with which to compare this object
0N/A *@return <code>true</code> if the two objects are equal;
0N/A * <code>false</code> otherwise
0N/A */
0N/A public boolean equals(java.lang.Object obj) {
0N/A if ( __delegate != null )
0N/A return __delegate.equals(this, obj);
0N/A else
0N/A return (this==obj);
0N/A }
0N/A}