FileDocCategorySizeDatePackage
EjbNameUnique.javaAPI DocGlassfish v2 API4355Fri May 04 22:33:32 BST 2007com.sun.enterprise.tools.verifier.tests.ejb

EjbNameUnique

public class EjbNameUnique extends EjbTest implements EjbCheck
The ejb-name must be unique amoung the names of the enterprise beans within the same ejb-jar file.

Fields Summary
Constructors Summary
Methods Summary
public com.sun.enterprise.tools.verifier.Resultcheck(com.sun.enterprise.deployment.EjbDescriptor descriptor)
The ejb-name must be unique amoung the names of the enterprise beans within the same ejb-jar file.

param
descriptor the Enterprise Java Bean deployment descriptor
return
Result the results for this assertion


        Result result = getInitializedResult();
        String ejbName = descriptor.getName();
        ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();

        // initialize needed by ejb loop
        int found = 0;

        // The ejb-name must be unique amoung the names of the enterprise beans
        // within the same ejb-jar file.
        // i.e. need to loop through all ejb's within this jar and get their
        // respective ejbName's, then do a string compare and make sure their are
        // no duplicates.
        for (Iterator itr =descriptor.getEjbBundleDescriptor().getEjbs().iterator();
             itr.hasNext();) {
            EjbDescriptor ejbDescriptor = (EjbDescriptor) itr.next();
            if (ejbDescriptor.getName().equals(ejbName)) {
                found++;
                if (found > 1) {
                    addErrorDetails(result, compName);
                    result.failed(smh.getLocalString
                            (getClass().getName() + ".failed",
                            "Error: [ {0} ] has found [ {1} ] duplicate ejb name(s) within the same jar.",
                            new Object[] {ejbName, new Integer((found - 1))}));
                }
            }
        }
        
        if (result.getStatus() != Result.FAILED) {
            addGoodDetails(result, compName);
            result.passed(smh.getLocalString
                    (getClass().getName() + ".passed",
                    "Valid: [ {0} ] was found once within jar, ejb-name is unique.",
                    new Object[] {ejbName}));
        }
        return result;