corba/src/share/classes/com/sun/corba/se/impl/presentation/rmi/ExceptionHandlerImpl.java
author jjg
Mon, 14 Jun 2010 11:28:53 -0700
changeset 5823 3ed9d501bfd8
parent 5555 b2b5ed3f0d0d
child 7672 aec650969dd5
permissions -rw-r--r--
6960831: fix CORBA build warnings Reviewed-by: darcy
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4
02bb8761fcce Initial load
duke
parents:
diff changeset
     1
/*
5555
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
     2
 * Copyright (c) 2003, 2004, Oracle and/or its affiliates. All rights reserved.
4
02bb8761fcce Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
02bb8761fcce Initial load
duke
parents:
diff changeset
     4
 *
02bb8761fcce Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
02bb8761fcce Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5555
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
4
02bb8761fcce Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5555
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
4
02bb8761fcce Initial load
duke
parents:
diff changeset
    10
 *
02bb8761fcce Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
02bb8761fcce Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
02bb8761fcce Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
02bb8761fcce Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
02bb8761fcce Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
02bb8761fcce Initial load
duke
parents:
diff changeset
    16
 *
02bb8761fcce Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
02bb8761fcce Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
02bb8761fcce Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
02bb8761fcce Initial load
duke
parents:
diff changeset
    20
 *
5555
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
    23
 * questions.
4
02bb8761fcce Initial load
duke
parents:
diff changeset
    24
 */
02bb8761fcce Initial load
duke
parents:
diff changeset
    25
02bb8761fcce Initial load
duke
parents:
diff changeset
    26
package com.sun.corba.se.impl.presentation.rmi ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    27
02bb8761fcce Initial load
duke
parents:
diff changeset
    28
import java.io.Serializable ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    29
import java.io.Externalizable ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    30
02bb8761fcce Initial load
duke
parents:
diff changeset
    31
import javax.rmi.PortableRemoteObject ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    32
import javax.rmi.CORBA.Util ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    33
02bb8761fcce Initial load
duke
parents:
diff changeset
    34
import java.rmi.RemoteException ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    35
import java.rmi.UnexpectedException ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    36
02bb8761fcce Initial load
duke
parents:
diff changeset
    37
import org.omg.CORBA.UserException ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    38
02bb8761fcce Initial load
duke
parents:
diff changeset
    39
import org.omg.CORBA_2_3.portable.InputStream ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    40
import org.omg.CORBA_2_3.portable.OutputStream ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    41
import org.omg.CORBA.portable.ApplicationException ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    42
02bb8761fcce Initial load
duke
parents:
diff changeset
    43
import java.lang.reflect.Method ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    44
02bb8761fcce Initial load
duke
parents:
diff changeset
    45
import com.sun.corba.se.spi.logging.CORBALogDomains ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    46
import com.sun.corba.se.impl.logging.ORBUtilSystemException ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    47
02bb8761fcce Initial load
duke
parents:
diff changeset
    48
public class ExceptionHandlerImpl implements ExceptionHandler
02bb8761fcce Initial load
duke
parents:
diff changeset
    49
{
02bb8761fcce Initial load
duke
parents:
diff changeset
    50
    private ExceptionRW[] rws ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    51
02bb8761fcce Initial load
duke
parents:
diff changeset
    52
    private final ORBUtilSystemException wrapper ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    53
02bb8761fcce Initial load
duke
parents:
diff changeset
    54
///////////////////////////////////////////////////////////////////////////////
02bb8761fcce Initial load
duke
parents:
diff changeset
    55
// ExceptionRW interface and implementations.
02bb8761fcce Initial load
duke
parents:
diff changeset
    56
// Used to read and write exceptions.
02bb8761fcce Initial load
duke
parents:
diff changeset
    57
///////////////////////////////////////////////////////////////////////////////
02bb8761fcce Initial load
duke
parents:
diff changeset
    58
02bb8761fcce Initial load
duke
parents:
diff changeset
    59
    public interface ExceptionRW
02bb8761fcce Initial load
duke
parents:
diff changeset
    60
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
    61
        Class getExceptionClass() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    62
02bb8761fcce Initial load
duke
parents:
diff changeset
    63
        String getId() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    64
02bb8761fcce Initial load
duke
parents:
diff changeset
    65
        void write( OutputStream os, Exception ex ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    66
02bb8761fcce Initial load
duke
parents:
diff changeset
    67
        Exception read( InputStream is ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    68
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
    69
02bb8761fcce Initial load
duke
parents:
diff changeset
    70
    public abstract class ExceptionRWBase implements ExceptionRW
02bb8761fcce Initial load
duke
parents:
diff changeset
    71
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
    72
        private Class cls ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    73
        private String id ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    74
02bb8761fcce Initial load
duke
parents:
diff changeset
    75
        public ExceptionRWBase( Class cls )
02bb8761fcce Initial load
duke
parents:
diff changeset
    76
        {
02bb8761fcce Initial load
duke
parents:
diff changeset
    77
            this.cls = cls ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    78
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
    79
02bb8761fcce Initial load
duke
parents:
diff changeset
    80
        public Class getExceptionClass()
02bb8761fcce Initial load
duke
parents:
diff changeset
    81
        {
02bb8761fcce Initial load
duke
parents:
diff changeset
    82
            return cls ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    83
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
    84
02bb8761fcce Initial load
duke
parents:
diff changeset
    85
        public String getId()
02bb8761fcce Initial load
duke
parents:
diff changeset
    86
        {
02bb8761fcce Initial load
duke
parents:
diff changeset
    87
            return id ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    88
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
    89
02bb8761fcce Initial load
duke
parents:
diff changeset
    90
        void setId( String id )
02bb8761fcce Initial load
duke
parents:
diff changeset
    91
        {
02bb8761fcce Initial load
duke
parents:
diff changeset
    92
            this.id = id ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    93
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
    94
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
    95
02bb8761fcce Initial load
duke
parents:
diff changeset
    96
    public class ExceptionRWIDLImpl extends ExceptionRWBase
02bb8761fcce Initial load
duke
parents:
diff changeset
    97
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
    98
        private Method readMethod ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    99
        private Method writeMethod ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   100
02bb8761fcce Initial load
duke
parents:
diff changeset
   101
        public ExceptionRWIDLImpl( Class cls )
02bb8761fcce Initial load
duke
parents:
diff changeset
   102
        {
02bb8761fcce Initial load
duke
parents:
diff changeset
   103
            super( cls ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   104
02bb8761fcce Initial load
duke
parents:
diff changeset
   105
            String helperName = cls.getName() + "Helper" ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   106
            ClassLoader loader = cls.getClassLoader() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   107
            Class helperClass ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   108
02bb8761fcce Initial load
duke
parents:
diff changeset
   109
            try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   110
                helperClass = Class.forName( helperName, true, loader ) ;
5823
3ed9d501bfd8 6960831: fix CORBA build warnings
jjg
parents: 5555
diff changeset
   111
                Method idMethod = helperClass.getDeclaredMethod( "id", (Class[])null ) ;
3ed9d501bfd8 6960831: fix CORBA build warnings
jjg
parents: 5555
diff changeset
   112
                setId( (String)idMethod.invoke( null, (Object[])null ) ) ;
4
02bb8761fcce Initial load
duke
parents:
diff changeset
   113
            } catch (Exception ex) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   114
                throw wrapper.badHelperIdMethod( ex, helperName ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   115
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   116
02bb8761fcce Initial load
duke
parents:
diff changeset
   117
            try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   118
                Class[] argTypes = new Class[] {
02bb8761fcce Initial load
duke
parents:
diff changeset
   119
                    org.omg.CORBA.portable.OutputStream.class, cls } ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   120
                writeMethod = helperClass.getDeclaredMethod( "write",
02bb8761fcce Initial load
duke
parents:
diff changeset
   121
                    argTypes ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   122
            } catch (Exception ex) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   123
                throw wrapper.badHelperWriteMethod( ex, helperName ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   124
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   125
02bb8761fcce Initial load
duke
parents:
diff changeset
   126
            try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   127
                Class[] argTypes = new Class[] {
02bb8761fcce Initial load
duke
parents:
diff changeset
   128
                    org.omg.CORBA.portable.InputStream.class } ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   129
                readMethod = helperClass.getDeclaredMethod( "read", argTypes ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   130
            } catch (Exception ex) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   131
                throw wrapper.badHelperReadMethod( ex, helperName ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   132
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   133
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   134
02bb8761fcce Initial load
duke
parents:
diff changeset
   135
        public void write( OutputStream os, Exception ex )
02bb8761fcce Initial load
duke
parents:
diff changeset
   136
        {
02bb8761fcce Initial load
duke
parents:
diff changeset
   137
            try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   138
                Object[] args = new Object[] { os, ex } ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   139
                writeMethod.invoke( null, args ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   140
            } catch (Exception exc) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   141
                throw wrapper.badHelperWriteMethod( exc,
02bb8761fcce Initial load
duke
parents:
diff changeset
   142
                    writeMethod.getDeclaringClass().getName() ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   143
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   144
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   145
02bb8761fcce Initial load
duke
parents:
diff changeset
   146
        public Exception read( InputStream is )
02bb8761fcce Initial load
duke
parents:
diff changeset
   147
        {
02bb8761fcce Initial load
duke
parents:
diff changeset
   148
            try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   149
                Object[] args = new Object[] { is } ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   150
                return (Exception)readMethod.invoke( null, args ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   151
            } catch (Exception ex) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   152
                throw wrapper.badHelperReadMethod( ex,
02bb8761fcce Initial load
duke
parents:
diff changeset
   153
                    readMethod.getDeclaringClass().getName() ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   154
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   155
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   156
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   157
02bb8761fcce Initial load
duke
parents:
diff changeset
   158
    public class ExceptionRWRMIImpl extends ExceptionRWBase
02bb8761fcce Initial load
duke
parents:
diff changeset
   159
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   160
        public ExceptionRWRMIImpl( Class cls )
02bb8761fcce Initial load
duke
parents:
diff changeset
   161
        {
02bb8761fcce Initial load
duke
parents:
diff changeset
   162
            super( cls ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   163
            setId( IDLNameTranslatorImpl.getExceptionId( cls ) ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   164
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   165
02bb8761fcce Initial load
duke
parents:
diff changeset
   166
        public void write( OutputStream os, Exception ex )
02bb8761fcce Initial load
duke
parents:
diff changeset
   167
        {
02bb8761fcce Initial load
duke
parents:
diff changeset
   168
            os.write_string( getId() ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   169
            os.write_value( ex, getExceptionClass() ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   170
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   171
02bb8761fcce Initial load
duke
parents:
diff changeset
   172
        public Exception read( InputStream is )
02bb8761fcce Initial load
duke
parents:
diff changeset
   173
        {
02bb8761fcce Initial load
duke
parents:
diff changeset
   174
            is.read_string() ; // read and ignore!
02bb8761fcce Initial load
duke
parents:
diff changeset
   175
            return (Exception)is.read_value( getExceptionClass() ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   176
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   177
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   178
02bb8761fcce Initial load
duke
parents:
diff changeset
   179
///////////////////////////////////////////////////////////////////////////////
02bb8761fcce Initial load
duke
parents:
diff changeset
   180
02bb8761fcce Initial load
duke
parents:
diff changeset
   181
    public ExceptionHandlerImpl( Class[] exceptions )
02bb8761fcce Initial load
duke
parents:
diff changeset
   182
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   183
        wrapper = ORBUtilSystemException.get(
02bb8761fcce Initial load
duke
parents:
diff changeset
   184
            CORBALogDomains.RPC_PRESENTATION ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   185
02bb8761fcce Initial load
duke
parents:
diff changeset
   186
        int count = 0 ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   187
        for (int ctr=0; ctr<exceptions.length; ctr++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   188
            Class cls = exceptions[ctr] ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   189
            if (!RemoteException.class.isAssignableFrom(cls))
02bb8761fcce Initial load
duke
parents:
diff changeset
   190
                count++ ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   191
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   192
02bb8761fcce Initial load
duke
parents:
diff changeset
   193
        rws = new ExceptionRW[count] ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   194
02bb8761fcce Initial load
duke
parents:
diff changeset
   195
        int index = 0 ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   196
        for (int ctr=0; ctr<exceptions.length; ctr++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   197
            Class cls = exceptions[ctr] ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   198
            if (!RemoteException.class.isAssignableFrom(cls)) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   199
                ExceptionRW erw = null ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   200
                if (UserException.class.isAssignableFrom(cls))
02bb8761fcce Initial load
duke
parents:
diff changeset
   201
                    erw = new ExceptionRWIDLImpl( cls ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   202
                else
02bb8761fcce Initial load
duke
parents:
diff changeset
   203
                    erw = new ExceptionRWRMIImpl( cls ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   204
02bb8761fcce Initial load
duke
parents:
diff changeset
   205
                /* The following check is not performed
02bb8761fcce Initial load
duke
parents:
diff changeset
   206
                 * in order to maintain compatibility with
02bb8761fcce Initial load
duke
parents:
diff changeset
   207
                 * rmic.  See bug 4989312.
02bb8761fcce Initial load
duke
parents:
diff changeset
   208
02bb8761fcce Initial load
duke
parents:
diff changeset
   209
                // Check for duplicate repository ID
02bb8761fcce Initial load
duke
parents:
diff changeset
   210
                String repositoryId = erw.getId() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   211
                int duplicateIndex = findDeclaredException( repositoryId ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   212
                if (duplicateIndex > 0) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   213
                    ExceptionRW duprw = rws[duplicateIndex] ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   214
                    String firstClassName =
02bb8761fcce Initial load
duke
parents:
diff changeset
   215
                        erw.getExceptionClass().getName() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   216
                    String secondClassName =
02bb8761fcce Initial load
duke
parents:
diff changeset
   217
                        duprw.getExceptionClass().getName() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   218
                    throw wrapper.duplicateExceptionRepositoryId(
02bb8761fcce Initial load
duke
parents:
diff changeset
   219
                        firstClassName, secondClassName, repositoryId ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   220
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   221
02bb8761fcce Initial load
duke
parents:
diff changeset
   222
                */
02bb8761fcce Initial load
duke
parents:
diff changeset
   223
02bb8761fcce Initial load
duke
parents:
diff changeset
   224
                rws[index++] = erw ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   225
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   226
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   227
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   228
02bb8761fcce Initial load
duke
parents:
diff changeset
   229
    private int findDeclaredException( Class cls )
02bb8761fcce Initial load
duke
parents:
diff changeset
   230
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   231
        for (int ctr = 0; ctr < rws.length; ctr++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   232
            Class next = rws[ctr].getExceptionClass() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   233
            if (next.isAssignableFrom(cls))
02bb8761fcce Initial load
duke
parents:
diff changeset
   234
                return ctr ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   235
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   236
02bb8761fcce Initial load
duke
parents:
diff changeset
   237
        return -1 ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   238
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   239
02bb8761fcce Initial load
duke
parents:
diff changeset
   240
    private int findDeclaredException( String repositoryId )
02bb8761fcce Initial load
duke
parents:
diff changeset
   241
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   242
        for (int ctr=0; ctr<rws.length; ctr++) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   243
            // This may occur when rws has not been fully
02bb8761fcce Initial load
duke
parents:
diff changeset
   244
            // populated, in which case the search should just fail.
02bb8761fcce Initial load
duke
parents:
diff changeset
   245
            if (rws[ctr]==null)
02bb8761fcce Initial load
duke
parents:
diff changeset
   246
                return -1 ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   247
02bb8761fcce Initial load
duke
parents:
diff changeset
   248
            String rid = rws[ctr].getId() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   249
            if (repositoryId.equals( rid ))
02bb8761fcce Initial load
duke
parents:
diff changeset
   250
                return ctr ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   251
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   252
02bb8761fcce Initial load
duke
parents:
diff changeset
   253
        return -1 ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   254
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   255
02bb8761fcce Initial load
duke
parents:
diff changeset
   256
    public boolean isDeclaredException( Class cls )
02bb8761fcce Initial load
duke
parents:
diff changeset
   257
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   258
        return findDeclaredException( cls ) >= 0 ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   259
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   260
02bb8761fcce Initial load
duke
parents:
diff changeset
   261
    public void writeException( OutputStream os, Exception ex )
02bb8761fcce Initial load
duke
parents:
diff changeset
   262
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   263
        int index = findDeclaredException( ex.getClass() ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   264
        if (index < 0)
02bb8761fcce Initial load
duke
parents:
diff changeset
   265
            throw wrapper.writeUndeclaredException( ex,
02bb8761fcce Initial load
duke
parents:
diff changeset
   266
                ex.getClass().getName() ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   267
02bb8761fcce Initial load
duke
parents:
diff changeset
   268
        rws[index].write( os, ex ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   269
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   270
02bb8761fcce Initial load
duke
parents:
diff changeset
   271
    public Exception readException( ApplicationException ae )
02bb8761fcce Initial load
duke
parents:
diff changeset
   272
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   273
        // Note that the exception ID is present in both ae
02bb8761fcce Initial load
duke
parents:
diff changeset
   274
        // and in the input stream from ae.  The exception
02bb8761fcce Initial load
duke
parents:
diff changeset
   275
        // reader must actually read the exception ID from
02bb8761fcce Initial load
duke
parents:
diff changeset
   276
        // the stream.
02bb8761fcce Initial load
duke
parents:
diff changeset
   277
        InputStream is = (InputStream)ae.getInputStream() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   278
        String excName = ae.getId() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   279
        int index = findDeclaredException( excName ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   280
        if (index < 0) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   281
            excName = is.read_string() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   282
            Exception res = new UnexpectedException( excName ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   283
            res.initCause( ae ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   284
            return res ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   285
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   286
02bb8761fcce Initial load
duke
parents:
diff changeset
   287
        return rws[index].read( is ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   288
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   289
02bb8761fcce Initial load
duke
parents:
diff changeset
   290
    // This is here just for the dynamicrmiiiop test
02bb8761fcce Initial load
duke
parents:
diff changeset
   291
    public ExceptionRW getRMIExceptionRW( Class cls )
02bb8761fcce Initial load
duke
parents:
diff changeset
   292
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   293
        return new ExceptionRWRMIImpl( cls ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   294
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   295
}