1 23 24 package com.sun.enterprise.tools.verifier.tests.web; 25 26 27 import com.sun.enterprise.tools.verifier.tests.TagLibTest; 28 import com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor; 29 import com.sun.enterprise.tools.verifier.Result; 30 import com.sun.enterprise.tools.verifier.Context; 31 import com.sun.enterprise.tools.verifier.TagLibDescriptor; 32 import com.sun.enterprise.tools.verifier.web.FunctionDescriptor; 33 import com.sun.enterprise.deployment.WebBundleDescriptor; 34 35 42 public class TaglibFunctionSignatureIsValid extends TagLibTest implements WebCheck { 43 public Result check(WebBundleDescriptor descriptor) { 44 ComponentNameConstructor compName = 45 getVerifierContext().getComponentNameConstructor(); 46 Result result = getInitializedResult(); 47 Context context = getVerifierContext(); 48 TagLibDescriptor tlds[] = context.getTagLibDescriptors(); 49 FunctionDescriptor[] fnDesc = null; 50 51 if (tlds == null) { 52 addGoodDetails(result, compName); 53 result.passed(smh.getLocalString 54 (getClass().getName() + ".passed", 55 "No tag lib files are specified")); 56 return result; 57 } 58 59 for (TagLibDescriptor tld : tlds) { 60 if (tld.getSpecVersion().compareTo("2.0") >= 0) { 61 fnDesc = tld.getFunctionDescriptors(); 62 if (fnDesc != null) 63 for (FunctionDescriptor fd : fnDesc) 64 checkSignature(result, fd, tld, compName); 65 } 66 } 67 if (result.getStatus() != Result.FAILED) { 68 addGoodDetails(result, compName); 69 result.passed(smh.getLocalString(getClass() 70 .getName() + 71 ".passed", "function-signature element of the tag lib " + 72 "descriptor are properly defined.")); 73 } 74 return result; 75 } 76 77 85 private void checkSignature(Result result, FunctionDescriptor fnDesc, 86 TagLibDescriptor tld, 87 ComponentNameConstructor compName) { 88 String signature = fnDesc.getFunctionSignature(); 89 ClassLoader cl = getVerifierContext().getClassLoader(); 90 String retType = getRetType(signature); 91 String [] parameter = getParameters(signature); 92 if (checkIfPrimitive(retType) == null && !checkValidRType(retType)) { 93 addErrorDetails(result, compName); 94 result.failed(smh.getLocalString(getClass().getName() + 95 ".failed", 96 "ERROR: In the tld [ {0} ] return type is not specified correctly in " + 97 "this signature [ {1} ]", 98 new Object []{tld.getUri(), signature})); 99 } 100 if(!checkParamTypeClass(parameter, cl)) { 102 addErrorDetails(result, compName); 103 result.failed(smh.getLocalString(getClass().getName() + 104 ".failed1", 105 "ERROR: In the tld [ {0} ] parameters are not specified correctly in " + 106 "this signature [ {1} ]", 107 new Object []{tld.getUri(), signature})); 108 } 109 } 110 111 116 private boolean checkValidRType(String retType) { 117 boolean valid = true; 118 try { 119 Class.forName(retType); 120 } catch (ClassNotFoundException e) { 121 return valid=false; 122 } 123 return valid; 124 } 125 126 133 private boolean checkParamTypeClass(String [] par, ClassLoader cl) { 134 for(String s : par) { 135 Class c = checkIfPrimitive(s); 136 if (c == null) 137 try { 138 c = Class.forName(s, false, cl); 139 } catch (ClassNotFoundException e) { 140 return false; 141 } 142 } 143 return true; 144 } 145 } 146 | Popular Tags |