KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > verifier > tests > ejb > RmiIIOPUtils


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23 package com.sun.enterprise.tools.verifier.tests.ejb;
24
25 import com.sun.enterprise.tools.verifier.tests.ejb.EjbTest;
26 import java.lang.reflect.*;
27 import java.util.*;
28 import com.sun.enterprise.deployment.EjbDescriptor;
29 import com.sun.enterprise.deployment.MethodDescriptor;
30 import com.sun.enterprise.tools.verifier.*;
31 import java.lang.ClassLoader JavaDoc;
32 import com.sun.enterprise.tools.verifier.tests.ejb.EjbCheck;
33
34 /**
35  * Interface, parameters, return type, and exceptions checked for RMI-IIOP
36  * compliance test.
37  *
38  */

39 public class RmiIIOPUtils {
40
41
42
43     /**
44      * Interface checked for RMI-IIOP compliance test.
45      * Verify the following:
46      *
47      * The remote interface is allowed to have superinterfaces. Use of interface
48      * inheritance is subject to the RMI-IIOP rules for the definition of remote
49      * interfaces.
50      *
51      * Verify the following:
52      *
53      * An RMI remote interface defines a Java interface that can be invoked
54      * remotely. A Java interface is a conforming RMI/IDL remote interface if:
55      *
56      * 1. The interface is or inherits from java.rmi.Remote either directly or
57      * indirectly.
58      *
59      * 2. All methods in the interface are defined to throw
60      * java.rmi.RemoteException or a superclass of java.rmi.RemoteException.
61      * Throughout this section, references to methods in the interface include
62      * methods in any inherited interfaces.
63      *
64      * 3. Method arguments and results may be of any types. However at run-time,
65      * the actual values passed as arguments or returned as results must be
66      * conforming RMI/IDL types (see "Overview of Conforming RMI/IDL Types" on
67      * page 28-2). In addition, for each RMI/IDL remote interface reference,
68      * the actual value passed or returned must be either a stub object or a
69      * remote interface implementation object (see "Stubs and remote
70      * implementation classes" on page 28-4).
71      *
72      * 4. All checked exception classes used in method declarations (other than
73      * java.rmi.RemoteException and its subclasses) are conforming RMI/IDL
74      * exception types (see "RMI/IDL Exception Types" on page 28-5)1
75      *
76      * 5. Method names may be overloaded. However, when an interface directly
77      * inherits from several base interfaces, it is forbidden for there to be
78      * method name conflicts between the inherited interfaces. This outlaws the
79      * case where an interface A defines a method "foo," an interface B also
80      * defines a method "foo," and an interface C tries to inherit from both A
81      * and B.
82      *
83      * 6. Constant definitions in the form of interface variables are permitted.
84      * The constant value must be a compile-time constant of one of the RMI/IDL
85      * primitive types or String.
86      *
87      * 7. Method and constant names must not cause name collisions when mapped to
88      * IDL (see "Names that would cause OMG IDL name collisions" on page 28-9).
89      *
90      * The following is an example of a conforming RMI/IDL interface definition:
91      * // Java
92      * public interface Wombat extends java.rmi.Remote {
93      * String BLEAT_CONSTANT = "bleat";
94      * boolean bleat(Wombat other) throws java.rmi.RemoteException;
95      * }
96      *
97      * While the following is an example of a non-conforming RMI/IDL interface:
98      * // Java
99      * // IllegalInterface fails to extend Remote!!
100      * public interface IllegalInterface {
101      * // illegalExceptions fails to throw RemoteException.
102      * void illegalExceptions();
103      * }
104      *
105      * @param RMIIIOPinterface the Interface to be checked for Rmi-IIOP compliance
106      *
107      * @return <code>boolean</code> true if RMIIIOPinterface is valid RMIIIOP interface, false otherwise
108      */

109     public static boolean isValidRmiIIOPInterface(Class JavaDoc RMIIIOPinterface) {
110
111     // 1. The interface is or inherits from java.rmi.Remote either directly or
112
// indirectly.
113
boolean validInterface = false;
114     Class JavaDoc c = RMIIIOPinterface;
115     // walk up the class tree
116
do {
117         if (RMIIIOPinterface.getName().equals("java.rmi.Remote")) {
118         validInterface = true;
119         break;
120         } else {
121         // walk up the class tree of the interface and see if it
122
// inherits from java.rmi.Remote either directly or indirectly.
123
Class JavaDoc[] interfaces = RMIIIOPinterface.getInterfaces();
124         //Class interfaces = RMIIIOPinterface.getSuperclass();
125
for (int i = 0; i < interfaces.length; i++) {
126
127             //if (interfaces[i].getName().equals("java.rmi.Remote")) {
128
if ((interfaces[i].getName().equals("java.rmi.Remote")) ||
129             //hack until i can ask hans why loop doesn't continue up past
130
// javax.ejb.EJBHome
131
(interfaces[i].getName().equals("javax.ejb.EJBObject")) ||
132             (interfaces[i].getName().equals("javax.ejb.EJBHome"))) {
133             validInterface = true;
134             break;
135             }
136             else if (isValidRmiIIOPInterface(interfaces[i])) {
137             return true;
138             }
139         }
140         }
141     } while ((((RMIIIOPinterface=RMIIIOPinterface.getSuperclass()) != null) && (!validInterface)));
142      
143         if (validInterface) {
144             return true;
145         } else {
146             return false;
147         }
148     }
149
150
151
152
153
154     /**
155      * Interface checked for RMI-IIOP compliance test.
156      *
157      * @param RMIIIOPinterface the Interface to be checked for Rmi-IIOP compliance
158      *
159      * @return <code>boolean</code> true if RMIIIOPinterface is valid RMIIIOP interface, false otherwise
160      */

161     public static boolean isValidRmiIIOPInterfaceMethods(Class JavaDoc RMIIIOPinterface) {
162
163         Class JavaDoc c = RMIIIOPinterface;
164         // continue on and check next condition
165

166         // All methods in the interface are defined to throw
167
// java.rmi.RemoteException or a superclass of java.rmi.RemoteException.
168
// Throughout this section, references to methods in the interface include
169
// methods in any inherited interfaces.
170
try {
171             Method methods[] = c.getDeclaredMethods();
172             Class JavaDoc [] methodExceptionTypes;
173             for (int i=0; i< methods.length; i++) {
174             // The methods exceptions types must be legal types for
175
// RMI-IIOP. This means that their exception values must
176
// throw java.rmi.RemoteException
177
methodExceptionTypes = methods[i].getExceptionTypes();
178             if (!EjbUtils.isValidRemoteException(methodExceptionTypes)) {
179                     return false;
180             } else {
181                 continue;
182             }
183         }
184  
185         // made it throw all methods thowing java.rmi.RemoteException check,
186
// without returning false, continue on...
187

188         // Method arguments and results may be of any types. However at run-time,
189
// the actual values passed as arguments or returned as results must be
190
// conforming RMI/IDL types (see "Overview of Conforming RMI/IDL Types" on
191
// page 28-2).
192
// can't check anything here, since this is a run-time check
193

194         // All checked exception classes used in method declarations (other than
195
// java.rmi.RemoteException and its subclasses) are conforming RMI/IDL
196
// exception types (see "RMI/IDL Exception Types" on page 28-5)1
197
for (int i=0; i < methods.length; i++) {
198             methodExceptionTypes = methods[i].getExceptionTypes();
199             if (!isValidRmiIIOPException(methodExceptionTypes)) {
200             return false;
201             } else {
202             continue;
203             }
204         }
205       
206         // Method names may be overloaded. However, when an interface directly
207
//inherits from several base interfaces, it is forbidden for there to be
208
//method name conflicts between the inherited interfaces. This outlaws the
209
//case where an interface A defines a method "foo," an interface B also
210
//defines a method "foo," and an interface C tries to inherit from both A
211
//and B.
212
// can't check anything here, since this is check cannot be determined
213
// thru reflection api checking
214

215         // Constant definitions in the form of interface variables are permitted.
216
//The constant value must be a compile-time constant of one of the RMI/IDL
217
// primitive types or String.
218

219         Field fields[] = c.getFields();
220         for (int i=0; i< fields.length; i++) {
221             // The fields types must be a compile-time constant of one of the
222
// RMI/IDL primitive types or String
223
if (!(isValidRmiIIOPField(fields[i]))) {
224             return false;
225             } else {
226             continue;
227             }
228         }
229  
230         // Method and constant names must not cause name collisions when mapped to
231
// IDL (see "Names that would cause OMG IDL name collisions" on page 28-9)
232
// can't check anything here, since this is an non-exhaustive search and
233
// compare, don't know all the various combinations that would cause
234
// name collisions,
235
} catch (Throwable JavaDoc t) {
236                 Verifier.debug(t);
237                 return false;
238             }
239      return true;
240     }
241
242     /**
243      * Method parameters checked for RMI-IIOP compliance test.
244      * Verify the following:
245      *
246      * The home/remote interface methods arguments types must be legal types for
247      * RMI-IIOP. This includes primitives, value types, and interfaces. This
248      * means that their arguments must be of valid types for RMI-IIOP.
249      *
250      * 28.2.4 RMI/IDL Value Types
251      * An RMI/IDL value type represents a class whose values can be moved
252      * between systems. So rather than transmitting a reference between systems,
253      * the actual state of the object is transmitted between systems. This
254      * requires that the receiving system have an analogous class that can be
255      * used to hold the received value. Value types may be passed as arguments
256      * or results of remote methods, or as fields within other objects that are
257      * passed remotely. A Java class is a conforming RMI/IDL value type if the
258      * following applies:
259      *
260      * 1. The class must implement the java.io.Serializable interface, either
261      * directly or indirectly, and must be serializable at run-time. It may
262      * serialize references to other RMI/IDL types, including value types
263      * and remote interfaces.
264      * 2. The class may implement java.io.Externalizable. (This indicates it
265      * overrides some of the standard serialization machinery.)
266      * 3. If the class is a non-static inner class, then its containing class
267      * must also be a conforming RMI/IDL value type.
268      * 4. A value type must not either directly or indirectly implement the
269      * java.rmi.Remote interface. (If this were allowed, then there would
270      * be potential confusion between value types and remote interface
271      * references.)
272      * 5. A value type may implement any interface except for java.rmi.Remote.
273      * 6. There are no restrictions on the method signatures for a value type.
274      * 7. There are no restrictions on static fields for a value type.
275      * 8. There are no restrictions on transient fields for a value type.
276      * 9. Method, constant and field names must not cause name collisions when
277      * mapped to IDL (see "Names that would cause OMG IDL name collisions"
278      * on page 28-9).
279      *
280      * Here is an example of a conforming RMI/IDL value type:
281      * // Java
282      * public class Point implements java.io.Serializable {
283      * public final static int CONSTANT_FOO = 3+3;
284      * private int x;
285      * private int y;
286      * public Point(int x, y) { ... }
287      * public int getX() { ... }
288      * public int getY() { ... }
289      * }
290      *
291      * 28.2.4.1 The Java String Type
292      * The java.lang.String class is a conforming RMI/IDL value type following
293      * these rules. Note, however, that String is handled specially when mapping
294      * Java to OMG IDL (see "Mapping for java.lang.String" on page 28-18).
295      *
296      * @param RMIIIOPparams the params to be checked for Rmi-IIOP compliance
297      *
298      * @return <code>boolean</code> true if RMIIIOPParams are valid RMIIIOP parameters, false otherwise
299      */

300     public static boolean isValidRmiIIOPParameters(Class JavaDoc [] RMIIIOPparams) {
301     if (RMIIIOPparams.length > 0) {
302         for (int ii = 0; ii < RMIIIOPparams.length; ii++) {
303         Class JavaDoc c = RMIIIOPparams[ii];
304
305         // if it's not a primitve, or
306
// if it's not a valid rmi-idl type, or
307
// if it's not java.lang.String, return false
308
if (!(isValidRmiIDLPrimitiveType(c)) &&
309             !(isValidRmiIIOPValueType(c)) &&
310             !(isValidRmiIIOPInterfaceType(c)) &&
311             !(isJavaLangStringType(c)) &&
312             !(isValidRmiIIOPException(RMIIIOPparams)) &&
313             !(c.getName().equals("java.lang.Object")) &&
314             !(isValidRmiIIOPCORBAObjectType(c)) &&
315             !(isValidRmiIIOPIDLEntityType(c))) {
316             //exception,corba object,array,idl entity type
317
return false;
318         }
319         }
320         // if you made it thru loop without returning false, then you
321
// passed the tests, return true
322
return true;
323     } else {
324         return true;
325     }
326     }
327
328
329     /**
330      * Class checked for RMI-IIOP value type compliance test.
331      * Verify the following:
332      *
333      * This class is proper CORBA Object type.
334      *
335      * @param RMIIIOPvaluetype the class to be checked
336      *
337      * @return <code>boolean</code> true if RMIIIOPvaluetype is valid Rmi-IIOP value type, false otherwise
338      */

339     public static boolean isValidRmiIIOPCORBAObjectType(Class JavaDoc RMIIIOPvaluetype) {
340
341     Class JavaDoc c = RMIIIOPvaluetype;
342     boolean validInterface = false;
343
344     do {
345         Class JavaDoc[] interfaces = c.getInterfaces();
346         for (int i = 0; i < interfaces.length; i++) {
347         if (interfaces[i].getName().equals("org.omg.CORBA.Object")) {
348             validInterface = true;
349             break;
350         } else {
351             // walk up the class tree of the interface and see if it
352
// implements org.omg.CORBA.Object
353
Class JavaDoc superClass = interfaces[i];
354             do {
355             if (superClass.getName().equals("org.omg.CORBA.Object")) {
356                 validInterface = true;
357                 break;
358             }
359             } while ((((superClass=superClass.getSuperclass()) != null) && (!validInterface)));
360         }
361         }
362     } while ((((c=c.getSuperclass()) != null) && (!validInterface)));
363     if (!validInterface) {
364         return false;
365     } else {
366         return true;
367     }
368     }
369
370   /**
371      * Class checked for RMI-IIOP value type compliance test.
372      * Verify the following:
373      *
374      * This class is proper Java IDL Entity type.
375      *
376      * @param RMIIIOPvaluetype the class to be checked
377      *
378      * @return <code>boolean</code> true if RMIIIOPvaluetype is valid Rmi-IIOP value type, false otherwise
379      */

380     public static boolean isValidRmiIIOPIDLEntityType(Class JavaDoc RMIIIOPvaluetype) {
381
382     Class JavaDoc c = RMIIIOPvaluetype;
383     boolean validInterface = false;
384
385     do {
386         Class JavaDoc[] interfaces = c.getInterfaces();
387         for (int i = 0; i < interfaces.length; i++) {
388         if (interfaces[i].getName().equals("org.omg.CORBA.portable.IDLEntity")) {
389             validInterface = true;
390             break;
391         } else {
392             // walk up the class tree of the interface and see if it
393
// implements java.io.Serializable
394
Class JavaDoc superClass = interfaces[i];
395             do {
396             if (superClass.getName().equals("org.omg.CORBA.portable.IDLEntity")) {
397                 validInterface = true;
398                 break;
399             }
400             } while ((((superClass=superClass.getSuperclass()) != null) && (!validInterface)));
401         }
402         }
403     } while ((((c=c.getSuperclass()) != null) && (!validInterface)));
404     if (!validInterface) {
405         return false;
406     } else {
407         return true;
408     }
409     }
410
411     /**
412      * Class checked for RMI-IIOP value type compliance test.
413      * Verify the following:
414      *
415      * This class s proper value types.
416      *
417      * @param RMIIIOPvaluetype the class to be checked for Rmi-IIOP value type
418      * compliance
419      *
420      * @return <code>boolean</code> true if RMIIIOPvaluetype is valid Rmi-IIOP value type, false otherwise
421      */

422     public static boolean isValidRmiIIOPValueType(Class JavaDoc RMIIIOPvaluetype) {
423
424     Class JavaDoc c = RMIIIOPvaluetype;
425     boolean validInterface = false;
426     boolean badOne = false;
427     // The class must implement the java.io.Serializable interface, either
428
// directly or indirectly, and must be serializable at run-time. It may
429
// serialize references to other RMI/IDL types, including value types
430
// and remote interfaces.
431
// walk up the class tree
432
if (c.getName().equals("java.lang.Object")) {
433         //validInterface = true;
434
return true;
435     }
436         /* Buggy Code
437     do {
438         Class[] interfaces = c.getInterfaces();
439         for (int i = 0; i < interfaces.length; i++) {
440         if (interfaces[i].getName().equals("java.io.Serializable")) {
441             validInterface = true;
442             break;
443         } else {
444             // walk up the class tree of the interface and see if it
445             // implements java.io.Serializable
446             Class superClass = interfaces[i];
447             do {
448             if (superClass.getName().equals("java.io.Serializable")) {
449                 validInterface = true;
450                 break;
451             }
452             } while ((((superClass=superClass.getSuperclass()) != null) && (validInterface == false)));
453         }
454         }
455     } while ((((c=c.getSuperclass()) != null) && (validInterface == false)));
456         */

457         validInterface = java.io.Serializable JavaDoc.class.isAssignableFrom(c);
458
459     if (validInterface == false) {
460         return false;
461     } else {
462         // 2. The class may implement java.io.Externalizable. (This indicates it
463
// overrides some of the standard serialization machinery.)
464
// nothing to check for here, since the keyword is "may implement"
465

466
467         // 3. If the class is a non-static inner class, then its containing class
468
// must also be a conforming RMI/IDL value type.
469
// don't know if this can be checked statically
470

471         // reset class c since it may have gotten moved in the above do/while loop
472
/* Buggy Code
473         c = RMIIIOPvaluetype;
474
475         do {
476         Class[] interfaces = c.getInterfaces();
477         for (int i = 0; i < interfaces.length; i++) {
478             if (interfaces[i].getName().equals("java.rmi.Remote")) {
479             badOne = true;
480             break;
481             }
482         }
483         } while ((((c=c.getSuperclass()) != null) && (!badOne)));
484             */

485
486             badOne = java.rmi.Remote JavaDoc.class.isAssignableFrom(c);
487
488         if (badOne) {
489         return false;
490         }
491   
492         // 5. A value type may implement any interface except for java.rmi.Remote.
493
// already checked this in step #4 above
494

495         // 6. There are no restrictions on the method signatures for a value type.
496
// 7. There are no restrictions on static fields for a value type.
497
// 8. There are no restrictions on transient fields for a value type.
498
// no checking need be done for these 6, 7, & 8
499

500         // 9. Method, constant and field names must not cause name collisions when
501
// mapped to IDL (see "Names that would cause OMG IDL name collisions"
502
// on page 28-9).
503
// can't check anything here, since this is an non-exhaustive search and
504
// compare, don't know all the various combinations that would cause
505
// name collisions, ask hans to be sure
506

507     }
508     if (validInterface) {
509         return true;
510     } else {
511         return false;
512     }
513     }
514
515
516     /**
517      * Constant definitions in the form of interface variables are permitted test.
518      * The constant value must be a compile-time constant of one of the RMI/IDL
519      * primitive types or String.
520      *
521      * Verify the following:
522      *
523      * The home/remote interface field types must be legal types for
524      * RMI-IIOP.
525      * This means that the constant value must be a compile-time constant
526      * of one of the RMI/IDL primitive types or String.
527      *
528      * @param RMIIIOPField the field to be checked for Rmi-IIOP compile-time
529      * constant of one of the RMI/IDL primitive types or String
530      *
531      * @return <code>boolean</code> true if RMIIIOPField is valid Rmi-IIOP type, false otherwise
532      */

533     public static boolean isValidRmiIIOPField(Field RMIIIOPField) {
534     boolean validPrimitiveType = false;
535     if ((isValidRmiIDLPrimitiveType(RMIIIOPField)) ||
536         (RMIIIOPField.getType().equals(java.lang.String JavaDoc.class))) {
537         validPrimitiveType = true;
538     }
539     return validPrimitiveType;
540     }
541
542
543
544     /**
545      * Constant definitions in the form of interface variables are permitted test.
546      * The constant value must be a compile-time constant of one of the RMI/IDL
547      * primitive types .
548      *
549      * Verify the following:
550      *
551      * The home/remote interface field types must be legal types for
552      * RMI-IIOP.
553      * This means that the constant value must be a compile-time constant
554      * of one of the RMI/IDL primitive types .
555      *
556      * @param RMIIIOPField the field to be checked for Rmi-IIOP compile-time
557      * constant of one of the RMI/IDL primitive types or String
558      *
559      * @return <code>boolean</code> true if RMIIIOPField is valid compile-time constant of
560      * one of the RMI/IDL primitive types, false otherwise
561      */

562     public static boolean isValidRmiIDLPrimitiveType(Field RMIIIOPField) {
563     boolean validPrimitiveType = false;
564     if ((RMIIIOPField.getType().getName().equals("void")) ||
565         (RMIIIOPField.getType().getName().equals("boolean")) ||
566         (RMIIIOPField.getType().getName().equals("byte")) ||
567         (RMIIIOPField.getType().getName().equals("char")) ||
568         (RMIIIOPField.getType().getName().equals("short")) ||
569         (RMIIIOPField.getType().getName().equals("int")) ||
570         (RMIIIOPField.getType().getName().equals("long")) ||
571         (RMIIIOPField.getType().getName().equals("float")) ||
572         (RMIIIOPField.getType().getName().equals("double"))) {
573         validPrimitiveType = true;
574     }
575     return validPrimitiveType;
576     }
577
578
579     /** Class is interface test.
580      * The class value must be a java interface type .
581      *
582      * Verify the following:
583      *
584      * The home/remote interface method params types must be legal types for
585      * RMI-IIOP.
586      * The class value must be a java interface type .
587      *
588      * @param interfaceClass the class to be checked for java interface class
589      *
590      * @return <code>boolean</code> true if interfaceClass is legal types for
591      * RMI-IIOP. false otherwise
592      */

593     private static boolean isValidRmiIIOPInterfaceType(Class JavaDoc interfaceClass) {
594     if (interfaceClass.isInterface()) {
595         return true;
596     } else {
597         return false;
598     }
599     }
600
601
602     /** Class is primitve test.
603      * The class value must be a java primitive type .
604      *
605      * Verify the following:
606      *
607      * The home/remote interface method params types must be legal types for
608      * RMI-IIOP.
609      * The class value must be a java primitive type .
610      *
611      * @param primitiveClass the class to be checked for java primitive class
612      *
613      * @return <code>boolean</code> true if primitiveClass is legal Java primitive type, false otherwise
614      */

615     public static boolean isValidRmiIDLPrimitiveType(Class JavaDoc primitiveClass) {
616     boolean validPrimitiveType = false;
617     if ((primitiveClass.getName().equals("void")) ||
618         (primitiveClass.getName().equals("boolean")) ||
619         (primitiveClass.getName().equals("byte")) ||
620         (primitiveClass.getName().equals("char")) ||
621         (primitiveClass.getName().equals("short")) ||
622         (primitiveClass.getName().equals("int")) ||
623         (primitiveClass.getName().equals("long")) ||
624         (primitiveClass.getName().equals("float")) ||
625         (primitiveClass.getName().equals("double"))) {
626         validPrimitiveType = true;
627     }
628     return validPrimitiveType;
629     }
630
631
632     /**
633      * Class is java.lang.String test.
634      * The class value may be java.lang.String type .
635      *
636      * Verify the following:
637      *
638      * The home/remote interface method params types must be legal types for
639      * RMI-IIOP.
640      * The class value may be java.lang.String type .
641      *
642      * @param jlsClass the class to be checked for java primitive class
643      *
644      * @return <code>boolean</code> true if jlsClass is java.lang.String type, false otherwise
645      */

646     public static boolean isJavaLangStringType(Class JavaDoc jlsClass) {
647     boolean validJlsType = false;
648     if (jlsClass.getName().equals("java.lang.String")) {
649         validJlsType = true;
650     }
651     return validJlsType;
652     }
653
654     /**
655      * Method exception checked for RMI-IIOP compliance test.
656      * Verify the following:
657      *
658      * The home/remote interface methods exception types must be legal types for
659      * RMI-IIOP. This includes primitives, value types, and interfaces.
660      * This means that their exception must throw java.rmi.RemoteException.
661      *
662      * 28.2.6 RMI/IDL Exception Types An RMI/IDL exception type is a checked
663      * exception class (as defined by the Java Language Specification). Since
664      * checked exception classes extend java.lang.Throwable which implements
665      * java.io.Serializable, it is unnecessary for an RMI/IDL exception class to
666      * directly implement java.io.Serializable. A type is a conforming RMI/IDL
667      * exception if the class:
668      * - is a checked exception class.
669      * - meets the requirements for RMI/IDL value types defined in
670      * "RMI/IDL Value Types" on page 28-4.
671      *
672      * @param RMIIIOPexceptions the exceptions to be checked for Rmi-IIOP throws
673      * java.rmi.RemoteException
674      *
675      * @return <code>boolean</code> true if RMIIIOPexceptions are legal type for RMI-IIOP, false otherwise
676      */

677     public static boolean isValidRmiIIOPException(Class JavaDoc [] RMIIIOPexceptions) {
678     // methods must throw java.rmi.RemoteException
679
boolean throwsRemoteException = false;
680     for (int kk = 0; kk < RMIIIOPexceptions.length; ++kk) {
681         if ((RMIIIOPexceptions[kk].getName().equals("java.rmi.RemoteException")) ||
682         (RMIIIOPexceptions[kk].getName().equals("RemoteException"))) {
683         throwsRemoteException = true;
684         break;
685         }
686     }
687     return throwsRemoteException;
688     }
689
690     /**
691      * Method return type checked for RMI-IIOP compliance test.
692      * Verify the following:
693      *
694      * The home/remote interface methods return type must be legal types for
695      * RMI-IIOP. This includes primitives, value types, and interfaces.
696      * This means that their return type must be of valid types for RMI-IIOP.
697      *
698      * @param RMIIIOPparams the return type to be checked for Rmi-IIOP compliance
699      *
700      * @return <code>boolean</code> true if RMIIIOPReturnType is legal type for RMI-IIOP, false otherwise
701      */

702     public static boolean isValidRmiIIOPReturnType(Class JavaDoc RMIIIOPReturnType) {
703     // if it's not a primitve, or
704
// if it's not a valid rmi-idl type, or
705
// if it's not java.lang.String, return false
706
if (!((isValidRmiIDLPrimitiveType(RMIIIOPReturnType)) ||
707           (isValidRmiIIOPValueType(RMIIIOPReturnType)) ||
708           (isValidRmiIIOPInterfaceType(RMIIIOPReturnType)) ||
709           (isJavaLangStringType(RMIIIOPReturnType)) ||
710           //(isValidRmiIIOPException(RMIIIOPparams)) ||
711
(isValidRmiIIOPCORBAObjectType(RMIIIOPReturnType)) ||
712           (RMIIIOPReturnType.getName().equals("java.lang.Object")) ||
713           (isValidRmiIIOPIDLEntityType(RMIIIOPReturnType)))) {
714         return false;
715     } else {
716         return true;
717     }
718     }
719
720
721     /**
722      * Class checked for Serializable value type compliance test.
723      * Verify the following:
724      *
725      * This class is a serializable class.
726      *
727      * @param serializableClass the class to be checked for serializable
728      * compliance
729      *
730      * @return <code>boolean</code> true if c is a serializable class, false otherwise
731      */

732     public static boolean isValidSerializableType(Class JavaDoc c) {
733
734        return java.io.Serializable JavaDoc.class.isAssignableFrom(c);
735
736        /* Buggy Code
737     boolean validInterface = false;
738
739     if (c.getName().equals("java.io.Serializable")) {
740         validInterface = true;
741         return validInterface;
742     }
743     do {
744         Class[] interfaces = c.getInterfaces();
745         for (int i = 0; i < interfaces.length; i++) {
746         if (interfaces[i].getName().equals("java.io.Serializable")) {
747             validInterface = true;
748             break;
749         } else {
750             // walk up the class tree of the interface and see if it
751             // implements java.io.Serializable
752             Class superClass = interfaces[i];
753             do {
754             if (superClass.getName().equals("java.io.Serializable")) {
755                 validInterface = true;
756                 break;
757             }
758             } while ((((superClass=superClass.getSuperclass()) != null) && (!validInterface)));
759         }
760         }
761     } while ((((c=c.getSuperclass()) != null) && (!validInterface)));
762
763     // The class must implement the java.io.Serializable interface, either
764     // directly or indirectly, and must be serializable at run-time.
765     // walk up the class tree
766
767     if (!validInterface) {
768         return false;
769     } else {
770         return true;
771     }
772         */

773     }
774
775
776     /**
777      * Container managed fields checked for one of the following:
778      * Java primitive types, Java serializable types, or references to
779      * enterprise beans' remote or home interfaces.
780      *
781      * Verify the following:
782      *
783      * Container managed fields checked for one of the following:
784      * Java primitive types, Java serializable types, or references to
785      * enterprise beans' remote or home interfaces.
786      *
787      * All the standard Java primitive types are supported as part of RMI/IDL.
788      * These are: void, boolean, byte, char, short, int, long, float, double
789      *
790      * @param CmpField params to be checked for CmpField valid type compliance
791      * @param HomeClass home class
792      * @param RemoteClass remote class
793      *
794      * @return <code>boolean</code> true if CmpField is Java primitive type,
795      * Java serializable types, or references to
796      * enterprise beans' remote or home interfaces.,
797      * false otherwise
798      */

799     public static boolean isPersistentFieldTypeValid(Class JavaDoc CmpField, String JavaDoc HomeClass, String JavaDoc RemoteClass) {
800     // if Java primitive types, Java serializable types, or references to
801
// enterprise beans' remote or home interfaces.
802
if (!((isValidRmiIDLPrimitiveType(CmpField)) ||
803           (isValidSerializableType(CmpField)) ||
804           (CmpField.getName().equals(HomeClass)) ||
805           (CmpField.getName().equals(RemoteClass)))) {
806         return false;
807     } else {
808         return true;
809     }
810
811     }
812
813
814     /**
815      * The ejbFind<METHOD> exceptions of Bean clas smust be a subset of the names
816      * of the exceptions defined in the throws clause of the matching find method
817      * of the home interface.
818      *
819      * Verify the following:
820      *
821      * All the exceptions defined in the throws clause of the
822      * matching ejbFind method of the
823      * enterprise Bean class must be included in the throws
824      * clause of the matching find method of the home interface
825      * this home interface find method must define a superset of all the
826      * exceptions thrown in the ejbFind method of the bean class
827      * so there may not be a 1-1 mapping of exceptions
828      * also, for all ejbFind/find combo's any unchecked
829      * exceptions thrown by the ejbFind<METHOD> in the bean
830      * class doesn't need to be thrown in the corresponding
831      * find<METHOD> of the home interface , these unchecked
832      * exceptions "subclass of RuntimeException" i.e
833      * out of memory exception are handled by the container,
834      * who throws a Runtime exception to the appropriate
835      * instance/object
836      *
837      * @param ejbFindExceptions the ejbFind<METHOD> exceptions to be checked for
838      * containment within the names of the exceptions defined in the throws
839      * clause of the matching find method of the home interface (i.e subset)
840      * @param findExceptions the find<METHOD> exceptions to be checked for
841      * containing the names of the exceptions defined in the throws
842      * clause of the matching ejbFind<METHOD> method of the bean class
843      * (i.e. superset)
844      *
845      * @return <code>boolean</code> true if ejbFindExceptions is subset of findExceptions,
846      * false otherwise
847      */

848     public static boolean isEjbFindMethodExceptionsSubsetOfFindMethodExceptions
849     (Class JavaDoc [] ejbFindExceptions, Class JavaDoc [] findExceptions) {
850     boolean oneFailed = false;
851     if (Arrays.equals(ejbFindExceptions,findExceptions)) {
852         return true;
853     } else {
854         // manipulate as list, and use list.contains() method
855
List ejbFindList = Arrays.asList(ejbFindExceptions);
856         List findList = Arrays.asList(findExceptions);
857         if (!ejbFindList.isEmpty()) {
858         for (Iterator itr = ejbFindList.iterator(); itr.hasNext();) {
859             Class JavaDoc nextEjbFindMethodException = (Class JavaDoc) itr.next();
860             if (findList.contains(nextEjbFindMethodException)) {
861             continue;
862             } else {
863             // also, for all ejbFind/find combo's any unchecked
864
// exceptions thrown by the ejbFind<METHOD> in the bean
865
// class doesn't need to be thrown in the corresponding
866
// find<METHOD> of the home interface , these unchecked
867
// exceptions "subclass of RuntimeException" i.e
868
// out of memory exception are handled by the container,
869
// who throws a Runtime exception to the appropriate
870
// instance/object
871
if (isSuperClassofClass("java.lang.RuntimeException",
872                         nextEjbFindMethodException)) {
873                 // ignore this particular unchecked exception, since it stems
874
// from RuntimeException, we can ignore it
875
continue;
876             } else {
877                 // okay, that's it, now we know ejbFind<METHOD> exception
878
// is not defined in the find<METHOD> in the home interface
879
// test must fail
880
oneFailed = true;
881                 // break out after first failure, however, no precise feedback
882
// to caller as to exactly which exception is causing problem
883
// which we happen to know at this point in time
884
break;
885             }
886             }
887         }
888         
889         // if we get thru all of 'em, and oneFailed is set, then we flunked test
890
if (oneFailed) {
891             return false;
892         } else {
893             // we know we never set oneFailed in the above loop, so either all
894
// ejbFind<METHOD> exceptions are defined in the superset find<METHOD>
895
// exceptions, or they are unchecked exceptions, which we can ignore
896
// so set test to passed
897
return true;
898         }
899         } else {
900         // ejbFind<METHOD> exceptions list is empty, pass test
901
return true;
902         }
903     }
904     }
905
906
907     /**
908      * Find superClass of specified class.
909      *
910      * @param superClass the specifed super Class to be checked against
911      * for containment of
912      * @param fromClass the class which you are trying to find the parent super
913      * class of
914      *
915      * @return <code>boolean</code> true if superClass is parent class of fromClass, false otherwise
916      */

917     private static boolean isSuperClassofClass(String JavaDoc superClass, Class JavaDoc fromClass) {
918     boolean validSuperClass = false;
919     Class JavaDoc c = fromClass;
920     // walk up the class tree
921
do {
922         if (c.getName().equals(superClass)) {
923         validSuperClass = true;
924         break;
925         }
926     } while ((((c=c.getSuperclass()) != null) && (!validSuperClass)));
927
928     if (!validSuperClass){
929         return false;
930     } else {
931         return true;
932     }
933
934
935
936     }
937
938
939 }
940
Popular Tags