Search in sources :

Example 1 with GenericAnnotationDetector

use of org.glassfish.deployment.common.GenericAnnotationDetector in project Payara by payara.

the class RarDetector method handles.

/**
 * {@inheritDoc}
 */
@Override
public boolean handles(ReadableArchive archive) throws IOException {
    boolean handles = false;
    try {
        if (Util.getURIName(archive.getURI()).endsWith(RAR_EXTENSION)) {
            return true;
        }
        handles = archive.exists(RA_XML);
    } catch (IOException ioe) {
    // ignore
    }
    if (!handles) {
        GenericAnnotationDetector detector = new GenericAnnotationDetector(connectorAnnotations);
        handles = detector.hasAnnotationInArchive(archive);
    }
    return handles;
}
Also used : GenericAnnotationDetector(org.glassfish.deployment.common.GenericAnnotationDetector) IOException(java.io.IOException)

Example 2 with GenericAnnotationDetector

use of org.glassfish.deployment.common.GenericAnnotationDetector 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) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) GenericAnnotationDetector(org.glassfish.deployment.common.GenericAnnotationDetector) ReadableArchive(org.glassfish.api.deployment.archive.ReadableArchive)

Example 3 with GenericAnnotationDetector

use of org.glassfish.deployment.common.GenericAnnotationDetector in project Payara by payara.

the class AppClientScanner method doProcess.

/**
 * This scanner will scan the given main class for annotation processing.
 * The archiveFile and libJarFiles correspond to classpath.
 * @param archiveFile
 * @param desc
 * @param classLoader
 */
private void doProcess(ReadableArchive archive, ApplicationClientDescriptor desc, ClassLoader classLoader) throws IOException {
    if (AnnotationUtils.getLogger().isLoggable(Level.FINE)) {
        AnnotationUtils.getLogger().fine("archiveFile is " + archive.getURI().toASCIIString());
        AnnotationUtils.getLogger().fine("classLoader is " + classLoader);
    }
    // always add main class
    String mainClassName = desc.getMainClassName();
    addScanClassName(mainClassName);
    // add callback handle if it exist in appclient-client.xml
    String callbackHandler = desc.getCallbackHandler();
    if (callbackHandler != null && !callbackHandler.trim().equals("")) {
        addScanClassName(desc.getCallbackHandler());
    }
    GenericAnnotationDetector detector = new GenericAnnotationDetector(managedBeanAnnotations);
    if (detector.hasAnnotationInArchive(archive)) {
        if (archive instanceof FileArchive) {
            addScanDirectory(new File(archive.getURI()));
        } else if (archive instanceof InputJarArchive) {
            /*
                 * This is during deployment, so use the faster code path using
                 * the File object.
                 */
            URI uriToAdd = archive.getURI();
            addScanJar(scanJar(uriToAdd));
        } else if (archive instanceof MultiReadableArchive) {
            /*
                 * During app client launches, scan the developer's archive
                 * which is in slot #1, not the facade archive which is in
                 * slot #0.  Also, use URIs instead of File objects because
                 * during Java Web Start launches we don't have access to
                 * File objects.
                 */
            addScanURI(scanURI(((MultiReadableArchive) archive).getURI(1)));
        }
    }
    this.classLoader = classLoader;
    // = archive;
    this.archiveFile = null;
}
Also used : InputJarArchive(com.sun.enterprise.deployment.deploy.shared.InputJarArchive) GenericAnnotationDetector(org.glassfish.deployment.common.GenericAnnotationDetector) FileArchive(com.sun.enterprise.deploy.shared.FileArchive) MultiReadableArchive(com.sun.enterprise.deployment.deploy.shared.MultiReadableArchive) File(java.io.File) URI(java.net.URI)

Aggregations

GenericAnnotationDetector (org.glassfish.deployment.common.GenericAnnotationDetector)3 FileArchive (com.sun.enterprise.deploy.shared.FileArchive)1 EjbBundleDescriptor (com.sun.enterprise.deployment.EjbBundleDescriptor)1 InputJarArchive (com.sun.enterprise.deployment.deploy.shared.InputJarArchive)1 MultiReadableArchive (com.sun.enterprise.deployment.deploy.shared.MultiReadableArchive)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 URI (java.net.URI)1 ReadableArchive (org.glassfish.api.deployment.archive.ReadableArchive)1 ModuleDescriptor (org.glassfish.deployment.common.ModuleDescriptor)1 EjbDeploymentDescriptorFile (org.glassfish.ejb.deployment.io.EjbDeploymentDescriptorFile)1