1 23 package com.sun.enterprise.tools.verifier.tests.ejb; 24 25 import java.io.*; 26 27 import com.sun.enterprise.deployment.*; 28 import com.sun.enterprise.deployment.io.DescriptorConstants; 29 import com.sun.enterprise.tools.verifier.*; 30 31 import com.sun.enterprise.tools.verifier.tests.*; 32 import com.sun.enterprise.deployment.deploy.shared.FileArchive; 33 34 39 public class EjbPublicID extends EjbTest implements EjbCheck { 40 41 42 51 public Result check(EjbDescriptor descriptor) { 52 53 Result result = getInitializedResult(); 54 55 String acceptablePubidLiterals[] = { 56 "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 1.1//EN", 57 "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN" }; 58 String acceptableURLs[] = {"http://java.sun.com/j2ee/dtds/ejb-jar_1_1.dtd", 59 "http://java.sun.com/dtd/ejb-jar_2_0.dtd"}; 60 61 ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor(); 62 63 if (descriptor.getEjbBundleDescriptor().getSpecVersion().compareTo("2.1") < 0){ 65 InputStream deploymentEntry=null; 66 String uri = null; 67 68 try { 69 uri = getAbstractArchiveUri(descriptor); 70 FileArchive arch = new FileArchive(); 71 arch.open(uri); 72 deploymentEntry = arch.getEntry(DescriptorConstants.EJB_DD_ENTRY); 73 74 if (deploymentEntry != null) { 75 BufferedReader in = new BufferedReader(new InputStreamReader(deploymentEntry)); 76 String s = in.readLine(); 77 boolean foundDOCTYPE = false, foundPubid = false, foundURL = false; 78 79 while(s != null) { 80 if(s.indexOf("DOCTYPE") > -1) 82 foundDOCTYPE = true; 83 if(foundDOCTYPE){ 84 for (int i=0;i<acceptablePubidLiterals.length;i++) { 85 if (s.indexOf(acceptablePubidLiterals[i]) > -1) { 86 foundPubid = true; 87 result.addGoodDetails(smh.getLocalString 88 ("tests.componentNameConstructor", 89 "For [ {0} ]", 90 new Object [] {compName.toString()})); 91 result.addGoodDetails 92 (smh.getLocalString 93 (getClass().getName() + ".passed", 94 "The deployment descriptor has the proper PubidLiteral: {0}", 95 new Object [] {acceptablePubidLiterals[i]})); 96 } 97 if (s.indexOf(acceptableURLs[i]) > -1) { 99 foundURL = true; 100 result.addGoodDetails(smh.getLocalString 101 ("tests.componentNameConstructor", 102 "For [ {0} ]", 103 new Object [] {compName.toString()})); 104 result.addGoodDetails 105 (smh.getLocalString 106 (getClass().getName() + ".passed1", 107 "The deployment descriptor has the proper URL corresponding the the PubIdLiteral: {0}", 108 new Object [] {acceptableURLs[i]})); 109 } 110 } 111 } 112 if(foundPubid && foundURL) { 113 result.setStatus(Result.PASSED); 114 break; 115 } else if(foundDOCTYPE && s.endsWith(">")) break; s = in.readLine(); 117 } 118 119 if(!foundDOCTYPE){ 120 result.addErrorDetails(smh.getLocalString 121 ("tests.componentNameConstructor", 122 "For [ {0} ]", 123 new Object [] {compName.toString()})); 124 result.failed 125 (smh.getLocalString 126 (getClass().getName() + ".failed1", 127 "Error: No document type declaration found in the deployment descriptor for {0}", 128 new Object [] {descriptor.getName()})); 129 } else if(!foundPubid) { 130 result.addErrorDetails(smh.getLocalString 131 ("tests.componentNameConstructor", 132 "For [ {0} ]", 133 new Object [] {compName.toString()})); 134 result.failed 135 (smh.getLocalString 136 (getClass().getName() + ".failed2", 137 "Error: The deployment descriptor for {0} does not have an expected PubidLiteral ", 138 new Object [] {descriptor.getName()})); 139 } else if (!foundURL){ 140 result.addErrorDetails(smh.getLocalString 141 ("tests.componentNameConstructor", 142 "For [ {0} ]", 143 new Object [] {compName.toString()})); 144 result.failed(smh.getLocalString 145 (getClass().getName() + ".failed", 146 "The deployment descriptor {0} doesnot have the right URL corresponding to the PubIdLiteral", 147 new Object [] {descriptor.getName()})); 148 } 149 } 150 151 } catch (IOException e) { 152 result.addErrorDetails(smh.getLocalString 153 ("tests.componentNameConstructor", 154 "For [ {0} ]", 155 new Object [] {compName.toString()})); 156 result.failed(smh.getLocalString 157 (getClass().getName() + ".IOException", 158 "Error: I/O error trying to open {0}", new Object [] {uri})); 159 } finally { 160 try { 161 if (deploymentEntry != null) 162 deploymentEntry.close(); 163 } catch (Exception x) {} 164 } 165 }else{ 166 result.addNaDetails(smh.getLocalString 168 ("tests.componentNameConstructor", 169 "For [ {0} ]", 170 new Object [] {compName.toString()})); 171 result.notApplicable(smh.getLocalString 172 (getClass().getName() + ".notApplicable", 173 "NOT-APPLICABLE: No DOCTYPE found for [ {0} ]", 174 new Object [] {descriptor.getName()})); 175 } 176 177 return result; 178 } 179 } 180 | Popular Tags |