Search in sources :

Example 11 with EjbReferenceDescriptor

use of com.sun.enterprise.deployment.EjbReferenceDescriptor in project Payara by payara.

the class EjbRefTypeElement method check.

// Logger to log messages
/**
 * The ejb-ref-type element must be one of the following:
 *   Entity
 *   Session
 *
 * @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();
    boolean failed = false;
    // Session
    if (!descriptor.getEjbReferenceDescriptors().isEmpty()) {
        for (Iterator itr = descriptor.getEjbReferenceDescriptors().iterator(); itr.hasNext(); ) {
            EjbReferenceDescriptor nextEjbReference = (EjbReferenceDescriptor) itr.next();
            // Need to use XPath, because if DOL sees an inconsistent
            // ref-type, it gives a warning and changes the type
            // String ejbRefTypeStr = nextEjbReference.getType();
            String refStr = (nextEjbReference.isLocal()) ? "ejb-local-ref" : "ejb-ref";
            String beanType = (descriptor.getType()).toLowerCase();
            String xpathQuery = null;
            if (getVerifierContext().getDocument().getDoctype() != null) {
                xpathQuery = "/ejb-jar/enterprise-beans/" + beanType + "[ejb-name=\"" + descriptor.getName() + "\"]/" + refStr + "[ejb-ref-name=\"" + nextEjbReference.getName() + "\"]/ejb-ref-type";
            } else {
                String prefix = XpathPrefixResolver.fakeXPrefix;
                xpathQuery = prefix + ":" + "ejb-jar/" + prefix + ":" + "enterprise-beans/" + prefix + ":" + beanType + "[" + prefix + ":ejb-name=\"" + descriptor.getName() + "\"]/" + prefix + ":" + refStr + "[" + prefix + ":ejb-ref-name=\"" + nextEjbReference.getName() + "\"]/" + prefix + ":" + "ejb-ref-type";
            }
            String ejbRefTypeStr = getXPathValueForNonRuntime(xpathQuery);
            EjbDescriptor rdesc = (EjbDescriptor) nextEjbReference.getEjbDescriptor();
            // XPath queries seem to fail for XSD Descriptors
            if (ejbRefTypeStr == null) {
                ejbRefTypeStr = nextEjbReference.getType();
            }
            if (!((ejbRefTypeStr.equals(EjbSessionDescriptor.TYPE)) || (ejbRefTypeStr.equals(EjbEntityDescriptor.TYPE)))) {
                result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                result.failed(smh.getLocalString(getClass().getName() + ".failed", "Error: ejb-ref-type [ {0} ] within \n bean [ {1} ] is not valid.  \n Must be [ {2} ] or [ {3} ]", new Object[] { ejbRefTypeStr, descriptor.getName(), EjbEntityDescriptor.TYPE, EjbSessionDescriptor.TYPE }));
                failed = true;
            } else if (rdesc != null) {
                String actualRefType = rdesc.getType();
                if (!ejbRefTypeStr.equals(actualRefType)) {
                    result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                    result.failed(smh.getLocalString(getClass().getName() + ".failed2", "Error: ejb-ref-type [ {0} ] was specifed for ejb-ref [ {1} ], within bean [ {2} ], when it should have been [ {3} ].", new Object[] { ejbRefTypeStr, nextEjbReference.getName(), descriptor.getName(), actualRefType }));
                    failed = true;
                }
            }
        }
    } else {
        result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
        result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable", "There are no ejb references to other beans within this bean [ {0} ]", new Object[] { descriptor.getName() }));
        return result;
    }
    if (failed) {
        result.setStatus(Result.FAILED);
    } else {
        result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
        result.passed(smh.getLocalString(getClass().getName() + ".passed", "All ejb-ref-type elements are valid.  They are all [ {0} ] or [ {1} ] within this bean [ {2} ]", new Object[] { EjbEntityDescriptor.TYPE, EjbSessionDescriptor.TYPE, descriptor.getName() }));
    }
    return result;
}
Also used : EjbReferenceDescriptor(com.sun.enterprise.deployment.EjbReferenceDescriptor) Iterator(java.util.Iterator) ComponentNameConstructor(com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor) EjbDescriptor(org.glassfish.ejb.deployment.descriptor.EjbDescriptor) Result(com.sun.enterprise.tools.verifier.Result)

Example 12 with EjbReferenceDescriptor

use of com.sun.enterprise.deployment.EjbReferenceDescriptor in project Payara by payara.

the class EjbReferencesElement method check.

// Logger to log messages
/**
 * The Bean Provider must declare all enterprise bean's references to the homes
 * of other enterprise beans as specified in section 14.3.2 of the Moscone spec.
 * Check for one within the same jar file, can't check outside of jar file.
 * Load/locate & check other bean's home/remote/bean, ensure they match with
 * what the linking bean says they should be; check for pair of referencing and
 * referenced beans exist.
 *
 * @param descriptor the Enterprise Java Bean deployment descriptor
 *
 * @return <code>Result</code> the results for this assertion
 */
public Result check(EjbDescriptor descriptor) {
    result = getInitializedResult();
    compName = getVerifierContext().getComponentNameConstructor();
    if ((descriptor instanceof EjbEntityDescriptor) || (descriptor instanceof EjbSessionDescriptor)) {
        // RULE: References to other beans must be declared in the form of
        // references to other beans homes as specified in section
        // 14.3.2 of the Moscone spec.
        // check for one bean within the same jar file; can't check outside of
        // jar file.  need to load/locate and check other beans remote, home, bean
        // match with the linking bean says they should be. i.e. check for pair
        // of referencing & referenced bean exist, using reflection API
        EjbReferenceDescriptor ejbReference;
        // EjbAbstractDescriptor ejbDescriptor;
        try {
            String fName = null;
            Set references = descriptor.getEjbReferenceDescriptors();
            if (references == null) {
                logger.log(Level.INFO, getClass().getName() + ".refnull");
                return result;
            }
            Iterator iterator = references.iterator();
            if (iterator.hasNext()) {
                boolean oneFailed = false;
                // boolean foundBeanClassName = false;
                // boolean foundHomeClassName = false;
                // boolean foundRemoteClassName = false;
                // File fileName = Verifier.getArchiveFile(descriptor.getEjbBundleDescriptor().getModuleDescriptor().getArchiveUri());
                // if (fileName!=null){
                // fName = fileName.getName();
                // }else{
                fName = descriptor.getEjbBundleDescriptor().getModuleDescriptor().getArchiveUri();
                // }
                while (iterator.hasNext()) {
                    ejbReference = (EjbReferenceDescriptor) iterator.next();
                    if (ejbReference.isLinked()) {
                        // reset
                        if (ejbReference.getEjbHomeInterface() != null && ejbReference.getEjbInterface() != null) {
                            oneFailed = commonToBothInterfaces(ejbReference.getEjbHomeInterface(), ejbReference.getEjbInterface(), fName);
                        }
                    } else {
                        // (e.g. external references)
                        result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                        result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable2", "Not Applicable: [ {0} ] must be external reference to bean outside of [ {1} ].", new Object[] { ejbReference.getName(), fName }));
                    }
                }
                if (oneFailed) {
                    result.setStatus(result.FAILED);
                } else {
                    result.setStatus(result.PASSED);
                }
            } else {
                result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable1", "There are no ejb references to other beans within this bean [ {0} ]", new Object[] { descriptor.getName() }));
            }
            return result;
        } catch (Exception e) {
            result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
            result.failed(smh.getLocalString(getClass().getName() + ".failedRef", "Exception occurred : [ {0} ]", new Object[] { e.getMessage() }));
            return result;
        }
    } else {
        result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
        result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable", "[ {0} ] not called \n with a Session or Entity bean.", new Object[] { getClass() }));
        return result;
    }
}
Also used : EjbEntityDescriptor(org.glassfish.ejb.deployment.descriptor.EjbEntityDescriptor) Set(java.util.Set) EjbReferenceDescriptor(com.sun.enterprise.deployment.EjbReferenceDescriptor) Iterator(java.util.Iterator) EjbSessionDescriptor(org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor)

Example 13 with EjbReferenceDescriptor

use of com.sun.enterprise.deployment.EjbReferenceDescriptor in project Payara by payara.

the class EjbLocalReferenceNode method getDescriptor.

@Override
public EjbReference getDescriptor() {
    if (descriptor == null) {
        descriptor = new EjbReferenceDescriptor();
        descriptor.setLocal(true);
    }
    return descriptor;
}
Also used : EjbReferenceDescriptor(com.sun.enterprise.deployment.EjbReferenceDescriptor)

Aggregations

EjbReferenceDescriptor (com.sun.enterprise.deployment.EjbReferenceDescriptor)13 Iterator (java.util.Iterator)7 Result (com.sun.enterprise.tools.verifier.Result)6 ComponentNameConstructor (com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor)6 Set (java.util.Set)3 EjbDescriptor (org.glassfish.ejb.deployment.descriptor.EjbDescriptor)2 Application (com.sun.enterprise.deployment.Application)1 EjbBundleDescriptor (com.sun.enterprise.deployment.EjbBundleDescriptor)1 EjbDescriptor (com.sun.enterprise.deployment.EjbDescriptor)1 InjectionTarget (com.sun.enterprise.deployment.InjectionTarget)1 WebBundleDescriptor (com.sun.enterprise.deployment.WebBundleDescriptor)1 EjbReference (com.sun.enterprise.deployment.types.EjbReference)1 Field (java.lang.reflect.Field)1 Method (java.lang.reflect.Method)1 AnnotationProcessorException (org.glassfish.apf.AnnotationProcessorException)1 EjbBundleDescriptorImpl (org.glassfish.ejb.deployment.descriptor.EjbBundleDescriptorImpl)1 EjbEntityDescriptor (org.glassfish.ejb.deployment.descriptor.EjbEntityDescriptor)1 EjbSessionDescriptor (org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor)1