Package com.sun.enterprise.tools.verifier

Examples of com.sun.enterprise.tools.verifier.Result


     *  
     * @return <code>Result</code> the results for this assertion
     */
    public Result check(EjbDescriptor descriptor) {

        Result result = getInitializedResult();
        ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();

        if (descriptor instanceof EjbSessionDescriptor) {
            try {
                Class c = Class.forName(((EjbSessionDescriptor)descriptor).getEjbClassName(), false, getVerifierContext().getClassLoader());
                // fields should not be defined in the session bean class as transient.
                Field [] fields = c.getDeclaredFields();
                for (int i = 0; i < fields.length; i++) {
                    int modifiers = fields[i].getModifiers();
                    if (!Modifier.isTransient(modifiers)) {
                        continue;
                    } else {
                        addWarningDetails(result, compName);
                        result.warning(smh.getLocalString
                                (getClass().getName() + ".warning",
                                        "Warning: Field [ {0} ] defined within session bean class [ {1} ] is defined as transient.  Session bean fields should not be defined in the session bean class as transient.",
                                        new Object[] {fields[i].getName(),((EjbSessionDescriptor)descriptor).getEjbClassName()}));
                    }
                }
            } catch (ClassNotFoundException e) {
                Verifier.debug(e);
                addErrorDetails(result, compName);
                result.failed(smh.getLocalString
                        (getClass().getName() + ".failedException",
                                "Error: [ {0} ] class not found.",
                                new Object[] {((EjbSessionDescriptor)descriptor).getEjbClassName()}));
            } catch (Throwable t) {
                addWarningDetails(result, compName);
                result.warning(smh.getLocalString
                        (getClass().getName() + ".warningException",
                        "Warning: [ {0} ] class encountered [ {1} ]. " +
                        "Cannot access fields of class [ {2} ] which is external to [ {3} ].",
                         new Object[] {(descriptor).getEjbClassName(),t.toString(),
                         t.getMessage(),
                         descriptor.getEjbBundleDescriptor().getModuleDescriptor().getArchiveUri()}));
            }
            return result;
        }

        if(result.getStatus()!=Result.WARNING){
            addGoodDetails(result, compName);
            result.passed(smh.getLocalString
                    (getClass().getName() + ".passed",
                            "The session bean class has defined all fields " +
                    "as non-transient fields."));

        }
View Full Code Here


*/
public class TaglibFunctionSignatureIsValid extends TagLibTest implements WebCheck {
    public Result check(WebBundleDescriptor descriptor) {
        ComponentNameConstructor compName =
                getVerifierContext().getComponentNameConstructor();
        Result result = getInitializedResult();
        Context context = getVerifierContext();
        TagLibDescriptor tlds[] = context.getTagLibDescriptors();
        FunctionDescriptor[] fnDesc = null;

        if (tlds == null) {
            addGoodDetails(result, compName);
            result.passed(smh.getLocalString
                    (getClass().getName() + ".passed",
                            "No tag lib files are specified"));
            return result;
        }

        for (TagLibDescriptor tld : tlds) {
            if (tld.getSpecVersion().compareTo("2.0") >= 0) {
                fnDesc = tld.getFunctionDescriptors();
                if (fnDesc != null)
                    for (FunctionDescriptor fd : fnDesc)
                        checkSignature(result, fd, tld, compName);
            }
        }
        if (result.getStatus() != Result.FAILED) {
            addGoodDetails(result, compName);
            result.passed(smh.getLocalString(getClass()
                    .getName() +
                    ".passed", "function-signature element of the tag lib " +
                    "descriptor are properly defined."));
        }
        return result;
View Full Code Here

* @author Vikas Awasthi
*/
public class CallbackMethodException extends EjbTest {

    public Result check(EjbDescriptor descriptor) {
        Result result = getInitializedResult();
        ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
        ClassLoader cl = getVerifierContext().getClassLoader();

        Set<LifecycleCallbackDescriptor> callbackDescs =
                                        new HashSet<LifecycleCallbackDescriptor>();
       
        for (EjbInterceptor interceptor : descriptor.getInterceptorClasses()) {
            callbackDescs.addAll(interceptor.getPostConstructDescriptors());
            callbackDescs.addAll(interceptor.getPreDestroyDescriptors());
            callbackDescs.addAll(interceptor.getCallbackDescriptors(
                        LifecycleCallbackDescriptor.CallbackType.PRE_PASSIVATE));
            callbackDescs.addAll(interceptor.getCallbackDescriptors(
                        LifecycleCallbackDescriptor.CallbackType.POST_ACTIVATE));
        }

        if(descriptor.hasPostConstructMethod())
            callbackDescs.addAll(descriptor.getPostConstructDescriptors());
        if(descriptor.hasPreDestroyMethod())
            callbackDescs.addAll(descriptor.getPreDestroyDescriptors());
       
        // session descriptor has two extra interceptor methods.
        if(descriptor instanceof EjbSessionDescriptor) {
            EjbSessionDescriptor ejbSessionDescriptor = ((EjbSessionDescriptor)descriptor);
            if(ejbSessionDescriptor.hasPostActivateMethod())
                callbackDescs.addAll(ejbSessionDescriptor.getPostActivateDescriptors());
            if(ejbSessionDescriptor.hasPrePassivateMethod())
                callbackDescs.addAll(ejbSessionDescriptor.getPrePassivateDescriptors());
        }

        for (LifecycleCallbackDescriptor callbackDesc : callbackDescs) {
            try {
                Method method = callbackDesc.getLifecycleCallbackMethodObject(cl);
                Class[] excepClasses = method.getExceptionTypes();
                for (Class exception : excepClasses) {
                    if(!(RuntimeException.class.isAssignableFrom(exception) ||
                            java.rmi.RemoteException.class.isAssignableFrom(exception))) {
                        addErrorDetails(result, compName);
                        result.failed(smh.getLocalString
                                        (getClass().getName() + ".failed",
                                        "Method [ {0} ] throws an application exception.",
                                        new Object[] {method}));
                    }
                }
            } catch (Exception e) {}// will be caught in other tests
        }
       
        if(result.getStatus()!=Result.FAILED) {
            addGoodDetails(result, compName);
            result.passed(smh.getLocalString
                            (getClass().getName() + ".passed",
                            "Valid Callback methods."));
        }
       
        return result;
View Full Code Here

//</addition>

public class ASWebEjbRef extends WebTest implements WebCheck {

    public Result check(WebBundleDescriptor descriptor) {
        Result result = getInitializedResult();
        ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
        boolean oneFailed = false;
        String refName;
        EjbRef[] ejbRefs = (descriptor.getSunDescriptor()).getEjbRef();
        if (ejbRefs!=null && ejbRefs.length > 0) {
            for (int rep=0; rep<ejbRefs.length; rep++ ) {
                refName = ejbRefs[rep].getEjbRefName();
                if (validEjbRefName(refName,descriptor)) {
                    addGoodDetails(result, compName);
                    result.passed(smh.getLocalString
                            (getClass().getName() + ".passed",
                                    "PASSED [AS-WEB ejb-ref] ejb-ref-name [ {0} ] properly defined in the war file.",
                                    new Object[] {refName}));
                } else {
                    oneFailed = true;
                    addErrorDetails(result, compName);
                    result.failed(smh.getLocalString
                            (getClass().getName() + ".failed",
                                    "FAILED [AS-WEB ejb-ref] ejb-ref-name [ {0} ] is not valid, either empty or not defined in web.xml.",
                                    new Object[] {refName}));
                }
            }
        } else {
            addNaDetails(result, compName);
            result.notApplicable(smh.getLocalString
                    (getClass().getName() + ".notApplicable",
                            "NOT APPLICABLE [AS-WEB sun-web-app] ejb-ref element(s) not defined in the web archive [ {0} ].",
                            new Object[] {descriptor.getName()}));
            return result;
        }
        if (oneFailed)
        {
            result.setStatus(Result.FAILED);
        } else {
            addGoodDetails(result, compName);
            result.passed
                    (smh.getLocalString
                    (getClass().getName() + ".passed2",
                            "PASSED [AS-WEB sun-web-app] ejb-ref element(s) defined are valid within the web archive [ {0} ].",
                            new Object[] {descriptor.getName()} ));
        }
View Full Code Here

     * See ejb specification 2.1 section 10.3.13
     * @param descriptor the Enterprise Java Bean deployment descriptor
     * @return <code>Result</code> the results for this assertion
     */
    public Result check(EjbDescriptor descriptor){
        Result result = getInitializedResult();
        ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
        String abstractSchema = null;

        if(descriptor instanceof EjbEntityDescriptor) {
            if (((EjbEntityDescriptor)descriptor).getPersistenceType().equals(EjbEntityDescriptor.CONTAINER_PERSISTENCE)) {
                if (((EjbCMPEntityDescriptor) descriptor).getCMPVersion()==EjbCMPEntityDescriptor.CMP_2_x) {
                    abstractSchema = ((EjbCMPEntityDescriptor)descriptor).getAbstractSchemaName();
                    if(abstractSchema!=null) {
                        boolean isJavaIdentifier=true;
                        boolean startChar=Character.isJavaIdentifierStart(abstractSchema.charAt(0));
                        if (startChar) {
                            for(int i=1;i<abstractSchema.length();i++)
                                if(!Character.isJavaIdentifierPart(abstractSchema.charAt(i))) {
                                    isJavaIdentifier=false;
                                    break;
                                }
                        } else {
                            isJavaIdentifier=false;
                        }
                        if(isJavaIdentifier) {
                            result.addGoodDetails(smh.getLocalString
                                    ("tests.componentNameConstructor",
                                            "For [ {0} ]",
                                            new Object[] {compName.toString()}));
                            result.passed(smh.getLocalString
                                    (getClass().getName() + ".passed",
                                            "abstract-schema-name [ {0} ] within bean [ {1} ] is a valid java identifier",
                                            new Object[] {abstractSchema, descriptor.getName()}));
                        }else{
                            result.addErrorDetails(smh.getLocalString
                                    ("tests.componentNameConstructor",
                                            "For [ {0} ]",
                                            new Object[] {compName.toString()}));
                            result.failed(smh.getLocalString
                                    (getClass().getName() + ".failed",
                                            "abstract-schema-name [ {0} ] within bean [ {1} ] is not a valid java identifier",
                                            new Object[] {abstractSchema, descriptor.getName()}));
                        }
                    }
                }
            }
        }
        if(abstractSchema==null){
            result.addNaDetails(smh.getLocalString
                    ("tests.componentNameConstructor",
                            "For [ {0} ]",
                            new Object[] {compName.toString()}));
            result.notApplicable(smh.getLocalString
                    (getClass().getName() + ".notApplicable",
                            "abstract-schema-name is not defined or this is not applicable for this bean"));
        }
        return result;
    }
View Full Code Here

* @author Vikas Awasthi
*/
public class BusinessInterfaceException extends EjbTest {

    public Result check(EjbDescriptor descriptor) {
        Result result = getInitializedResult();
        ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
       
        Set<String> localAndRemoteClassNames = descriptor.getLocalBusinessClassNames();
        localAndRemoteClassNames.addAll(descriptor.getRemoteBusinessClassNames());
       
        for (String localOrRemoteClass : localAndRemoteClassNames)
            checkForRemoteException(localOrRemoteClass,result,compName);

        if(result.getStatus() != Result.WARNING) {
            addGoodDetails(result, compName);
            result.passed(smh.getLocalString
                            (getClass().getName() + ".passed",
                            "Business interface(s) if any are valid."));
        }
        return result;
    }
View Full Code Here

     * @param descriptor the Enterprise Java Bean deployment descriptor
     * @return <code>Result</code> the results for this assertion
     */
    public Result check(EjbDescriptor descriptor) {
       
    Result result = getInitializedResult();
    ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
    try {

        if (descriptor instanceof IASEjbCMPEntityDescriptor) {
            Collection col = null;
            if(getVerifierContext().getJDOException()!=null){
                result.addErrorDetails(smh.getLocalString
                            ("tests.componentNameConstructor",
                                    "For [ {0} ]",
                                    new Object[] {compName.toString()}));
                result.failed (smh.getLocalString(getClass().getName() + ".failed1",
                            "Error: Exception [ {0} ] while initialising JDO code generator.",
                            new Object[] {getVerifierContext().getJDOException().getMessage()}));

                return result;
            }else{
                try{
                    JDOCodeGenerator jdc= getVerifierContext().getJDOCodeGenerator();
                    col = jdc.validate((IASEjbCMPEntityDescriptor)descriptor);
                }catch(Exception ex){
                    result.addErrorDetails(smh.getLocalString
                            ("tests.componentNameConstructor",
                                    "For [ {0} ]",
                                    new Object[] {compName.toString()}));
                    result.failed (smh.getLocalString(getClass().getName() + ".failed",
                            "Error: Exception [ {0} ] when calling JDOCodeGenerator.validate().",
                            new Object[] {ex.getMessage()}));
                    return result;
                }
            }
            if (col.isEmpty()){
              result.addGoodDetails(smh.getLocalString
                                       ("tests.componentNameConstructor",
                                        "For [ {0} ]",
                                        new Object[] {compName.toString()}));
              result.passed(smh.getLocalString(getClass().getName() + ".passed",
                            "Syntax and Semantics of EJBQL Queries (if any) are correct."));

            }else{
               // collect all the EJBQL errors
               String allErrors = null;
               Iterator it = col.iterator();
               while (it.hasNext()) {
                  Exception e = (Exception)it.next();
                  if (e instanceof EJBQLException) {
                     allErrors = e.getMessage() + "\n\n";
                  }
               }

               if (allErrors != null) {
                 result.addErrorDetails(smh.getLocalString
                                       ("tests.componentNameConstructor",
                                        "For [ {0} ]",
                                        new Object[] {compName.toString()}));
                 result.failed(smh.getLocalString(getClass().getName() + ".parseError",
                            "Error: Entity bean [ {0} ] has the following EJBQL error(s) [ {1} ]."
                            , new Object[] {descriptor.getEjbClassName(), "\n" + allErrors} ));

               }
               else {
                 result.addGoodDetails(smh.getLocalString
                                       ("tests.componentNameConstructor",
                                        "For [ {0} ]",
                                        new Object[] {compName.toString()}));
                 result.passed(smh.getLocalString(getClass().getName() + ".passed",
                            "Syntax and Semantics of EJBQL Queries (if any) are correct."));
               }
            }

  } else {
      result.addNaDetails(smh.getLocalString
               ("tests.componentNameConstructor",
          "For [ {0} ]",
          new Object[] {compName.toString()}));
      result.notApplicable(
                    smh.getLocalString(getClass().getName() + ".notApplicable",
                            "Not applicable: Test only applies to container managed EJBs"));
  }
    } catch(Exception e) {
      result.addErrorDetails(smh.getLocalString
                                       ("tests.componentNameConstructor",
                                        "For [ {0} ]",
                                        new Object[] {compName.toString()}));
      result.failed (smh.getLocalString(getClass().getName() + ".failed",
                            "Error: Exception [ {0} ] when calling JDOCodeGenerator.validate().",
                            new Object[] {e.getMessage()}));
    }
      return result;
    }
View Full Code Here

     *  
     * @return <code>Result</code> the results for this assertion
     */
    public Result check(EjbDescriptor descriptor) {

  Result result = getInitializedResult();
        try {

  if (descriptor instanceof EjbCMPEntityDescriptor) {
      String persistence =
    ((EjbEntityDescriptor)descriptor).getPersistenceType();
      if (EjbEntityDescriptor.CONTAINER_PERSISTENCE.equals(persistence) &&
                   ((EjbCMPEntityDescriptor)descriptor).getCMPVersion()==EjbCMPEntityDescriptor.CMP_1_1) {

                try {
        Class c = Class.forName(descriptor.getHomeClassName(), false, getVerifierContext().getClassLoader());
        Method [] methods = c.getDeclaredMethods();
                    boolean oneFailed = false;
                    for (int i=0;i<methods.length;i++) {
                        Method aMethod = methods[i];
                        if (aMethod.getName().startsWith("create")) {
                            if (!aMethod.getName().endsWith("create")) {
            result.addErrorDetails(smh.getLocalString
                 (getClass().getName() + ".failed",
                  "CMP 1.1 entity beans are not authorized to define [ {0} ] method",
                  new Object[] {aMethod.getName()}));
                                     oneFailed = true;
                            }
                        }
                    }
                    if (oneFailed) {
            result.setStatus(Result.FAILED);
                    } else {
                        result.passed(smh.getLocalString
          (getClass().getName() + ".passed",
                                        "No create<METHOD> defined for this CMP 1.1 entity bean [ {0} ] ",
           new Object[] {descriptor.getName()}));
                    }
                    return result;
                } catch(ClassNotFoundException cnfe) {
        result.failed(smh.getLocalString
          (getClass().getName() + ".failedException",
           "Error: [ {0} ] class not found.",
           new Object[] {descriptor.getHomeClassName()}));
                    return result;
                }
            }
        }
        } catch(Exception e) {
            e.printStackTrace();
        }
        result.notApplicable(smh.getLocalString
                             (getClass().getName() + ".notApplicable",
                              "[ {0} ] is not a CMP 1.1 Entity Bean.",
                              new Object[] {descriptor.getName()}));
       return result;
    }                       
View Full Code Here

     *  
     * @return <code>Result</code> the results for this assertion
     */
    public Result check(EjbDescriptor descriptor) {

        Result result = getInitializedResult();
        ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
        boolean oneFound = false;

        if (descriptor instanceof EjbSessionDescriptor) {
            try {
                Context context = getVerifierContext();
                ClassLoader jcl = context.getClassLoader();
                Class c = Class.forName(descriptor.getEjbClassName(), false, getVerifierContext().getClassLoader());
                // walk up the class tree
                do {
                    Class[] interfaces = c.getInterfaces();

                    for (int i = 0; i < interfaces.length; i++) {
                        if (interfaces[i].getName().equals("javax.ejb.SessionSynchronization")) {
                            oneFound = true;
                            break;
                        }
                    }
                } while ((c=c.getSuperclass()) != null);

            } catch (ClassNotFoundException e) {
                Verifier.debug(e);
                addErrorDetails(result, compName);
                result.failed(smh.getLocalString
                        (getClass().getName() + ".failedException1",
                                "Error: [ {0} ] class not found.",
                                new Object[] {descriptor.getEjbClassName()}));
                return result;
            }

            // If an enterprise bean implements the javax.ejb.SessionSynchronization
            // interface, the Application Assembler can specify only the following
            // values for the transaction attributes of the bean's methods:
            //   Required, RequiresNew, Mandatory
            if (oneFound) {
                String transactionAttribute = "";
                ContainerTransaction containerTransaction = null;
                boolean oneFailed = false;
                if (!descriptor.getMethodContainerTransactions().isEmpty()) {
                    for (Enumeration ee = descriptor.getMethodContainerTransactions().keys(); ee.hasMoreElements();) {
                        MethodDescriptor methodDescriptor = (MethodDescriptor) ee.nextElement();
                        containerTransaction =
                                (ContainerTransaction) descriptor.getMethodContainerTransactions().get(methodDescriptor);

                        if (!(containerTransaction != null && properAttribDefined(containerTransaction))) {
                            transactionAttribute  =
                                    containerTransaction.getTransactionAttribute();
                            addErrorDetails(result, compName);
                            result.failed(smh.getLocalString
                                    (getClass().getName() + ".failed",
                                            "Error: TransactionAttribute [ {0} ] for method [ {1} ] is not valid.",
                                            new Object[] {transactionAttribute, methodDescriptor.getName()}));

                        }
                    }
                }
            }
        }

        if(result.getStatus()!=Result.FAILED) {
            addGoodDetails(result, compName);
            result.passed(smh.getLocalString
                    (getClass().getName() + ".passed",
                            "TransactionAttributes are defined properly for the bean"));
        }
        return result;
    }
View Full Code Here

     *
     * @return <code>Result</code> the results for this assertion
     */

    public Result check(WebBundleDescriptor descriptor) {
        Result result = getInitializedResult();
        ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
        //This test is not applicable for application based on Servlet Spec 2.3
        String prefix = XpathPrefixResolver.fakeXPrefix;
        String query = prefix + ":" + "web-app/" + prefix + ":" + "session-config";
        int count = getNonRuntimeCountNodeSet(query);
       
        if ( count == 0 || count == -1) {
            addNaDetails(result, compName);
            result.notApplicable(smh.getLocalString
                    (getClass().getName() + ".notApplicable",
                    "Not Applicable: Servlet session-config element is not Specified."));
        } else if ( count  == 1 ) {
            addGoodDetails(result, compName);
            result.passed(smh.getLocalString
                    (getClass().getName() + ".passed" ,
                    "The session-config element is specified correctly"));
        } else if ( count > 1 ) {
            addErrorDetails(result, compName);
            result.failed(smh.getLocalString
                    (getClass().getName() + ".failed",
                    "The deployment descriptor instance contains multiple elements of session-config element"));
        }
        return result;
    }
View Full Code Here

TOP

Related Classes of com.sun.enterprise.tools.verifier.Result

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.