KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > corba > se > impl > io > ObjectStreamClassCorbaExt


1 /*
2  * @(#)ObjectStreamClassCorbaExt.java 1.7 05/01/04
3  *
4  * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package com.sun.corba.se.impl.io;
9
10 import java.security.AccessController JavaDoc;
11 import java.security.PrivilegedExceptionAction JavaDoc;
12 import java.security.PrivilegedActionException JavaDoc;
13 import java.security.PrivilegedAction JavaDoc;
14
15 import java.lang.reflect.Modifier JavaDoc;
16 import java.lang.reflect.Array JavaDoc;
17 import java.lang.reflect.Field JavaDoc;
18 import java.lang.reflect.Member JavaDoc;
19 import java.lang.reflect.Method JavaDoc;
20
21
22 // This file contains some utility methods that
23
// originally were in the OSC in the RMI-IIOP
24
// code delivered by IBM. They don't make
25
// sense there, and hence have been put
26
// here so that they can be factored out in
27
// an attempt to eliminate redundant code from
28
// ObjectStreamClass. Eventually the goal is
29
// to move to java.io.ObjectStreamClass, and
30
// java.io.ObjectStreamField.
31

32 // class is package private for security reasons
33

34 class ObjectStreamClassCorbaExt {
35
36     /**
37      * Return true, iff,
38      *
39      * 1. 'cl' is an interface, and
40      * 2. 'cl' and all its ancestors do not implement java.rmi.Remote, and
41      * 3. if 'cl' has no methods (including those of its ancestors), or,
42      * if all the methods (including those of its ancestors) throw an
43      * exception that is atleast java.rmi.RemoteException or one of
44      * java.rmi.RemoteException's super classes.
45      */

46     static final boolean isAbstractInterface(Class JavaDoc cl) {
47         if (!cl.isInterface() || // #1
48
java.rmi.Remote JavaDoc.class.isAssignableFrom(cl)) { // #2
49
return false;
50         }
51         Method JavaDoc[] methods = cl.getMethods();
52         for (int i = 0; i < methods.length; i++) {
53             Class JavaDoc exceptions[] = methods[i].getExceptionTypes();
54         boolean exceptionMatch = false;
55             for (int j = 0; (j < exceptions.length) && !exceptionMatch; j++) {
56                 if ((java.rmi.RemoteException JavaDoc.class == exceptions[j]) ||
57                     (java.lang.Throwable JavaDoc.class == exceptions[j]) ||
58                     (java.lang.Exception JavaDoc.class == exceptions[j]) ||
59                     (java.io.IOException JavaDoc.class == exceptions[j])) {
60                     exceptionMatch = true;
61                 }
62             }
63         if (!exceptionMatch) {
64         return false;
65         }
66     }
67     return true;
68     }
69
70     /*
71      * Returns TRUE if type is 'any'.
72      */

73     static final boolean isAny(String JavaDoc typeString) {
74
75     int isAny = 0;
76
77     if ( (typeString != null) &&
78         (typeString.equals("Ljava/lang/Object;") ||
79          typeString.equals("Ljava/io/Serializable;") ||
80          typeString.equals("Ljava/io/Externalizable;")) )
81                 isAny = 1;
82
83         return (isAny==1);
84     }
85
86     private static final Method JavaDoc[] getDeclaredMethods(final Class JavaDoc clz) {
87         return (Method JavaDoc[]) AccessController.doPrivileged(new PrivilegedAction JavaDoc() {
88             public Object JavaDoc run() {
89                 return clz.getDeclaredMethods();
90             }
91         });
92     }
93
94 }
95
Popular Tags