Search in sources :

Example 16 with EjbSessionDescriptor

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

the class SessionType method check.

/**
 * Session Bean State management test (stateful/stateless).
 * If the enterprise bean is a Session Bean, the Bean provider must use
 * the "session-type" element to declare whether the session bean
 * is stateful or stateless.
 *
 * @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();
    if (descriptor instanceof EjbSessionDescriptor) {
        String stateType = ((EjbSessionDescriptor) descriptor).getSessionType();
        if ((EjbSessionDescriptor.STATELESS.equals(stateType)) || (EjbSessionDescriptor.STATEFUL.equals(stateType))) {
            result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
            result.passed(smh.getLocalString(getClass().getName() + ".passed", "[ {0} ] is valid stateType within bean [ {1} ].", new Object[] { stateType, descriptor.getName() }));
        } else {
            result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
            result.failed(smh.getLocalString(getClass().getName() + ".failed", "Error: [ {0} ] is not valid stateType within bean [ {1} ].", new Object[] { stateType, descriptor.getName() }));
        }
        return result;
    } else {
        result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
        result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable", "[ {0} ] expected {1} bean, but called with {2} bean.", new Object[] { getClass(), "Session", "Entity" }));
        return result;
    }
}
Also used : EjbSessionDescriptor(com.sun.enterprise.deployment.EjbSessionDescriptor) ComponentNameConstructor(com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor) Result(com.sun.enterprise.tools.verifier.Result)

Example 17 with EjbSessionDescriptor

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

the class EjbHasLocalorRemoteorBothInterfaces method check.

/**
 * Bean interface type test.
 * The bean provider must provide either Local or Remote or Both interfaces
 *
 * @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();
    if (!(descriptor instanceof EjbSessionDescriptor) && !(descriptor instanceof EjbEntityDescriptor)) {
        addNaDetails(result, compName);
        result.notApplicable(smh.getLocalString("com.sun.enterprise.tools.verifier.tests.ejb.intf.InterfaceClassExist.notApplicable1", "Test apply only to session or entity beans."));
        return result;
    }
    if ((descriptor.getRemoteClassName() == null || "".equals(descriptor.getRemoteClassName())) && (descriptor.getLocalClassName() == null || "".equals(descriptor.getLocalClassName()))) {
        if (implementsEndpoints(descriptor)) {
            addNaDetails(result, compName);
            result.notApplicable(smh.getLocalString("com.sun.enterprise.tools.verifier.tests.ejb.webservice.notapp", "Not Applicable because, EJB [ {0} ] implements a Service Endpoint Interface.", new Object[] { compName.toString() }));
            return result;
        } else {
            addErrorDetails(result, compName);
            result.failed(smh.getLocalString(getClass().getName() + ".failed", "Ejb [ {0} ] does not have local or remote interfaces", new Object[] { descriptor.getEjbClassName() }));
            return result;
        }
    } else {
        addGoodDetails(result, compName);
        result.passed(smh.getLocalString(getClass().getName() + ".passed", "Ejb [ {0} ] does have valid local and/or remote interfaces", new Object[] { descriptor.getEjbClassName() }));
        return result;
    }
}
Also used : EjbEntityDescriptor(org.glassfish.ejb.deployment.descriptor.EjbEntityDescriptor) EjbSessionDescriptor(com.sun.enterprise.deployment.EjbSessionDescriptor) ComponentNameConstructor(com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor) Result(com.sun.enterprise.tools.verifier.Result)

Example 18 with EjbSessionDescriptor

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

the class EjbBeanType method check.

/**
 * Bean Type Test.
 * The bean provider must use the appropriate session or entity element
 * to declare the bean type.
 *
 * @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();
    if ((descriptor instanceof EjbSessionDescriptor) || (descriptor instanceof EjbEntityDescriptor)) {
        try {
            Class c = Class.forName(descriptor.getEjbClassName(), false, getVerifierContext().getClassLoader());
            boolean validBean = false;
            // walk up the class tree (bug #4243606)
            do {
                Class[] interfaces = c.getInterfaces();
                for (int i = 0; i < interfaces.length; i++) {
                    logger.log(Level.FINE, getClass().getName() + ".debug1", new Object[] { interfaces[i].getName() });
                    if (interfaces[i].getName().equals("javax.ejb.EntityBean") && (descriptor instanceof EjbEntityDescriptor)) {
                        validBean = true;
                        result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                        result.passed(smh.getLocalString(getClass().getName() + ".passed", "[ {0} ] properly implements the {1}Bean interface.", new Object[] { descriptor.getEjbClassName(), "Entity" }));
                        break;
                    } else if (interfaces[i].getName().equals("javax.ejb.SessionBean") && descriptor instanceof EjbSessionDescriptor) {
                        validBean = true;
                        result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                        result.passed(smh.getLocalString(getClass().getName() + ".passed", "[ {0} ] properly implements the {1}Bean interface.", new Object[] { descriptor.getEjbClassName(), "Session" }));
                        break;
                    }
                }
            } while ((((c = c.getSuperclass()) != null) && (!validBean)));
            if (!validBean) {
                result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                result.failed(smh.getLocalString(getClass().getName() + ".failed", "Error: [ {0} ] is not a valid bean. The bean provider must use the appropriate {1} or {2} element to declare the bean type.", new Object[] { descriptor.getEjbClassName(), "session", "entity" }));
            }
        } catch (ClassNotFoundException e) {
            Verifier.debug(e);
            result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
            result.failed(smh.getLocalString(getClass().getName() + ".failedException", "Error: [ {0} ] class not found.", new Object[] { descriptor.getEjbClassName() }));
        }
        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 with a Session or Entity Bean.", new Object[] { getClass() }));
        return result;
    }
}
Also used : EjbEntityDescriptor(org.glassfish.ejb.deployment.descriptor.EjbEntityDescriptor) EjbSessionDescriptor(com.sun.enterprise.deployment.EjbSessionDescriptor) ComponentNameConstructor(com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor) Result(com.sun.enterprise.tools.verifier.Result)

Example 19 with EjbSessionDescriptor

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

the class EjbDescriptorImpl method getLocalBusinessInterfaces.

/**
 * Gets the local business interfaces of the EJB
 *
 * @return An iterator over the local business interfaces
 */
@Override
public Collection<BusinessInterfaceDescriptor<?>> getLocalBusinessInterfaces() {
    Set<BusinessInterfaceDescriptor<?>> localBusIntfs = new HashSet<BusinessInterfaceDescriptor<?>>();
    if (ejbDesc.getType().equals(EjbSessionDescriptor.TYPE)) {
        EjbSessionDescriptor sessionDesc = (EjbSessionDescriptor) ejbDesc;
        Set<String> localNames = sessionDesc.getLocalBusinessClassNames();
        // Include the no-interface Local view
        if (sessionDesc.isLocalBean()) {
            localNames.add(sessionDesc.getEjbClassName());
        }
        for (String local : localNames) {
            try {
                Class<?> localClass = sessionDesc.getEjbBundleDescriptor().getClassLoader().loadClass(local);
                @SuppressWarnings({ "rawtypes", "unchecked" }) BusinessInterfaceDescriptor<?> busIntfDesc = new BusinessInterfaceDescriptorImpl(localClass);
                localBusIntfs.add(busIntfDesc);
            } catch (ClassNotFoundException e) {
                throw new IllegalStateException(e);
            }
        }
    }
    return localBusIntfs;
}
Also used : BusinessInterfaceDescriptor(org.jboss.weld.ejb.spi.BusinessInterfaceDescriptor) EjbSessionDescriptor(com.sun.enterprise.deployment.EjbSessionDescriptor) HashSet(java.util.HashSet)

Example 20 with EjbSessionDescriptor

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

the class EjbDescriptorImpl method getRemoteBusinessInterfaces.

@Override
public Collection<BusinessInterfaceDescriptor<?>> getRemoteBusinessInterfaces() {
    Set<BusinessInterfaceDescriptor<?>> remoteBusIntfs = new HashSet<BusinessInterfaceDescriptor<?>>();
    if (ejbDesc.getType().equals(EjbSessionDescriptor.TYPE)) {
        EjbSessionDescriptor sessionDesc = (EjbSessionDescriptor) ejbDesc;
        Set<String> remoteNames = sessionDesc.getRemoteBusinessClassNames();
        for (String remote : remoteNames) {
            try {
                Class<?> remoteClass = sessionDesc.getEjbBundleDescriptor().getClassLoader().loadClass(remote);
                @SuppressWarnings({ "rawtypes", "unchecked" }) BusinessInterfaceDescriptor<?> busIntfDesc = new BusinessInterfaceDescriptorImpl(remoteClass);
                remoteBusIntfs.add(busIntfDesc);
            } catch (ClassNotFoundException e) {
                throw new IllegalStateException(e);
            }
        }
    }
    return remoteBusIntfs;
}
Also used : BusinessInterfaceDescriptor(org.jboss.weld.ejb.spi.BusinessInterfaceDescriptor) EjbSessionDescriptor(com.sun.enterprise.deployment.EjbSessionDescriptor) HashSet(java.util.HashSet)

Aggregations

EjbSessionDescriptor (com.sun.enterprise.deployment.EjbSessionDescriptor)21 Result (com.sun.enterprise.tools.verifier.Result)14 ComponentNameConstructor (com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor)14 EjbEntityDescriptor (org.glassfish.ejb.deployment.descriptor.EjbEntityDescriptor)12 Method (java.lang.reflect.Method)5 VerifierTestContext (com.sun.enterprise.tools.verifier.VerifierTestContext)4 HashSet (java.util.HashSet)3 EjbDescriptor (com.sun.enterprise.deployment.EjbDescriptor)2 EjbMessageBeanDescriptor (com.sun.enterprise.deployment.EjbMessageBeanDescriptor)2 DeploymentDescriptorNode (com.sun.enterprise.deployment.node.DeploymentDescriptorNode)2 BusinessInterfaceDescriptor (org.jboss.weld.ejb.spi.BusinessInterfaceDescriptor)2 Node (org.w3c.dom.Node)2 EjbIORConfigurationDescriptor (com.sun.enterprise.deployment.EjbIORConfigurationDescriptor)1 InjectionTarget (com.sun.enterprise.deployment.InjectionTarget)1 MethodDescriptor (com.sun.enterprise.deployment.MethodDescriptor)1 RunAsIdentityDescriptor (com.sun.enterprise.deployment.RunAsIdentityDescriptor)1 XMLElement (com.sun.enterprise.deployment.node.XMLElement)1 EjbRefNode (com.sun.enterprise.deployment.node.runtime.EjbRefNode)1 MessageDestinationRefNode (com.sun.enterprise.deployment.node.runtime.MessageDestinationRefNode)1 ResourceEnvRefNode (com.sun.enterprise.deployment.node.runtime.ResourceEnvRefNode)1