FileDocCategorySizeDatePackage
TagLibTest.javaAPI DocGlassfish v2 API7295Fri May 04 22:33:26 BST 2007com.sun.enterprise.tools.verifier.tests

TagLibTest

public abstract class TagLibTest extends com.sun.enterprise.tools.verifier.tests.web.WebTest
author
Sudipto Ghosh

Fields Summary
Constructors Summary
Methods Summary
public java.lang.StringgetName(java.lang.String signature)
This method will return the method name from the signature String passed as argument. eg: for java.lana.String nickName( java.lang.String, int )

param
signature
return
method name

        StringBuilder sb = new StringBuilder();
        String[] tokens = (signature.split("\\s"));
        for (int i = 1; i < tokens.length; i++)
            sb.append(tokens[i]);
        String name = sb.toString();
        name = name.substring(0, name.indexOf("("));
        return name;
    
public java.lang.Class[]getParamTypeClass(java.lang.String[] par, java.lang.ClassLoader cl)
given a parameter array contained in a method, this method returns the Class array representation of the parameters

param
par
param
cl
return
class array representation of the parameters

        List<Class> list = new ArrayList<Class>();
        for(String s : par) {
            Class c = checkIfPrimitive(s);
            if (c != null)
                list.add(c);
            else {
                try {
                    c = Class.forName(s, false, cl);
                    list.add(c);
                } catch (ClassNotFoundException e) {
                  //do nothing. Other test will report the problem if parameter
                  // is not specified correctly
                }
            }
        }
        return list.toArray(new Class[0]);
    
public java.lang.String[]getParameters(java.lang.String signature)
This method parses the function-signature argument and returns the list of parameters as String array. signature param to this method contains the value of this element in tld. java.lana.String nickName( java.lang.String, int )

param
signature
return
The String array containing the parameter class type.

        StringBuilder sb = new StringBuilder();
        String[] tokens = (signature.split("\\s"));
        for (int i = 1; i < tokens.length; i++)
            sb.append(tokens[i]);
        String fullParamString = sb.toString().substring(sb.indexOf("(") + 1, sb.indexOf(")"));
        String[] params = getParams(fullParamString);
        return params;
    
public java.lang.String[]getParams(java.lang.String fullParamString)

param
fullParamString This is the parsed string from which the parameters will be separated and added as a list of Strings eg: for java.lana.String nickName( java.lang.String, int ) . The parsed String will look like this java.lang.String,int
return
String array containing all the parameter Types

        List<String> list = new ArrayList<String>();
        if (fullParamString.contains(",")) {
            String rest = fullParamString.substring(fullParamString.indexOf(",") + 1, fullParamString.length());
            fullParamString = fullParamString.substring(0, fullParamString.indexOf(","));
            list.add(fullParamString);
            getParams(rest);
        } else list.add(fullParamString);

        return list.toArray(new String[0]);
    
public java.lang.StringgetRetType(java.lang.String signature)
This method returns the first token of this string, which must be the return type of the method.

param
signature string from the function-signature element of tld
return
return type of the method.

        String[] tokens = (signature.split("\\s"));
        return tokens[0];
    
public booleanparametersMatch(java.lang.reflect.Method m, java.lang.Class[] param)
Checks if the parameter array matches with this method's parameters

param
m method object
param
param parameter class array
return
true if parameters match, false otherwise

        boolean match = false;
        Class[] types = m.getParameterTypes();
        if (types.length!=param.length)
            return false;
        for (int i=0; i<types.length; i++) {
            match = types[i].equals(param[i]);
        }
        return match;
    
public booleanreturnTypeMatch(java.lang.reflect.Method m, java.lang.String retType)
Checks if the return type specified in this method m and the return type required matches

param
m
param
retType
return
true if retType and m.getReturnType matches, false otherwise

        Class ret = m.getReturnType();
        Class retTypeClass  = checkIfPrimitive(retType);
        if (retTypeClass == null);
        try {
            retTypeClass = Class.forName(retType);
        } catch (ClassNotFoundException e) {
            //do nothing. If return type is incorrect, it will be caught by
            // another test in verifier.
        }
        if(retTypeClass != null)            //this may happen if retType is
            return retTypeClass.equals(ret);//non-primitive and invalid
        else return false;