InjectionTargetTestpublic abstract class InjectionTargetTest extends VerifierTest implements VerifierCheckThe field or method where injection annotation is used may have any access
qualifier (public , private , etc.) but must not be static or final.
This is the base class of all the InjectionAnnotation tests. |
Fields Summary |
---|
private com.sun.enterprise.deployment.Descriptor | descriptor | com.sun.enterprise.tools.verifier.Result | result | ComponentNameConstructor | compName |
Methods Summary |
---|
public com.sun.enterprise.tools.verifier.Result | check(com.sun.enterprise.deployment.Descriptor descriptor)
this.descriptor = descriptor;
result = getInitializedResult();
compName = getVerifierContext().getComponentNameConstructor();
ClassLoader cl = getVerifierContext().getClassLoader();
List<InjectionCapable> injectables = getInjectables(getClassName());
for (InjectionCapable injectionCapable : injectables) {
Set<InjectionTarget> iTargets = injectionCapable.getInjectionTargets();
for (InjectionTarget target : iTargets) {
try {
if(target.isFieldInjectable()) {
Class classObj = Class.forName(getClassName(), false, cl);
Field field = classObj.getDeclaredField(target.getFieldName());
testMethodModifiers(field.getModifiers(), "field", field);
}
if(target.isMethodInjectable()) {
Class classObj = Class.forName(getClassName(), false, cl);
Method method = getInjectedMethod(classObj, target.getMethodName());
if(method == null) continue;
testMethodModifiers(method.getModifiers(), "method", method);
}
} catch (Exception e) {} //ignore as it will be caught in other tests
}
}
if(result.getStatus() != Result.FAILED) {
addGoodDetails(result, compName);
result.passed(smh.getLocalString
(getClass().getName()+".passed",
"Valid injection method(s)."));
}
return result;
| protected abstract java.lang.String | getClassName()
| protected com.sun.enterprise.deployment.Descriptor | getDescriptor()
return descriptor;
| protected abstract java.util.List | getInjectables(java.lang.String className)
| private java.lang.reflect.Method | getInjectedMethod(java.lang.Class classObj, java.lang.String methodName)
for (Method method : classObj.getDeclaredMethods()) {
if(method.getName().equals(methodName))
return method;
}
return null;
| private void | testMethodModifiers(int modifier, java.lang.String targetType, java.lang.Object fieldOrMethod)
if(Modifier.isStatic(modifier) ||
Modifier.isFinal(modifier)) {
addErrorDetails(result, compName);
result.failed(smh.getLocalString
("com.sun.enterprise.tools.verifier.tests.InjectionTargetTest.failed",
"Invalid annotation in {0} [ {1} ].",
new Object[] {targetType, fieldOrMethod}));
}
|
|