public Result check(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;
  }
Пример #2
0
  public Result check(WebBundleDescriptor descriptor) {

    Result result = getInitializedResult();
    addWarningDetails(result, getVerifierContext().getComponentNameConstructor());
    result.setStatus(Result.PASSED); // default status is PASSED

    for (EntityManagerReferenceDescriptor emRefDesc :
        descriptor.getEntityManagerReferenceDescriptors()) {
      Set<InjectionTarget> injectionTargets = emRefDesc.getInjectionTargets();
      if (injectionTargets != null) {
        for (InjectionTarget it : injectionTargets) {
          String itClassName = it.getClassName();
          String errMsg =
              smh.getLocalString(
                  className + ".warning",
                  "Found a persistence unit by name [ {0} ] injected into [ {1} ].",
                  new Object[] {emRefDesc.getUnitName(), itClassName});
          try {
            Class c = Class.forName(itClassName, false, getVerifierContext().getClassLoader());
            if (!(Servlet.class.isAssignableFrom(c))) {
              result.warning(errMsg);
            } else if (!(SingleThreadModel.class.isAssignableFrom(c))) {
              result.warning(errMsg);
            }
          } catch (Exception ex) {
            result.warning(errMsg);
          }
        }
      }
    }
    return result;
  }