|
Glassfish example source code file (WeldDeployer.java)
The Glassfish WeldDeployer.java source code/* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * * Copyright (c) 2009-2011 Oracle and/or its affiliates. All rights reserved. * * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common Development * and Distribution License("CDDL") (collectively, the "License"). You * may not use this file except in compliance with the License. You can * obtain a copy of the License at * https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html * or packager/legal/LICENSE.txt. See the License for the specific * language governing permissions and limitations under the License. * * When distributing the software, include this License Header Notice in each * file and include the License file at packager/legal/LICENSE.txt. * * GPL Classpath Exception: * Oracle designates this particular file as subject to the "Classpath" * exception as provided by Oracle in the GPL Version 2 section of the License * file that accompanied this code. * * Modifications: * If applicable, add the following below the License Header, with the fields * enclosed by brackets [] replaced by your own identifying information: * "Portions Copyright [year] [name of copyright owner]" * * Contributor(s): * If you wish your version of this file to be governed by only the CDDL or * only the GPL Version 2, indicate your decision by adding "[Contributor] * elects to include this software in this distribution under the [CDDL or GPL * Version 2] license." If you don't indicate a single choice of license, a * recipient has the option to distribute your version of this file under * either the CDDL, the GPL Version 2 or to extend the choice of license to * its licensees as provided above. However, if you add GPL Version 2 code * and therefore, elected the GPL Version 2 license, then the option applies * only if the new code is made subject to such option by the copyright * holder. */ package org.glassfish.weld; import java.util.Collection; import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; import java.util.logging.Level; import java.util.logging.Logger; import javax.enterprise.inject.spi.AnnotatedType; import javax.enterprise.inject.spi.InjectionTarget; import javax.servlet.Filter; import javax.servlet.Servlet; import javax.servlet.ServletContextListener; import javax.servlet.ServletRequestListener; import javax.servlet.http.HttpSessionListener; import org.glassfish.api.deployment.DeploymentContext; import org.glassfish.api.deployment.MetaData; import org.glassfish.api.deployment.archive.ReadableArchive; import org.glassfish.api.event.EventListener; import org.glassfish.api.event.Events; import org.glassfish.api.deployment.DeployCommandParameters; import org.glassfish.deployment.common.DeploymentException; import org.glassfish.deployment.common.SimpleDeployer; import org.glassfish.internal.data.ApplicationInfo; import org.glassfish.internal.data.ApplicationRegistry; import org.glassfish.weld.services.EjbServicesImpl; import org.glassfish.weld.services.InjectionServicesImpl; import org.glassfish.weld.services.ProxyServicesImpl; import org.glassfish.weld.services.SecurityServicesImpl; import org.glassfish.weld.services.TransactionServicesImpl; import org.glassfish.weld.services.ValidationServicesImpl; import org.jboss.weld.bootstrap.WeldBootstrap; import org.jboss.weld.bootstrap.api.Environments; import org.jboss.weld.bootstrap.spi.BeanDeploymentArchive; import org.jboss.weld.ejb.spi.EjbServices; import org.jboss.weld.injection.spi.InjectionServices; import org.jboss.weld.security.spi.SecurityServices; import org.jboss.weld.serialization.spi.ProxyServices; import org.jboss.weld.transaction.spi.TransactionServices; import org.jboss.weld.validation.spi.ValidationServices; import org.jvnet.hk2.annotations.Inject; import org.jvnet.hk2.annotations.Service; import org.jvnet.hk2.component.Habitat; import org.jvnet.hk2.component.PostConstruct; import com.sun.enterprise.container.common.spi.util.InjectionManager; import com.sun.enterprise.deployment.AppListenerDescriptorImpl; import com.sun.enterprise.deployment.Application; import com.sun.enterprise.deployment.BundleDescriptor; import com.sun.enterprise.deployment.EjbBundleDescriptor; import com.sun.enterprise.deployment.EjbDescriptor; import com.sun.enterprise.deployment.WebBundleDescriptor; import com.sun.logging.LogDomains; @Service public class WeldDeployer extends SimpleDeployer<WeldContainer, WeldApplicationContainer> implements PostConstruct, EventListener { private Logger _logger = LogDomains.getLogger(WeldDeployer.class, LogDomains.CORE_LOGGER); public static final String WELD_EXTENSION = "org.glassfish.weld"; public static final String WELD_DEPLOYMENT = "org.glassfish.weld.WeldDeployment"; /* package */ static final String WELD_BOOTSTRAP = "org.glassfish.weld.WeldBootstrap"; private static final String WELD_CONTEXT_LISTENER = "org.glassfish.weld.WeldContextListener"; private static final String WELD_LISTENER = "org.jboss.weld.servlet.WeldListener"; private static final String WELD_SHUTDOWN = "false"; @Inject private Events events; @Inject private Habitat habitat; @Inject private ApplicationRegistry applicationRegistry; private Map<Application, WeldBootstrap> appToBootstrap = new HashMap<Application, WeldBootstrap>(); private Map<BundleDescriptor, BeanDeploymentArchive> bundleToBeanDeploymentArchive = new HashMap<BundleDescriptor, BeanDeploymentArchive>(); private static final Class<?>[] NON_CONTEXT_CLASSES = { Servlet.class, ServletContextListener.class, Filter.class, HttpSessionListener.class, ServletRequestListener.class // TODO need to add more classes }; @Override public MetaData getMetaData() { return new MetaData(true, null, new Class[] {Application.class}); } public void postConstruct() { events.register(this); } /** * Specific stages of the Weld bootstrapping process will execute across different stages * of the deployment process. Weld deployment will happen when the load phase of the * deployment process is complete. When all modules have been loaded, a deployment * graph is produced defining the accessiblity relationships between * <code>BeanDeploymentArchives. */ public void event(Event event) { if ( event.is(org.glassfish.internal.deployment.Deployment.APPLICATION_LOADED) ) { ApplicationInfo appInfo = (ApplicationInfo)event.hook(); WeldBootstrap bootstrap = (WeldBootstrap)appInfo.getTransientAppMetaData(WELD_BOOTSTRAP, WeldBootstrap.class); if( bootstrap != null ) { DeploymentImpl deploymentImpl = (DeploymentImpl)appInfo.getTransientAppMetaData( WELD_DEPLOYMENT, DeploymentImpl.class); deploymentImpl.buildDeploymentGraph(); if (_logger.isLoggable(Level.FINE)) { _logger.fine(deploymentImpl.toString()); } //get Current TCL ClassLoader oldTCL = Thread.currentThread().getContextClassLoader(); try { bootstrap.startContainer(Environments.SERVLET, deploymentImpl/*, new ConcurrentHashMapBeanStore()*/); bootstrap.startInitialization(); fireProcessInjectionTargetEvents(bootstrap, deploymentImpl); bootstrap.deployBeans(); } catch (Throwable t) { DeploymentException de = new DeploymentException(t.getMessage()); de.initCause(t); throw(de); } finally { //The TCL is originally the EAR classloader //and is reset during Bean deployment to the //corresponding module classloader in BeanDeploymentArchiveImpl.getBeans //for Bean classloading to succeed. The TCL is reset //to its old value here. Thread.currentThread().setContextClassLoader(oldTCL); } } } else if ( event.is(org.glassfish.internal.deployment.Deployment.APPLICATION_STARTED) ) { ApplicationInfo appInfo = (ApplicationInfo)event.hook(); WeldBootstrap bootstrap = (WeldBootstrap)appInfo.getTransientAppMetaData(WELD_BOOTSTRAP, WeldBootstrap.class); if( bootstrap != null ) { try { bootstrap.validateBeans(); bootstrap.endInitialization(); } catch (Throwable t) { DeploymentException de = new DeploymentException(t.getMessage()); de.initCause(t); throw(de); } } } else if ( event.is(org.glassfish.internal.deployment.Deployment.APPLICATION_STOPPED) || event.is(org.glassfish.internal.deployment.Deployment.APPLICATION_UNLOADED)) { ApplicationInfo appInfo = (ApplicationInfo)event.hook(); Application app = appInfo.getMetaData(Application.class); if( app != null ) { for(BundleDescriptor next : app.getBundleDescriptors()) { if( next instanceof EjbBundleDescriptor || next instanceof WebBundleDescriptor ) { bundleToBeanDeploymentArchive.remove(next); } } appToBootstrap.remove(app); } String shutdown = appInfo.getTransientAppMetaData(WELD_SHUTDOWN, String.class); if (Boolean.valueOf(shutdown) == Boolean.TRUE) { return; } WeldBootstrap bootstrap = (WeldBootstrap)appInfo.getTransientAppMetaData(WELD_BOOTSTRAP, WeldBootstrap.class); if (bootstrap != null) { try { bootstrap.shutdown(); } catch(Exception e) { _logger.log(Level.WARNING, "JCDI shutdown error", e); } appInfo.addTransientAppMetaData(WELD_SHUTDOWN, "true"); } DeploymentImpl deploymentImpl = (DeploymentImpl)appInfo.getTransientAppMetaData( WELD_DEPLOYMENT, DeploymentImpl.class); if (deploymentImpl != null) { deploymentImpl.cleanup(); } } } /* * We are only firing ProcessInjectionTarget<X> for non-contextual EE * components and not using the InjectionTarget<X> from the event during * instance creation in JCDIServiceImpl.java * TODO weld would provide a better way to do this, otherwise we may need * TODO to store InjectionTarget<X> to be used in instance creation */ private void fireProcessInjectionTargetEvents(WeldBootstrap bootstrap, DeploymentImpl impl) { List<BeanDeploymentArchive> bdaList = impl.getBeanDeploymentArchives(); for(BeanDeploymentArchive bda : bdaList) { Collection<Class bdaClasses = ((BeanDeploymentArchiveImpl)bda).getBeanClassObjects(); for(Class<?> bdaClazz: bdaClasses) { for(Class<?> nonClazz : NON_CONTEXT_CLASSES) { if (nonClazz.isAssignableFrom(bdaClazz)) { AnnotatedType at = bootstrap.getManager(bda).createAnnotatedType(bdaClazz); InjectionTarget<?> it = bootstrap.getManager(bda).fireProcessInjectionTarget(at); ((BeanDeploymentArchiveImpl)bda).putInjectionTarget(at, it); } } } } } public BeanDeploymentArchive getBeanDeploymentArchiveForBundle(BundleDescriptor bundle) { return bundleToBeanDeploymentArchive.get(bundle); } public boolean is299Enabled(BundleDescriptor bundle) { return bundleToBeanDeploymentArchive.containsKey(bundle); } public WeldBootstrap getBootstrapForApp(Application app) { return appToBootstrap.get(app); } protected void generateArtifacts(DeploymentContext dc) throws DeploymentException { } protected void cleanArtifacts(DeploymentContext dc) throws DeploymentException { } public <V> V loadMetaData(Class Other Glassfish examples (source code examples)Here is a short list of links related to this Glassfish WeldDeployer.java source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.