ObjectStreamClassCorbaExt.java revision 608:7e06bf1dcb09
1/*
2 * Copyright (c) 2000, 2004, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.  Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26package com.sun.corba.se.impl.io;
27
28import java.security.AccessController;
29import java.security.PrivilegedExceptionAction;
30import java.security.PrivilegedActionException;
31import java.security.PrivilegedAction;
32
33import java.lang.reflect.Modifier;
34import java.lang.reflect.Array;
35import java.lang.reflect.Field;
36import java.lang.reflect.Member;
37import java.lang.reflect.Method;
38
39
40// This file contains some utility methods that
41// originally were in the OSC in the RMI-IIOP
42// code delivered by IBM.  They don't make
43// sense there, and hence have been put
44// here so that they can be factored out in
45// an attempt to eliminate redundant code from
46// ObjectStreamClass.  Eventually the goal is
47// to move to java.io.ObjectStreamClass, and
48// java.io.ObjectStreamField.
49
50// class is package private for security reasons
51
52class ObjectStreamClassCorbaExt {
53
54    /**
55     * Return true, iff,
56     *
57     * 1. 'cl' is an interface, and
58     * 2. 'cl' and all its ancestors do not implement java.rmi.Remote, and
59     * 3. if 'cl' has no methods (including those of its ancestors), or,
60     *    if all the methods (including those of its ancestors) throw an
61     *    exception that is atleast java.rmi.RemoteException or one of
62     *    java.rmi.RemoteException's super classes.
63     */
64    static final boolean isAbstractInterface(Class cl) {
65        if (!cl.isInterface() || // #1
66                java.rmi.Remote.class.isAssignableFrom(cl)) { // #2
67            return false;
68        }
69        Method[] methods = cl.getMethods();
70        for (int i = 0; i < methods.length; i++) {
71            Class exceptions[] = methods[i].getExceptionTypes();
72            boolean exceptionMatch = false;
73            for (int j = 0; (j < exceptions.length) && !exceptionMatch; j++) {
74                if ((java.rmi.RemoteException.class == exceptions[j]) ||
75                    (java.lang.Throwable.class == exceptions[j]) ||
76                    (java.lang.Exception.class == exceptions[j]) ||
77                    (java.io.IOException.class == exceptions[j])) {
78                    exceptionMatch = true;
79                }
80            }
81            if (!exceptionMatch) {
82                return false;
83            }
84        }
85        return true;
86    }
87
88    /*
89     *  Returns TRUE if type is 'any'.
90     */
91    static final boolean isAny(String typeString) {
92
93        int isAny = 0;
94
95        if ( (typeString != null) &&
96            (typeString.equals("Ljava/lang/Object;") ||
97             typeString.equals("Ljava/io/Serializable;") ||
98             typeString.equals("Ljava/io/Externalizable;")) )
99                isAny = 1;
100
101        return (isAny==1);
102    }
103
104    private static final Method[] getDeclaredMethods(final Class clz) {
105        return (Method[]) AccessController.doPrivileged(new PrivilegedAction() {
106            public Object run() {
107                return clz.getDeclaredMethods();
108            }
109        });
110    }
111
112}
113