Search in sources :

Example 1 with Parser

use of org.glassfish.hk2.classmodel.reflect.Parser in project Payara by payara.

the class Archivist method processAnnotations.

/**
 * Process annotations in a bundle descriptor, the annoation processing
 * is dependent on the type of descriptor being passed.
 */
protected ProcessingResult processAnnotations(RootDeploymentDescriptor bundleDesc, ModuleScanner scanner, ReadableArchive archive) throws AnnotationProcessorException, IOException {
    if (scanner == null) {
        return null;
    }
    AnnotatedElementHandler aeHandler = AnnotatedElementHandlerFactory.createAnnotatedElementHandler(bundleDesc);
    if (aeHandler == null) {
        return null;
    }
    Parser parser = null;
    if (archive.getParentArchive() != null) {
        parser = archive.getParentArchive().getExtraData(Parser.class);
    } else {
        parser = archive.getExtraData(Parser.class);
    }
    scanner.process(archive, bundleDesc, classLoader, parser);
    if (!scanner.getElements().isEmpty()) {
        if (((BundleDescriptor) bundleDesc).isDDWithNoAnnotationAllowed()) {
            // if we come into this block, it means an old version
            // of deployment descriptor has annotation which is not correct
            // throw exception in this case
            String ddName = getStandardDDFile().getDeploymentDescriptorPath();
            String explodedArchiveName = new File(archive.getURI()).getName();
            String archiveName = FileUtils.revertFriendlyFilenameExtension(explodedArchiveName);
            throw new AnnotationProcessorException(localStrings.getLocalString("enterprise.deployment.oldDDwithAnnotation", "{0} in archive {1} is of version {2}, which cannot support annotations in an application.  Please upgrade the deployment descriptor to be a version supported by Java EE 5.0 (or later).", new Object[] { ddName, archiveName, bundleDesc.getSpecVersion() }));
        }
        boolean isFullAttribute = false;
        if (bundleDesc instanceof BundleDescriptor) {
            isFullAttribute = ((BundleDescriptor) bundleDesc).isFullAttribute();
        }
        AnnotationProcessor ap = annotationFactory.getAnnotationProcessor(isFullAttribute);
        ProcessingContext ctx = ap.createContext();
        ctx.setArchive(archive);
        if (annotationErrorHandler != null) {
            ctx.setErrorHandler(annotationErrorHandler);
        }
        ctx.setProcessingInput(scanner);
        ctx.pushHandler(aeHandler);
        // Make sure there is a classloader available on the descriptor
        // during annotation processing.
        ClassLoader originalBundleClassLoader = null;
        try {
            originalBundleClassLoader = bundleDesc.getClassLoader();
        } catch (Exception e) {
        // getClassLoader can throw exception if not available
        }
        // Only set classloader if it's not already set.
        if (originalBundleClassLoader == null) {
            bundleDesc.setClassLoader(classLoader);
        }
        try {
            return ap.process(ctx);
        } finally {
            if (originalBundleClassLoader == null) {
                bundleDesc.setClassLoader(null);
            }
        }
    }
    return null;
}
Also used : DeploymentDescriptorFile(com.sun.enterprise.deployment.io.DeploymentDescriptorFile) JarFile(java.util.jar.JarFile) ConfigurationDeploymentDescriptorFile(com.sun.enterprise.deployment.io.ConfigurationDeploymentDescriptorFile) SAXParseException(org.xml.sax.SAXParseException) MultiException(org.glassfish.hk2.api.MultiException)

Example 2 with Parser

use of org.glassfish.hk2.classmodel.reflect.Parser in project Payara by payara.

the class JavaEEScanner method initTypes.

protected void initTypes(File file) throws IOException {
    ParsingContext context = new ParsingContext.Builder().build();
    Parser cp = new Parser(context);
    cp.parse(file, null);
    try {
        cp.awaitTermination();
    } catch (InterruptedException e) {
        throw new IOException(e);
    }
    types = cp.getContext().getTypes();
}
Also used : ParsingContext(org.glassfish.hk2.classmodel.reflect.ParsingContext) IOException(java.io.IOException) Parser(org.glassfish.hk2.classmodel.reflect.Parser)

Example 3 with Parser

use of org.glassfish.hk2.classmodel.reflect.Parser in project Payara by payara.

the class Utils method getServiceLocator.

public static ServiceLocator getServiceLocator(final InputStream inputStream, String name) {
    try {
        final ServiceLocator habitat = getNewServiceLocator(name);
        final ConfigParser parser = new ConfigParser(habitat);
        XMLInputFactory xif = XMLInputFactory.class.getClassLoader() == null ? XMLInputFactory.newFactory() : XMLInputFactory.newFactory(XMLInputFactory.class.getName(), XMLInputFactory.class.getClassLoader());
        final DomDocument document = parser.parse(xif.createXMLStreamReader(inputStream));
        ServiceLocatorUtilities.addOneConstant(habitat, document);
        return habitat;
    } catch (Exception e) {
        e.printStackTrace();
        throw new GrizzlyConfigException(e.getMessage(), e);
    }
}
Also used : ServiceLocator(org.glassfish.hk2.api.ServiceLocator) ConfigParser(org.jvnet.hk2.config.ConfigParser) XMLInputFactory(javax.xml.stream.XMLInputFactory) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) DomDocument(org.jvnet.hk2.config.DomDocument)

Example 4 with Parser

use of org.glassfish.hk2.classmodel.reflect.Parser in project Payara by payara.

the class SecureAdminClientManager method prepareDomain.

private Domain prepareDomain(final String serverName, final String nodeDir, final String node, final File nodeDirRoot) {
    /*
         * At least one of serverName, nodeDir, or node must be non-null.
         * Otherwise we'll have no way of figuring out which domain.xml to
         * look in to see if we should use client authentication.  This will
         * often be the case, for instance, if create-local-instance is
         * run directly (not from another command).  In such cases, if
         * secure admin is enabled the user should provide --user and
         * --passwordfile on the command line to authenticate to the DAS.
         */
    if (serverName == null && nodeDir == null && node == null) {
        return null;
    }
    final ServerDirsSelector selector;
    try {
        final String nodeDirToUse = (nodeDir != null ? nodeDir : nodeDirRoot.getAbsolutePath());
        selector = ServerDirsSelector.getInstance(null, serverName, nodeDirToUse, node);
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }
    /*
         * If the caller did not pass any of the values we can use to locate
         * the domain.xml, then we cannot run in client-cert mode.
         */
    final ServerDirs dirs = selector.dirs();
    if (dirs == null) {
        return null;
    }
    final File domainXMLFile = dirs.getDomainXml();
    if (!domainXMLFile.exists()) {
        return null;
    }
    try {
        ServiceLocator habitat = Globals.getStaticHabitat();
        ConfigParser parser = new ConfigParser(habitat);
        URL domainURL = domainXMLFile.toURI().toURL();
        DomDocument doc = parser.parse(domainURL);
        Dom domDomain = doc.getRoot();
        Domain d = domDomain.createProxy(Domain.class);
        return d;
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }
}
Also used : ServiceLocator(org.glassfish.hk2.api.ServiceLocator) Dom(org.jvnet.hk2.config.Dom) ConfigParser(org.jvnet.hk2.config.ConfigParser) ServerDirs(com.sun.enterprise.util.io.ServerDirs) Domain(com.sun.enterprise.config.serverbeans.Domain) File(java.io.File) IOException(java.io.IOException) KeyStoreException(java.security.KeyStoreException) CertificateException(java.security.cert.CertificateException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) UnrecoverableKeyException(java.security.UnrecoverableKeyException) URL(java.net.URL) DomDocument(org.jvnet.hk2.config.DomDocument)

Example 5 with Parser

use of org.glassfish.hk2.classmodel.reflect.Parser in project Payara by payara.

the class VerifyDomainXmlCommand method executeCommand.

/**
 */
@Override
protected int executeCommand() throws CommandException, CommandValidationException {
    File domainXMLFile = getDomainXml();
    logger.log(Level.FINER, "Domain XML file = {0}", domainXMLFile);
    try {
        // get the list of JAR files from the modules directory
        ArrayList<URL> urls = new ArrayList<URL>();
        File idir = new File(System.getProperty(SystemPropertyConstants.INSTALL_ROOT_PROPERTY));
        File mdir = new File(idir, "modules");
        for (File f : mdir.listFiles()) {
            if (f.toString().endsWith(".jar")) {
                urls.add(f.toURI().toURL());
            }
        }
        final URL[] urlsA = urls.toArray(new URL[urls.size()]);
        ClassLoader cl = (ClassLoader) AccessController.doPrivileged(new PrivilegedAction() {

            @Override
            public Object run() {
                return new URLClassLoader(urlsA, Globals.class.getClassLoader());
            }
        });
        ModulesRegistry registry = new StaticModulesRegistry(cl);
        ServiceLocator serviceLocator = registry.createServiceLocator("default");
        ConfigParser parser = new ConfigParser(serviceLocator);
        URL domainURL = domainXMLFile.toURI().toURL();
        DomDocument doc = parser.parse(domainURL);
        Dom domDomain = doc.getRoot();
        Domain domain = domDomain.createProxy(Domain.class);
        DomainXmlVerifier validator = new DomainXmlVerifier(domain);
        if (validator.invokeConfigValidator())
            return 1;
    } catch (Exception e) {
        throw new CommandException(e);
    }
    return 0;
}
Also used : Dom(org.jvnet.hk2.config.Dom) ArrayList(java.util.ArrayList) ConfigParser(org.jvnet.hk2.config.ConfigParser) StaticModulesRegistry(com.sun.enterprise.module.single.StaticModulesRegistry) URL(java.net.URL) IOException(java.io.IOException) DomDocument(org.jvnet.hk2.config.DomDocument) ServiceLocator(org.glassfish.hk2.api.ServiceLocator) PrivilegedAction(java.security.PrivilegedAction) ModulesRegistry(com.sun.enterprise.module.ModulesRegistry) StaticModulesRegistry(com.sun.enterprise.module.single.StaticModulesRegistry) URLClassLoader(java.net.URLClassLoader) URLClassLoader(java.net.URLClassLoader) Domain(com.sun.enterprise.config.serverbeans.Domain) File(java.io.File)

Aggregations

IOException (java.io.IOException)5 ServiceLocator (org.glassfish.hk2.api.ServiceLocator)3 ConfigParser (org.jvnet.hk2.config.ConfigParser)3 DomDocument (org.jvnet.hk2.config.DomDocument)3 Domain (com.sun.enterprise.config.serverbeans.Domain)2 File (java.io.File)2 URL (java.net.URL)2 Parser (org.glassfish.hk2.classmodel.reflect.Parser)2 ParsingContext (org.glassfish.hk2.classmodel.reflect.ParsingContext)2 Dom (org.jvnet.hk2.config.Dom)2 ConfigurationDeploymentDescriptorFile (com.sun.enterprise.deployment.io.ConfigurationDeploymentDescriptorFile)1 DeploymentDescriptorFile (com.sun.enterprise.deployment.io.DeploymentDescriptorFile)1 ModulesRegistry (com.sun.enterprise.module.ModulesRegistry)1 StaticModulesRegistry (com.sun.enterprise.module.single.StaticModulesRegistry)1 ServerDirs (com.sun.enterprise.util.io.ServerDirs)1 MalformedURLException (java.net.MalformedURLException)1 URLClassLoader (java.net.URLClassLoader)1 KeyStoreException (java.security.KeyStoreException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 PrivilegedAction (java.security.PrivilegedAction)1