1 23 24 package com.sun.enterprise.tools.verifier.tests; 25 26 import java.util.List ; 27 import java.util.ArrayList ; 28 import java.lang.reflect.Method ; 29 30 import com.sun.enterprise.tools.verifier.tests.web.WebTest; 31 32 35 public abstract class TagLibTest extends WebTest { 36 37 48 public String [] getParameters(String signature) { 49 StringBuilder sb = new StringBuilder (); 50 String [] tokens = (signature.split("\\s")); 51 for (int i = 1; i < tokens.length; i++) 52 sb.append(tokens[i]); 53 String fullParamString = sb.toString().substring(sb.indexOf("(") + 1, sb.indexOf(")")); 54 String [] params = getParams(fullParamString); 55 return params; 56 } 57 58 67 68 public String [] getParams(String fullParamString) { 69 List <String > list = new ArrayList <String >(); 70 if (fullParamString.contains(",")) { 71 String rest = fullParamString.substring(fullParamString.indexOf(",") + 1, fullParamString.length()); 72 fullParamString = fullParamString.substring(0, fullParamString.indexOf(",")); 73 list.add(fullParamString); 74 getParams(rest); 75 } else list.add(fullParamString); 76 77 return list.toArray(new String [0]); 78 } 79 80 81 87 public String getRetType(String signature) { 88 String [] tokens = (signature.split("\\s")); 89 return tokens[0]; 90 } 91 92 100 public String getName(String signature) { 101 StringBuilder sb = new StringBuilder (); 102 String [] tokens = (signature.split("\\s")); 103 for (int i = 1; i < tokens.length; i++) 104 sb.append(tokens[i]); 105 String name = sb.toString(); 106 name = name.substring(0, name.indexOf("(")); 107 return name; 108 } 109 110 111 117 public boolean parametersMatch(Method m, Class [] param) { 118 boolean match = false; 119 Class [] types = m.getParameterTypes(); 120 if (types.length!=param.length) 121 return false; 122 for (int i=0; i<types.length; i++) { 123 match = types[i].equals(param[i]); 124 } 125 return match; 126 } 127 128 135 public boolean returnTypeMatch(Method m, String retType) { 136 Class ret = m.getReturnType(); 137 Class retTypeClass = checkIfPrimitive(retType); 138 if (retTypeClass == null); 139 try { 140 retTypeClass = Class.forName(retType); 141 } catch (ClassNotFoundException e) { 142 } 145 if(retTypeClass != null) return retTypeClass.equals(ret); else return false; 148 } 149 150 157 public Class [] getParamTypeClass(String [] par, ClassLoader cl) { 158 List <Class > list = new ArrayList <Class >(); 159 for(String s : par) { 160 Class c = checkIfPrimitive(s); 161 if (c != null) 162 list.add(c); 163 else { 164 try { 165 c = Class.forName(s, false, cl); 166 list.add(c); 167 } catch (ClassNotFoundException e) { 168 } 171 } 172 } 173 return list.toArray(new Class [0]); 174 } 175 } 176 | Popular Tags |