1 23 24 package com.sun.enterprise.tools.verifier.tests.ejb; 25 26 import com.sun.enterprise.tools.verifier.Result; 27 import com.sun.enterprise.tools.verifier.Verifier; 28 import com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor; 29 import com.sun.enterprise.deployment.*; 30 31 import java.lang.reflect.Method ; 32 import java.util.HashSet ; 33 import java.util.Iterator ; 34 import java.util.Set ; 35 36 42 public class LocalInterfaceExposed extends EjbTest implements EjbCheck { 43 44 52 public Result check(EjbDescriptor descriptor) { 53 54 Result result = getInitializedResult(); 55 ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor(); 56 57 if (!(descriptor instanceof EjbSessionDescriptor) && 58 !(descriptor instanceof EjbEntityDescriptor)) { 59 addNaDetails(result, compName); 60 result.notApplicable(smh.getLocalString 61 (getClass().getName()+".notApplicable1", 62 "Test apply only to session or entity beans.")); 63 return result; 64 } 65 66 EjbBundleDescriptor bundle = descriptor.getEjbBundleDescriptor(); 67 Iterator iterator = (bundle.getEjbs()).iterator(); 68 Set <String > localInterfaces = new HashSet <String >(); 69 while(iterator.hasNext()) { 70 EjbAbstractDescriptor entity = (EjbAbstractDescriptor) iterator.next(); 71 if (entity.getLocalClassName() != null) 72 localInterfaces.add(entity.getLocalClassName()); 73 localInterfaces.addAll(entity.getLocalBusinessClassNames()); 74 } 75 ClassLoader jcl = getVerifierContext().getClassLoader(); 76 try { 77 Set <String > remoteInterfaces = new HashSet <String >(); 78 if(descriptor.getRemoteClassName()!=null) 79 remoteInterfaces.add(descriptor.getRemoteClassName()); 80 remoteInterfaces.addAll(descriptor.getRemoteBusinessClassNames()); 81 82 for (String intf : remoteInterfaces) { 83 Class c = Class.forName(intf, false, getVerifierContext().getClassLoader()); 84 Method [] methods = c.getDeclaredMethods(); 85 for(int i=0; i<methods.length; i++) { 86 for(Iterator itr = localInterfaces.iterator();itr.hasNext();) { 88 String localIntf = (String ) itr.next(); 89 Class returnType = methods[i].getReturnType(); 90 if((getBaseComponentType(returnType).getName()).equals(localIntf) || 91 (contains(methods[i].getParameterTypes(), localIntf))) { 92 addErrorDetails(result, compName); 93 result.failed(smh.getLocalString 94 (getClass().getName() + ".failed", 95 "Error : Local Interface [ {0} ] has been " + 96 "exposed in remote interface [ {1} ]", 97 new Object [] {localIntf, c.getName()})); 98 return result; 99 } 100 } 101 } 102 } 103 addGoodDetails(result, compName); 104 result.passed(smh.getLocalString 105 (getClass().getName() + ".passed", 106 "Valid Remote interface.")); 107 } catch (ClassNotFoundException e) { 108 Verifier.debug(e); 109 addErrorDetails(result, compName); 110 result.failed(smh.getLocalString 111 (getClass().getName() + ".failedException", 112 "Error: [ {0} ] class not found.", 113 new Object [] {descriptor.getRemoteClassName()})); 114 } 115 return result; 116 } 117 118 private boolean contains(Class [] args, String intf) { 119 for (int i = 0; i < args.length; i++) 120 if(getBaseComponentType(args[i]).getName().equals(intf)) 121 return true; 122 123 return false; 124 } 125 126 128 private Class getBaseComponentType(Class cls) { 129 if(!cls.isArray()) 130 return cls; 131 return getBaseComponentType(cls.getComponentType()); 132 } 133 } 134 135 | Popular Tags |