1 23 package com.sun.enterprise.tools.verifier.tests.ejb.beanclass; 24 25 import com.sun.enterprise.tools.verifier.tests.ejb.EjbTest; 26 import java.lang.reflect.*; 27 import com.sun.enterprise.deployment.*; 28 import com.sun.enterprise.tools.verifier.*; 29 import com.sun.enterprise.tools.verifier.tests.ejb.EjbCheck; 30 import com.sun.enterprise.tools.verifier.tests.*; 31 32 33 43 public class EjbClassStaticFieldsFinal extends EjbTest implements EjbCheck { 44 45 46 47 61 public Result check(EjbDescriptor descriptor) { 62 63 Result result = getInitializedResult(); 64 ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor(); 65 66 try { 69 Class c = Class.forName(descriptor.getEjbClassName(), false, getVerifierContext().getClassLoader()); 70 71 boolean oneFailed = false; 72 boolean badField = false; 73 Field [] fields = c.getDeclaredFields(); 74 for (int i = 0; i < fields.length; i++) { 75 badField = false; 76 if (fields[i].getName().indexOf("$") == -1) { 81 int modifiers = fields[i].getModifiers(); 82 if (Modifier.isStatic(modifiers)) { 83 if (Modifier.isFinal(modifiers)) { 84 continue; 85 } else { 86 if (!oneFailed) { 87 oneFailed = true; 88 } 89 badField = true; 90 } 91 } 92 } 93 94 if (badField) { 95 result.addWarningDetails(smh.getLocalString 96 ("tests.componentNameConstructor", 97 "For [ {0} ]", 98 new Object [] {compName.toString()})); 99 result.warning(smh.getLocalString 100 (getClass().getName() + ".warning", 101 "Warning: Field [ {0} ] defined within bean class [ {1} ] is defined as static, but not defined as final. An enterprise Bean must not use read/write static fields. Using read-only static fields is allowed.", 102 new Object [] {fields[i].getName(),(descriptor).getEjbClassName()})); 103 } 104 } 105 if (!oneFailed) { 106 result.addGoodDetails(smh.getLocalString 107 ("tests.componentNameConstructor", 108 "For [ {0} ]", 109 new Object [] {compName.toString()})); 110 result.passed(smh.getLocalString 111 (getClass().getName() + ".passed", 112 "This bean class [ {0} ] has defined any and all static fields as final.", 113 new Object [] {(descriptor).getEjbClassName()})); 114 } 115 } catch (ClassNotFoundException e) { 116 Verifier.debug(e); 117 result.addErrorDetails(smh.getLocalString 118 ("tests.componentNameConstructor", 119 "For [ {0} ]", 120 new Object [] {compName.toString()})); 121 result.failed(smh.getLocalString 122 (getClass().getName() + ".failedException", 123 "Error: [ {0} ] class not found.", 124 new Object [] {(descriptor).getEjbClassName()})); 125 } catch (Exception e) { 126 Verifier.debug(e); 127 result.addErrorDetails(smh.getLocalString 128 ("tests.componentNameConstructor", 129 "For [ {0} ]", 130 new Object [] {compName.toString()})); 131 result.failed(smh.getLocalString 132 (getClass().getName() + ".failedException1", 133 "Error: [ {0} ] class encountered [ {1} ]", 134 new Object [] {(descriptor).getEjbClassName(),e.getMessage()})); 135 } catch (Throwable t) { 136 result.addWarningDetails(smh.getLocalString 137 ("tests.componentNameConstructor", 138 "For [ {0} ]", 139 new Object [] {compName.toString()})); 140 result.warning(smh.getLocalString 141 (getClass().getName() + ".warningException", 142 "Warning: [ {0} ] class encountered [ {1} ]. Cannot access fields of class [ {2} ] which is external to [ {3} ].", 143 new Object [] {(descriptor).getEjbClassName(),t.toString(), t.getMessage(), descriptor.getEjbBundleDescriptor().getModuleDescriptor().getArchiveUri()})); 144 } 145 return result; 146 147 } 148 } 149 | Popular Tags |