KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.util.*;
26 import java.lang.reflect.*;
27
28 /**
29  * Utility package for dealing with method descriptors from <method-permission>
30  * element and <container-transaction> elements
31  */

32 public class MethodUtils {
33
34     /**
35      * Add method name to vector
36      *
37      * @param v Vector to be added to
38      * @param methods array of methods to be added to vector
39      *
40      */

41     public static void addMethodNamesToVector(Vector<String JavaDoc> v, Method[] methods) {
42         for (int i=0; i< methods.length; i++) {
43             // add method name to vector
44
v.addElement(methods[i].getName());
45         }
46     }
47  
48     /**
49      * Determine is method parameters are equal.
50      *
51      * @param v Vector to be added to
52      * @param hMethods array of home interface methods to be added to vector
53      * @param rMethods array of remote interface methods to be added to vector
54      *
55      */

56     public static void addMethodNamesToVector(Vector<String JavaDoc> v, Method[] hMethods, Method[] rMethods) {
57         // add method names to vector for both home and remote interfaces
58
addMethodNamesToVector(v,hMethods);
59         addMethodNamesToVector(v,rMethods);
60     }
61  
62    
63     /**
64      * Determine is method parameters are equal.
65      *
66      * @param s1 array of parameters for method
67      * @param s2 array of parameters for method
68      *
69      * @return <code>boolean</code> the results for this parameter equality test
70      */

71     public static boolean stringArrayEquals(String JavaDoc[] s1, String JavaDoc[] s2) {
72         if (s1 == null && s2 == null) {
73             return true;
74         }
75         if (s1 == null && s2 != null) {
76             return false;
77         }
78         if (s2 == null && s1 != null) {
79             return false;
80         }
81         if (s1.length == s2.length) {
82             for (int i = 0; i < s1.length; i++) {
83                 if (!s1[i].equals(s2[i])) {
84                     return false;
85                 }
86             }
87             return true;
88         } else {
89             return false;
90         }
91     }
92     
93     /** returns true if method names, return types and parameters match. Otherwise
94      * it returns false. */

95     public static boolean methodEquals(Method classMethod, Method intfMethod) {
96         return classMethod.getName().equals(intfMethod.getName()) &&
97                 intfMethod.getReturnType().isAssignableFrom(classMethod.getReturnType()) &&
98                 Arrays.equals(classMethod.getParameterTypes(), intfMethod.getParameterTypes());
99     }
100
101 }
102
Popular Tags