alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Java example source code file (ObjectImpl.java)

This example Java source code file (ObjectImpl.java) is included in the alvinalexander.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Learn more about this Java project at its project page.

Java - Java tags/keywords

applicationexception, bad_operation, class, corba, delegate, error, exceptionlist, namedvalue, nvlist, object, objectimpl, request, runtimeexception, string, throwable

The ObjectImpl.java Java example source code

/*
 * Copyright (c) 1997, 2006, Oracle and/or its affiliates. All rights reserved.
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
 * published by the Free Software Foundation.  Oracle designates this
 * particular file as subject to the "Classpath" exception as provided
 * by Oracle in the LICENSE file that accompanied this code.
 *
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 * or visit www.oracle.com if you need additional information or have any
 * questions.
 */
package org.omg.CORBA.portable;

import org.omg.CORBA.Request;
import org.omg.CORBA.NamedValue;
import org.omg.CORBA.NVList;
import org.omg.CORBA.ExceptionList;
import org.omg.CORBA.ContextList;
import org.omg.CORBA.Context;
import org.omg.CORBA.TypeCode;
import org.omg.CORBA.BAD_OPERATION;
import org.omg.CORBA.SystemException;


/**
 *  The common base class for all stub classes; provides default implementations
 *  of the <code>org.omg.CORBA.Object methods. All method implementations are
 *  forwarded to a <code>Delegate object stored in the ObjectImpl
 *  instance.  <code>ObjectImpl allows for portable stubs because the
 *  <code>Delegate can be implemented by a different vendor-specific ORB.
 */

abstract public class ObjectImpl implements org.omg.CORBA.Object
{

    /**
     * The field that stores the <code>Delegate instance for
     * this <code>ObjectImpl object. This Delegate
     * instance can be implemented by a vendor-specific ORB.  Stub classes,
     * which are derived from this <code>ObjectImpl class, can be
     * portable because they delegate all of the methods called on them to this
     * <code>Delegate object.
     */
    private transient Delegate __delegate;


    /**
     * Retrieves the reference to the vendor-specific <code>Delegate
     * object to which this <code>ObjectImpl object delegates all
     * methods invoked on it.
     *
     * @return the Delegate contained in this ObjectImpl instance
     * @throws BAD_OPERATION if the delegate has not been set
     * @see #_set_delegate
     */
    public Delegate _get_delegate() {
        if (__delegate == null)
            throw new BAD_OPERATION("The delegate has not been set!");
        return __delegate;
    }


    /**
     * Sets the Delegate for this <code>ObjectImpl instance to the given
     * <code>Delegate object.  All method invocations on this
     * <code>ObjectImpl object will be forwarded to this delegate.
     *
     * @param delegate the <code>Delegate instance to which
     *        all method calls on this <code>ObjectImpl object
     *        will be delegated; may be implemented by a third-party ORB
     * @see #_get_delegate
     */
    public void _set_delegate(Delegate delegate) {
        __delegate = delegate;
    }

    /**
     * Retrieves a string array containing the repository identifiers
     * supported by this <code>ObjectImpl object.  For example,
     * for a stub, this method returns information about all the
     * interfaces supported by the stub.
     *
     * @return the array of all repository identifiers supported by this
     *         <code>ObjectImpl instance
     */
    public abstract String[] _ids();


    /**
     * Returns a duplicate of this <code>ObjectImpl object.
     *
     * @return an <code>orb.omg.CORBA.Object object that is
     *         a duplicate of this object
     */
    public org.omg.CORBA.Object _duplicate() {
        return _get_delegate().duplicate(this);
    }

    /**
     * Releases the resources associated with this <code>ObjectImpl object.
     */
    public void _release() {
        _get_delegate().release(this);
    }

    /**
     * Checks whether the object identified by the given repository
     * identifier is an <code>ObjectImpl object.
     *
     * @param repository_id a <code>String object with the repository
     *        identifier to check
     * @return <code>true if the object identified by the given
     *         repository id is an instance of <code>ObjectImpl;
     *         <code>false otherwise
     */
    public boolean _is_a(String repository_id) {
        return _get_delegate().is_a(this, repository_id);
    }

    /**
     * Checks whether the the given <code>ObjectImpl object is
     * equivalent to this <code>ObjectImpl object.
     *
     * @param that an instance of <code>ObjectImpl to compare with
     *        this <code>ObjectImpl object
     * @return <code>true if the given object is equivalent
     *         to this <code>ObjectImpl object;
     *         <code>false otherwise
     */
    public boolean _is_equivalent(org.omg.CORBA.Object that) {
        return _get_delegate().is_equivalent(this, that);
    }

    /**
     * Checks whether the server object for this <code>ObjectImpl
     * object has been destroyed.
     *
     * @return <code>true if the ORB knows authoritatively that the
     *         server object does not exist; <code>false otherwise
     */
    public boolean _non_existent() {
        return _get_delegate().non_existent(this);
    }

    /**
     * Retrieves the hash code that serves as an ORB-internal identifier for
     * this <code>ObjectImpl object.
     *
     * @param maximum an <code>int indicating the upper bound on the hash
     *        value returned by the ORB
     * @return an <code>int representing the hash code for this
     *         <code>ObjectImpl object
     */
    public int _hash(int maximum) {
        return _get_delegate().hash(this, maximum);
    }

    /**
     * Creates a <code>Request object containing the given method
     * that can be used with the Dynamic Invocation Interface.
     *
     * @param operation the method to be invoked by the new <code>Request
     *        object
     * @return a new <code>Request object initialized with the
     *         given method
     */
    public Request _request(String operation) {
        return _get_delegate().request(this, operation);
    }

    /**
     * Creates a <code>Request object that contains the given context,
     * method, argument list, and container for the result.
     *
     * @param ctx the Context for the request
     * @param operation the method that the new <code>Request
     *        object will invoke
     * @param arg_list the arguments for the method; an <code>NVList
     *        in which each argument is a <code>NamedValue object
     * @param result a <code>NamedValue object to be used for
     *        returning the result of executing the request's method
     * @return a new <code>Request object initialized with the
     *         given context, method, argument list, and container for the
     *         return value
     */
    public Request _create_request(Context ctx,
                                   String operation,
                                   NVList arg_list,
                                   NamedValue result) {
        return _get_delegate().create_request(this,
                                              ctx,
                                              operation,
                                              arg_list,
                                              result);
    }

    /**
     * Creates a <code>Request object that contains the given context,
     * method, argument list, container for the result, exceptions, and
     * list of property names to be used in resolving the context strings.
     * This <code>Request object is for use in the Dynamic
     * Invocation Interface.
     *
     * @param ctx the <code>Context object that contains the
     *        context strings that must be resolved before they are
     *        sent along with the request
     * @param operation the method that the new <code>Request
     *        object will invoke
     * @param arg_list the arguments for the method; an <code>NVList
     *        in which each argument is a <code>NamedValue object
     * @param result a <code>NamedValue object to be used for
     *        returning the result of executing the request's method
     * @param exceptions a list of the exceptions that the given method
     *        throws
     * @param contexts a list of the properties that are needed to
     *        resolve the contexts in <i>ctx; the strings in
     *        <i>contexts are used as arguments to the method
     *        <code>Context.get_values,
     *        which returns the value associated with the given property
     * @return a new <code>Request object initialized with the
     *         given context strings to resolve, method, argument list,
     *         container for the result, exceptions, and list of property
     *         names to be used in resolving the context strings
     */
    public Request _create_request(Context ctx,
                                   String operation,
                                   NVList arg_list,
                                   NamedValue result,
                                   ExceptionList exceptions,
                                   ContextList contexts) {
        return _get_delegate().create_request(this,
                                              ctx,
                                              operation,
                                              arg_list,
                                              result,
                                              exceptions,
                                              contexts);
    }

    /**
     * Retrieves the interface definition for this <code>ObjectImpl
     * object.
     *
     * @return the <code>org.omg.CORBA.Object instance that is the
     *         interface definition for this <code>ObjectImpl object
     */
    public org.omg.CORBA.Object _get_interface_def()
    {
        // First try to call the delegate implementation class's
        // "Object get_interface_def(..)" method (will work for JDK1.2 ORBs).
        // Else call the delegate implementation class's
        // "InterfaceDef get_interface(..)" method using reflection
        // (will work for pre-JDK1.2 ORBs).

        org.omg.CORBA.portable.Delegate delegate = _get_delegate();
        try {
            // If the ORB's delegate class does not implement
            // "Object get_interface_def(..)", this will call
            // get_interface_def(..) on portable.Delegate.
            return delegate.get_interface_def(this);
        }
        catch( org.omg.CORBA.NO_IMPLEMENT ex ) {
            // Call "InterfaceDef get_interface(..)" method using reflection.
            try {
                Class[] argc = { org.omg.CORBA.Object.class };
                java.lang.reflect.Method meth =
                    delegate.getClass().getMethod("get_interface", argc);
                Object[] argx = { this };
                return (org.omg.CORBA.Object)meth.invoke(delegate, argx);
            }
            catch( java.lang.reflect.InvocationTargetException exs ) {
                Throwable t = exs.getTargetException();
                if (t instanceof Error) {
                    throw (Error) t;
                }
                else if (t instanceof RuntimeException) {
                    throw (RuntimeException) t;
                }
                else {
                    throw new org.omg.CORBA.NO_IMPLEMENT();
                }
            } catch( RuntimeException rex ) {
                throw rex;
            } catch( Exception exr ) {
                throw new org.omg.CORBA.NO_IMPLEMENT();
            }
        }
    }

    /**
     * Returns a reference to the ORB associated with this object and
     * its delegate.  This is the <code>ORB object that created
     * the delegate.
     *
     * @return the <code>ORB instance that created the
     *          <code>Delegate object contained in this
     *          <code>ObjectImpl object
     */
    public org.omg.CORBA.ORB _orb() {
        return _get_delegate().orb(this);
    }


    /**
     * Retrieves the <code>Policy object for this
     * <code>ObjectImpl object that has the given
     * policy type.
     *
     * @param policy_type an int indicating the policy type
     * @return the <code>Policy object that is the specified policy type
     *         and that applies to this <code>ObjectImpl object
     * @see org.omg.CORBA.PolicyOperations#policy_type
     */
    public org.omg.CORBA.Policy _get_policy(int policy_type) {
        return _get_delegate().get_policy(this, policy_type);
    }

    /**
     * Retrieves a list of the domain managers for this
     * <code>ObjectImpl object.
     *
     * @return an array containing the <code>DomainManager
     *         objects for this instance of <code>ObjectImpl
     */
    public org.omg.CORBA.DomainManager[] _get_domain_managers() {
        return _get_delegate().get_domain_managers(this);
    }

    /**
     * Sets this <code>ObjectImpl object's override type for
     * the given policies to the given instance of
     * <code>SetOverrideType.
     *
     * @param policies an array of <code>Policy objects with the
     *         policies that will replace the current policies or be
     *         added to the current policies
     * @param set_add either <code>SetOverrideType.SET_OVERRIDE,
     *         indicating that the given policies will replace any existing
     *         ones, or <code>SetOverrideType.ADD_OVERRIDE, indicating
     *         that the given policies should be added to any existing ones
     * @return an <code>Object with the given policies replacing or
     *         added to its previous policies
     */
    public org.omg.CORBA.Object
        _set_policy_override(org.omg.CORBA.Policy[] policies,
                             org.omg.CORBA.SetOverrideType set_add) {
        return _get_delegate().set_policy_override(this, policies,
                                                   set_add);
    }

    /**
     * Checks whether this <code>ObjectImpl object is implemented
     * by a local servant.  If so, local invocation API's may be used.
     *
     * @return <code>true if this object is implemented by a local
     *         servant; <code>false otherwise
     */
    public boolean _is_local() {
        return _get_delegate().is_local(this);
    }

    /**
     * Returns a Java reference to the local servant that should be used for sending
     * a request for the method specified. If this <code>ObjectImpl
     * object is a local stub, it will invoke the <code>_servant_preinvoke
     * method before sending a request in order to obtain the
     * <code>ServantObject instance to use.
     * <P>
     * If a <code>ServantObject object is returned, its servant
     * field has been set to an object of the expected type (Note: the object may
     * or may not be the actual servant instance). The local stub may cast
     * the servant field to the expected type, and then invoke the operation
     * directly. The <code>ServantRequest object is valid for only one
     * invocation and cannot be used for more than one invocation.
     *
     * @param operation a <code>String containing the name of the method
     *        to be invoked. This name should correspond to the method name as
     *        it would be encoded in a GIOP request.
     *
     * @param expectedType a <code>Class object representing the
     *        expected type of the servant that is returned. This expected
     *        type is the <code>Class object associated with the
     *        operations class for the stub's interface. For example, a
     *        stub for an interface <code>Foo would pass the
     *        <code>Class object for the FooOperations
     *        interface.
     *
     * @return (1) a <code>ServantObject object, which may or may
     *         not be the actual servant instance, or (2) <code>null if
     *         (a) the servant is not local or (b) the servant has ceased to
     *         be local due to a ForwardRequest from a POA ServantManager
     * @throws org.omg.CORBA.BAD_PARAM if the servant is not the expected type
     */
    public ServantObject _servant_preinvoke(String operation,
                                            Class expectedType) {
        return _get_delegate().servant_preinvoke(this, operation,
                                                 expectedType);
    }

    /**
     * Is called by the local stub after it has invoked an operation
     * on the local servant that was previously retrieved from a
     * call to the method <code>_servant_preinvoke.
     * The <code>_servant_postinvoke method must be called
     * if the <code>_servant_preinvoke
     * method returned a non-null value, even if an exception was thrown
     * by the method invoked by the servant. For this reason, the call
     * to the method <code>_servant_postinvoke should be placed
     * in a Java <code>finally clause.
     *
     * @param servant the instance of the <code>ServantObject
     *        returned by the <code>_servant_preinvoke method
     */
    public void _servant_postinvoke(ServantObject servant) {
        _get_delegate().servant_postinvoke(this, servant);
    }

    /*
     * The following methods were added by orbos/98-04-03: Java to IDL
     * Mapping. These are used by RMI over IIOP.
     */

    /**
     * Returns an <code>OutputStream object to use for marshalling
     * the arguments of the given method.  This method is called by a stub,
     * which must indicate if a response is expected, that is, whether or not
     * the call is oneway.
     *
     * @param operation         a String giving the name of the method.
     * @param responseExpected  a boolean -- <code>true if the
     *         request is not one way, that is, a response is expected
     * @return an <code>OutputStream object for dispatching the request
     */
    public OutputStream _request(String operation,
                                 boolean responseExpected) {
        return _get_delegate().request(this, operation, responseExpected);
    }

    /**
     * Invokes an operation and returns an <code>InputStream
     * object for reading the response. The stub provides the
     * <code>OutputStream object that was previously returned by a
     * call to the <code>_request method. The method specified
     * as an argument to <code>_request when it was
     * called previously is the method that this method invokes.
     * <P>
     * If an exception occurs, the <code>_invoke method may throw an
     * <code>ApplicationException object that contains an InputStream from
     * which the user exception state may be unmarshalled.
     *
     * @param output  an OutputStream object for dispatching the request
     * @return an <code>InputStream object containing the marshalled
     *         response to the method invoked
     * @throws ApplicationException if the invocation
     *         meets application-defined exception
     * @throws RemarshalException if the invocation leads
     *         to a remarshalling error
     * @see #_request
     */
    public InputStream _invoke(OutputStream output)
        throws ApplicationException, RemarshalException {
        return _get_delegate().invoke(this, output);
    }

    /**
     * Releases the given
     * reply stream back to the ORB when unmarshalling has
     * completed after a call to the method <code>_invoke.
     * Calling this method is optional for the stub.
     *
     * @param input  the <code>InputStream object that was returned
     *        by the <code>_invoke method or the
     *        <code>ApplicationException.getInputStream method;
     *        may be <code>null, in which case this method does
     *        nothing
     * @see #_invoke
     */
    public void _releaseReply(InputStream input) {
        _get_delegate().releaseReply(this, input);
    }

    /**
     * Returns a <code>String object that represents this
     * <code>ObjectImpl object.
     *
     * @return the <code>String representation of this object
     */
    public String toString() {
        if ( __delegate != null )
           return __delegate.toString(this);
        else
           return getClass().getName() + ": no delegate set";
    }

    /**
     * Returns the hash code for this <code>ObjectImpl object.
     *
     * @return the hash code for this object
     */
    public int hashCode() {
        if ( __delegate != null )
           return __delegate.hashCode(this);
        else
            return super.hashCode();
    }

    /**
     * Compares this <code>ObjectImpl object with the given one
     * for equality.
     *
     *@param obj the object with which to compare this object
     *@return <code>true if the two objects are equal;
     *        <code>false otherwise
     */
    public boolean equals(java.lang.Object obj) {
        if ( __delegate != null )
           return __delegate.equals(this, obj);
        else
           return (this==obj);
    }
}

Other Java examples (source code examples)

Here is a short list of links related to this Java ObjectImpl.java source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.