FileDocCategorySizeDatePackage
InjectionTargetTest.javaAPI DocGlassfish v2 API5579Fri May 04 22:33:26 BST 2007com.sun.enterprise.tools.verifier.tests

InjectionTargetTest

public abstract class InjectionTargetTest extends VerifierTest implements VerifierCheck
The 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.
author
Vikas Awasthi

Fields Summary
private com.sun.enterprise.deployment.Descriptor
descriptor
com.sun.enterprise.tools.verifier.Result
result
ComponentNameConstructor
compName
Constructors Summary
Methods Summary
public com.sun.enterprise.tools.verifier.Resultcheck(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.StringgetClassName()

protected com.sun.enterprise.deployment.DescriptorgetDescriptor()

        return descriptor;
    
protected abstract java.util.ListgetInjectables(java.lang.String className)

private java.lang.reflect.MethodgetInjectedMethod(java.lang.Class classObj, java.lang.String methodName)

        for (Method method : classObj.getDeclaredMethods()) {
            if(method.getName().equals(methodName)) 
                return method;
        }
        return null;
    
private voidtestMethodModifiers(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}));
        }