Search in sources :

Example 1 with JDOCodeGenerator

use of com.sun.jdo.spi.persistence.support.ejb.ejbc.JDOCodeGenerator in project Payara by payara.

the class ASCmpMappingTest method check.

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 initializing JDOCodeGenerator. Please check your descriptors and mapping files for consistency ", 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", "The mappings for the cmp beans (if any) are correct."));
            } else {
                // collect all the cmpmapping related 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 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", "The mappings for the cmp beans (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;
}
Also used : IASEjbCMPEntityDescriptor(org.glassfish.ejb.deployment.descriptor.IASEjbCMPEntityDescriptor) JDOCodeGenerator(com.sun.jdo.spi.persistence.support.ejb.ejbc.JDOCodeGenerator) Iterator(java.util.Iterator) EJBQLException(com.sun.jdo.spi.persistence.support.ejb.ejbqlc.EJBQLException) Collection(java.util.Collection) ComponentNameConstructor(com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor) EJBQLException(com.sun.jdo.spi.persistence.support.ejb.ejbqlc.EJBQLException) Result(com.sun.enterprise.tools.verifier.Result)

Example 2 with JDOCodeGenerator

use of com.sun.jdo.spi.persistence.support.ejb.ejbc.JDOCodeGenerator in project Payara by payara.

the class CMPDeployerImpl method deploy.

/**
 * Generates the concrete impls for all CMPs in the application.
 *
 * @throws DeploymentException if this exception was thrown while generating concrete impls
 */
public void deploy(DeploymentContext ctx) throws DeploymentException {
    // deployment descriptor object representation for the archive
    Application application = null;
    // deployment descriptor object representation for each module
    EjbBundleDescriptorImpl bundle = null;
    // ejb name
    String beanName = null;
    // GeneratorException message if any
    StringBuffer generatorExceptionMsg = null;
    try {
        CMPGenerator gen = new JDOCodeGenerator();
        // stubs dir for the current deployment (generated/ejb)
        // NOI18N
        File stubsDir = ctx.getScratchDir("ejb");
        application = ctx.getModuleMetaData(Application.class);
        if (_logger.isLoggable(Logger.FINE)) {
            // NOI18N
            _logger.fine(// NOI18N
            "cmpc.processing_cmp", application.getRegistrationName());
        }
        List<File> cmpFiles = new ArrayList<File>();
        final ClassLoader jcl = application.getClassLoader();
        bundle = ctx.getModuleMetaData(EjbBundleDescriptorImpl.class);
        // This gives the dir where application is exploded
        String archiveUri = ctx.getSource().getURI().getSchemeSpecificPart();
        if (_logger.isLoggable(Logger.FINE)) {
            _logger.fine(// NOI18N
            "[CMPC] Module Dir name is " + archiveUri);
        }
        // xml dir for the current deployment (generated/xml)
        String generatedXmlsPath = ctx.getScratchDir("xml").getCanonicalPath();
        if (_logger.isLoggable(Logger.FINE)) {
            _logger.fine(// NOI18N
            "[CMPC] Generated XML Dir name is " + generatedXmlsPath);
        }
        try {
            long start = System.currentTimeMillis();
            gen.init(bundle, ctx, archiveUri, generatedXmlsPath);
            Iterator ejbs = bundle.getEjbs().iterator();
            while (ejbs.hasNext()) {
                EjbDescriptor desc = (EjbDescriptor) ejbs.next();
                beanName = desc.getName();
                if (_logger.isLoggable(Logger.FINE)) {
                    _logger.fine(// NOI18N
                    "[CMPC] Ejb Class Name: " + desc.getEjbClassName());
                }
                if (desc instanceof IASEjbCMPEntityDescriptor) {
                    // generate concrete CMP class implementation
                    IASEjbCMPEntityDescriptor entd = (IASEjbCMPEntityDescriptor) desc;
                    if (_logger.isLoggable(Logger.FINE)) {
                        _logger.fine(// NOI18N
                        "[CMPC] Home Object Impl name  is " + entd.getLocalHomeImplClassName());
                    }
                    // The classloader needs to be set else we fail down the road.
                    ClassLoader ocl = entd.getClassLoader();
                    entd.setClassLoader(jcl);
                    try {
                        gen.generate(entd, stubsDir, stubsDir);
                    } catch (GeneratorException e) {
                        String msg = e.getMessage();
                        _logger.warning(msg);
                        generatorExceptionMsg = addGeneratorExceptionMessage(msg, generatorExceptionMsg);
                    } finally {
                        entd.setClassLoader(ocl);
                    }
                /* WARNING: IASRI 4683195
                     * JDO Code failed when there was a relationship involved
                     * because it depends upon the orginal ejbclasname and hence
                     * this code is shifted to just before the Remote Impl is
                     * generated.Remote/Home Impl generation depends upon this
                     * value
                     */
                }
            }
            // end while ejbs.hasNext()
            beanName = null;
            cmpFiles.addAll(gen.cleanup());
            long end = System.currentTimeMillis();
            _logger.fine("CMP Generation: " + (end - start) + " msec");
        } catch (GeneratorException e) {
            String msg = e.getMessage();
            _logger.warning(msg);
            generatorExceptionMsg = addGeneratorExceptionMessage(msg, generatorExceptionMsg);
        }
        // Used in exception processing
        bundle = null;
        // Compile the generated classes
        if (generatorExceptionMsg == null) {
            long start = System.currentTimeMillis();
            compileClasses(ctx, cmpFiles, stubsDir);
            long end = System.currentTimeMillis();
            _logger.fine("Java Compilation: " + (end - start) + " msec");
            // Do Java2DB if needed
            start = System.currentTimeMillis();
            CMPProcessor processor = new CMPProcessor(ctx);
            processor.process();
            end = System.currentTimeMillis();
            _logger.fine("Java2DB processing: " + (end - start) + " msec");
            _logger.fine("cmpc.done_processing_cmp", application.getRegistrationName());
        }
    } catch (GeneratorException e) {
        _logger.warning(e.getMessage());
        throw new DeploymentException(e);
    } catch (Throwable e) {
        String eType = e.getClass().getName();
        String appName = application.getRegistrationName();
        String exMsg = e.getMessage();
        String msg = null;
        if (bundle == null) {
            // Application or compilation error
            msg = I18NHelper.getMessage(messages, "cmpc.cmp_app_error", eType, appName, exMsg);
        } else {
            String bundleName = bundle.getModuleDescriptor().getArchiveUri();
            if (beanName == null) {
                // Module processing error
                msg = I18NHelper.getMessage(messages, "cmpc.cmp_module_error", new Object[] { eType, appName, bundleName, exMsg });
            } else {
                // CMP bean generation error
                msg = I18NHelper.getMessage(messages, "cmpc.cmp_bean_error", new Object[] { eType, beanName, appName, bundleName, exMsg });
            }
        }
        _logger.log(Logger.SEVERE, msg, e);
        throw new DeploymentException(msg);
    }
    if (generatorExceptionMsg != null) {
        // We already logged each separate part.
        throw new DeploymentException(generatorExceptionMsg.toString());
    }
}
Also used : JDOCodeGenerator(com.sun.jdo.spi.persistence.support.ejb.ejbc.JDOCodeGenerator) CMPProcessor(com.sun.jdo.spi.persistence.support.ejb.ejbc.CMPProcessor) ArrayList(java.util.ArrayList) EjbDescriptor(org.glassfish.ejb.deployment.descriptor.EjbDescriptor) IASEjbCMPEntityDescriptor(org.glassfish.ejb.deployment.descriptor.IASEjbCMPEntityDescriptor) Iterator(java.util.Iterator) DeploymentException(org.glassfish.deployment.common.DeploymentException) Application(com.sun.enterprise.deployment.Application) File(java.io.File) EjbBundleDescriptorImpl(org.glassfish.ejb.deployment.descriptor.EjbBundleDescriptorImpl)

Example 3 with JDOCodeGenerator

use of com.sun.jdo.spi.persistence.support.ejb.ejbc.JDOCodeGenerator in project Payara by payara.

the class EjbQLFromCmpEntityDescriptor method check.

/**
 * Implements the check on EJB QL's syntax and semantics.
 *
 * @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;
}
Also used : IASEjbCMPEntityDescriptor(org.glassfish.ejb.deployment.descriptor.IASEjbCMPEntityDescriptor) JDOCodeGenerator(com.sun.jdo.spi.persistence.support.ejb.ejbc.JDOCodeGenerator) Iterator(java.util.Iterator) EJBQLException(com.sun.jdo.spi.persistence.support.ejb.ejbqlc.EJBQLException) Collection(java.util.Collection) ComponentNameConstructor(com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor) EJBQLException(com.sun.jdo.spi.persistence.support.ejb.ejbqlc.EJBQLException) Result(com.sun.enterprise.tools.verifier.Result)

Aggregations

JDOCodeGenerator (com.sun.jdo.spi.persistence.support.ejb.ejbc.JDOCodeGenerator)3 Iterator (java.util.Iterator)3 IASEjbCMPEntityDescriptor (org.glassfish.ejb.deployment.descriptor.IASEjbCMPEntityDescriptor)3 Result (com.sun.enterprise.tools.verifier.Result)2 ComponentNameConstructor (com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor)2 EJBQLException (com.sun.jdo.spi.persistence.support.ejb.ejbqlc.EJBQLException)2 Collection (java.util.Collection)2 Application (com.sun.enterprise.deployment.Application)1 CMPProcessor (com.sun.jdo.spi.persistence.support.ejb.ejbc.CMPProcessor)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1 DeploymentException (org.glassfish.deployment.common.DeploymentException)1 EjbBundleDescriptorImpl (org.glassfish.ejb.deployment.descriptor.EjbBundleDescriptorImpl)1 EjbDescriptor (org.glassfish.ejb.deployment.descriptor.EjbDescriptor)1