Search in sources :

Example 1 with EjbDeploymentDescriptorFile

use of org.glassfish.ejb.deployment.io.EjbDeploymentDescriptorFile in project Payara by payara.

the class EJBContainerProviderImpl method getRequestedEJBModuleOrLibrary.

/**
 * @returns DeploymentElement if this file represents an EJB module or a library.
 * Returns null if it's an EJB module which name is not present in the list of requested
 * module names.
 */
private DeploymentElement getRequestedEJBModuleOrLibrary(File file, Map<String, Boolean> moduleNames) throws Exception {
    DeploymentElement result = null;
    String fileName = file.getName();
    if (_logger.isLoggable(Level.FINE)) {
        _logger.fine("... Testing ... " + fileName);
    }
    ReadableArchive archive = null;
    InputStream is = null;
    try {
        boolean isEJBModule = false;
        String moduleName = DeploymentUtils.getDefaultEEName(fileName);
        archive = archiveFactory.openArchive(file);
        is = getDeploymentDescriptor(archive);
        if (is != null) {
            isEJBModule = true;
            EjbDeploymentDescriptorFile eddf = new EjbDeploymentDescriptorFile();
            eddf.setXMLValidation(false);
            EjbBundleDescriptor bundleDesc = (EjbBundleDescriptor) eddf.read(is);
            ModuleDescriptor moduleDesc = bundleDesc.getModuleDescriptor();
            moduleDesc.setArchiveUri(fileName);
            moduleName = moduleDesc.getModuleName();
        } else {
            GenericAnnotationDetector detector = new GenericAnnotationDetector(ejbAnnotations);
            isEJBModule = detector.hasAnnotationInArchive(archive);
        }
        if (_logger.isLoggable(Level.FINE)) {
            _logger.fine("... is EJB module: " + isEJBModule);
            if (isEJBModule) {
                _logger.fine("... is Requested EJB module [" + moduleName + "]: " + (moduleNames.isEmpty() || moduleNames.containsKey(moduleName)));
            }
        }
        if (!isEJBModule || moduleNames.isEmpty()) {
            result = new DeploymentElement(file, isEJBModule, moduleName);
        } else if (moduleNames.containsKey(moduleName) && !moduleNames.get(moduleName)) {
            // Is a requested EJB module and was not found already
            result = new DeploymentElement(file, isEJBModule, moduleName);
            moduleNames.put(moduleName, true);
        }
        return result;
    } finally {
        if (archive != null)
            archive.close();
        if (is != null)
            is.close();
    }
}
Also used : ModuleDescriptor(org.glassfish.deployment.common.ModuleDescriptor) EjbDeploymentDescriptorFile(org.glassfish.ejb.deployment.io.EjbDeploymentDescriptorFile) EjbBundleDescriptor(com.sun.enterprise.deployment.EjbBundleDescriptor) GenericAnnotationDetector(org.glassfish.deployment.common.GenericAnnotationDetector) ReadableArchive(org.glassfish.api.deployment.archive.ReadableArchive)

Example 2 with EjbDeploymentDescriptorFile

use of org.glassfish.ejb.deployment.io.EjbDeploymentDescriptorFile in project Payara by payara.

the class EjbCheckMgrImpl method check.

/**
 * Check Ejb for spec. conformance
 *
 * @param descriptor Ejb descriptor
 */
public void check(Descriptor descriptor) throws Exception {
    // run persistence tests first.
    checkPersistenceUnits(EjbBundleDescriptorImpl.class.cast(descriptor));
    // an EjbBundleDescriptor can have an WebServicesDescriptor
    checkWebServices(descriptor);
    // an EjbBundleDescriptor can have  WebService References
    checkWebServicesClient(descriptor);
    if (verifierFrameworkContext.isPartition() && !verifierFrameworkContext.isEjb())
        return;
    EjbBundleDescriptorImpl bundleDescriptor = (EjbBundleDescriptorImpl) descriptor;
    setDescClassLoader(bundleDescriptor);
    // an ejb-ref is unresolved etc.
    try {
        EjbBundleValidator validator = new EjbBundleValidator();
        validator.accept(bundleDescriptor);
    } catch (Exception e) {
    }
    // initialize JDOC if bundle has CMP's
    if (bundleDescriptor.containsCMPEntity()) {
        try {
            // See bug #6274161. We now pass an additional boolean
            // to indicate whether we are in portable or AS mode.
            jdc.init(bundleDescriptor, context.getClassLoader(), getAbstractArchiveUri(bundleDescriptor), verifierFrameworkContext.isPortabilityMode());
        } catch (Throwable ex) {
            context.setJDOException(ex);
        }
    }
    // set the JDO Codegenerator into the context
    context.setJDOCodeGenerator(jdc);
    // run the ParseDD test
    if (bundleDescriptor.getSpecVersion().compareTo("2.1") < 0) {
        // NOI18N
        EjbDeploymentDescriptorFile ddf = new EjbDeploymentDescriptorFile();
        File file = new File(getAbstractArchiveUri(bundleDescriptor), ddf.getDeploymentDescriptorPath());
        FileInputStream is = new FileInputStream(file);
        try {
            if (is != null) {
                Result result = new ParseDD().validateEJBDescriptor(is);
                result.setComponentName(new File(bundleDescriptor.getModuleDescriptor().getArchiveUri()).getName());
                setModuleName(result);
                verifierFrameworkContext.getResultManager().add(result);
            }
        } finally {
            try {
                if (is != null) {
                    is.close();
                }
            } catch (Exception e) {
            }
        }
    }
    for (Iterator itr = bundleDescriptor.getEjbs().iterator(); itr.hasNext(); ) {
        EjbDescriptor ejbDescriptor = (EjbDescriptor) itr.next();
        super.check(ejbDescriptor);
    }
    if (bundleDescriptor.containsCMPEntity() && context.getJDOException() == null) {
        jdc.cleanup();
        context.setJDOCodeGenerator(null);
    }
}
Also used : EjbDeploymentDescriptorFile(org.glassfish.ejb.deployment.io.EjbDeploymentDescriptorFile) ParseDD(com.sun.enterprise.tools.verifier.tests.dd.ParseDD) Iterator(java.util.Iterator) EjbBundleValidator(org.glassfish.ejb.deployment.util.EjbBundleValidator) EjbDeploymentDescriptorFile(org.glassfish.ejb.deployment.io.EjbDeploymentDescriptorFile) File(java.io.File) FileInputStream(java.io.FileInputStream) EjbDescriptor(org.glassfish.ejb.deployment.descriptor.EjbDescriptor) EjbBundleDescriptorImpl(org.glassfish.ejb.deployment.descriptor.EjbBundleDescriptorImpl) Result(com.sun.enterprise.tools.verifier.Result)

Aggregations

EjbDeploymentDescriptorFile (org.glassfish.ejb.deployment.io.EjbDeploymentDescriptorFile)2 EjbBundleDescriptor (com.sun.enterprise.deployment.EjbBundleDescriptor)1 Result (com.sun.enterprise.tools.verifier.Result)1 ParseDD (com.sun.enterprise.tools.verifier.tests.dd.ParseDD)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 Iterator (java.util.Iterator)1 ReadableArchive (org.glassfish.api.deployment.archive.ReadableArchive)1 GenericAnnotationDetector (org.glassfish.deployment.common.GenericAnnotationDetector)1 ModuleDescriptor (org.glassfish.deployment.common.ModuleDescriptor)1 EjbBundleDescriptorImpl (org.glassfish.ejb.deployment.descriptor.EjbBundleDescriptorImpl)1 EjbDescriptor (org.glassfish.ejb.deployment.descriptor.EjbDescriptor)1 EjbBundleValidator (org.glassfish.ejb.deployment.util.EjbBundleValidator)1