1 23 package com.sun.enterprise.tools.verifier.tests.web; 24 25 import java.util.*; 26 import com.sun.enterprise.deployment.*; 27 import com.sun.enterprise.tools.verifier.*; 28 import com.sun.enterprise.tools.verifier.tests.*; 29 import com.sun.enterprise.deployment.WebComponentDescriptor; 30 31 35 public class ServletParamName extends WebTest implements WebCheck { 36 37 38 46 public Result check(WebBundleDescriptor descriptor) { 47 48 Set servlets; 49 Iterator servItr; 50 String epName = null; 51 Result result = getInitializedResult(); 52 ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor(); 53 WebComponentDescriptor servlet = null; 54 Enumeration en; 55 EnvironmentProperty ep = null; 56 boolean oneFailed = false; 57 boolean duplicate = false; 58 59 if (!descriptor.getServletDescriptors().isEmpty()) { 60 61 servlets = descriptor.getServletDescriptors(); 63 servItr = servlets.iterator(); 64 while (servItr.hasNext()) { 66 servlet = (WebComponentDescriptor)servItr.next(); 67 HashSet<String > envSet = new HashSet<String >(); 68 for ( en = servlet.getInitializationParameters(); en.hasMoreElements();) { 69 ep = (EnvironmentProperty)en.nextElement(); 70 epName = ep.getName(); 71 72 if (epName.length() != 0) { 73 duplicate = checkDuplicate(epName, envSet); 75 76 } else { 77 oneFailed = true; 78 result.addErrorDetails(smh.getLocalString 79 ("tests.componentNameConstructor", 80 "For [ {0} ]", 81 new Object [] {compName.toString()})); 82 result.addErrorDetails(smh.getLocalString 83 (getClass().getName() + ".failed", 84 "Error: Param name/value entry should of finite length.")); 85 } 86 if ( !duplicate) { 87 envSet.add(epName); 88 } 89 else { 90 oneFailed = true; 91 result.addErrorDetails(smh.getLocalString 92 ("tests.componentNameConstructor", 93 "For [ {0} ]", 94 new Object [] {compName.toString()})); 95 result.addErrorDetails(smh.getLocalString 96 (getClass().getName() + ".failed", 97 "Error: Duplicate param names are not allowed.")); 98 } 99 } 100 } 101 result.addGoodDetails(smh.getLocalString 102 ("tests.componentNameConstructor", 103 "For [ {0} ]", 104 new Object [] {compName.toString()})); 105 result.addGoodDetails(smh.getLocalString 106 (getClass().getName() + ".passed", 107 "Param named/value exists for in the servlet [ {0} ].", 108 new Object [] {servlet.getName()})); 109 110 } else { 111 result.setStatus(Result.NOT_APPLICABLE); 112 result.addNaDetails(smh.getLocalString 113 ("tests.componentNameConstructor", 114 "For [ {0} ]", 115 new Object [] {compName.toString()})); 116 result.notApplicable(smh.getLocalString 117 (getClass().getName() + ".notApplicable", 118 "There are no initialization parameters for the servlet within the web archive [ {0} ]", 119 new Object [] {descriptor.getName()})); 120 return result; 121 } 122 123 if (oneFailed) { 124 result.setStatus(Result.FAILED); 125 } else { 126 result.setStatus(Result.PASSED); 127 } 128 return result; 129 } 130 131 private boolean checkDuplicate(String epName, HashSet theSet) { 132 133 return theSet.contains(epName); 134 } 135 } 136 137 | Popular Tags |