1 23 package com.sun.enterprise.tools.verifier.tests.web; 24 25 import java.util.*; 26 import java.util.logging.Level ; 27 import com.sun.enterprise.deployment.WebBundleDescriptor; 28 import com.sun.enterprise.deployment.EjbBundleDescriptor; 29 import com.sun.enterprise.deployment.EjbReferenceDescriptor; 30 import com.sun.enterprise.deployment.Application; 31 import com.sun.enterprise.deployment.EjbDescriptor; 32 import com.sun.enterprise.tools.verifier.*; 33 import com.sun.enterprise.tools.verifier.tests.*; 34 import com.sun.enterprise.tools.verifier.tests.*; 35 36 37 40 public class EjbLinkElement extends WebTest implements WebCheck { 41 42 43 50 public Result check(WebBundleDescriptor descriptor) { 51 52 Result result = getInitializedResult(); 53 ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor(); 54 55 boolean resolved = false; 56 boolean oneFailed = false; 57 int na = 0; 58 59 String applicationName = null; 62 if (!descriptor.getEjbReferenceDescriptors().isEmpty()) { 63 for (Iterator itr = descriptor.getEjbReferenceDescriptors().iterator(); 64 itr.hasNext();) { 65 EjbReferenceDescriptor nextEjbReference = (EjbReferenceDescriptor) itr.next(); 66 if (nextEjbReference.isLinked()) { 67 String ejb_link = nextEjbReference.getLinkName(); 68 ejb_link = ejb_link.substring(ejb_link.indexOf("#") + 1); 69 try { 71 Application application = descriptor.getApplication(); 72 applicationName = application.getName(); 73 Set ejbBundles = application.getEjbBundleDescriptors(); 77 Iterator ejbBundlesIterator = ejbBundles.iterator(); 78 EjbBundleDescriptor ejbBundle = null; 79 while (ejbBundlesIterator.hasNext()) { 80 ejbBundle = (EjbBundleDescriptor)ejbBundlesIterator.next(); 81 for (Iterator itr2 = ejbBundle.getEjbs().iterator(); itr2.hasNext();) { 85 EjbDescriptor ejbDescriptor = (EjbDescriptor) itr2.next(); 86 if (ejbDescriptor.getName().equals(ejb_link)) { 87 resolved = true; 88 logger.log(Level.FINE, getClass().getName() + ".passed", 89 new Object [] {ejb_link,ejbDescriptor.getName()}); 90 result.addGoodDetails(smh.getLocalString 91 ("tests.componentNameConstructor", 92 "For [ {0} ]", 93 new Object [] {compName.toString()})); 94 result.addGoodDetails 95 (smh.getLocalString 96 (getClass().getName() + ".passed", 97 "ejb-link [ {0} ] found same value as EJB [ {1} ]", 98 new Object [] {ejb_link,ejbDescriptor.getName()})); 99 break; 100 } 101 } 102 } 103 } catch (Exception e) { 104 105 106 logger.log(Level.FINE, "com.sun.enterprise.tools.verifier.testsprint {0}", new Object [] {"[" + getClass() + "] Error: " + e.getMessage()}); 107 if (!oneFailed) { 108 oneFailed = true; 109 } 110 } 111 112 if (!resolved) { 115 if (!oneFailed) { 116 oneFailed = true; 117 } 118 result.addErrorDetails(smh.getLocalString 119 ("tests.componentNameConstructor", 120 "For [ {0} ]", 121 new Object [] {compName.toString()})); 122 result.addErrorDetails(smh.getLocalString 123 (getClass().getName() + ".failed", 124 "Error: No EJB matching [ {0} ] found within [ {1} ] ear file.", 125 new Object [] {ejb_link, applicationName})); 126 } else { 127 resolved =false; 129 } 130 131 } else { 132 result.addNaDetails(smh.getLocalString 135 ("tests.componentNameConstructor", 136 "For [ {0} ]", 137 new Object [] {compName.toString()})); 138 result.addNaDetails 139 (smh.getLocalString 140 (getClass().getName() + ".notApplicable1", 141 "Not Applicable: Cannot verify the existance of an ejb reference [ {0} ] to external bean within different .ear file.", 142 new Object [] {nextEjbReference.getName()})); 143 na++; 144 } 145 } 146 147 if (oneFailed) { 148 result.setStatus(result.FAILED); 149 } else if (na == descriptor.getEjbReferenceDescriptors().size()) { 150 result.setStatus(result.NOT_APPLICABLE); 151 } else { 152 result.setStatus(result.PASSED); 153 } 154 return result; 158 159 } else { 160 result.notApplicable(smh.getLocalString 161 (getClass().getName() + ".notApplicable", 162 "There are no ejb references to other beans within this web archive [ {0} ]", 163 new Object [] {descriptor.getName()})); 164 } 165 return result; 166 } 167 } 168 | Popular Tags |