[jboss-cvs] JBossAS SVN: r58510 - trunk/tomcat/src/main/org/jboss/web/tomcat/tc6/deployers
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Fri Nov 17 21:03:17 EST 2006
Author: scott.stark at jboss.org
Date: 2006-11-17 21:03:15 -0500 (Fri, 17 Nov 2006)
New Revision: 58510
Added:
trunk/tomcat/src/main/org/jboss/web/tomcat/tc6/deployers/WarClassLoaderDeployer.java
Log:
An in progress web app class loading deployer
Added: trunk/tomcat/src/main/org/jboss/web/tomcat/tc6/deployers/WarClassLoaderDeployer.java
===================================================================
--- trunk/tomcat/src/main/org/jboss/web/tomcat/tc6/deployers/WarClassLoaderDeployer.java 2006-11-18 02:02:27 UTC (rev 58509)
+++ trunk/tomcat/src/main/org/jboss/web/tomcat/tc6/deployers/WarClassLoaderDeployer.java 2006-11-18 02:03:15 UTC (rev 58510)
@@ -0,0 +1,190 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.web.tomcat.tc6.deployers;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.catalina.Loader;
+import org.jboss.deployers.plugins.deployer.AbstractSimpleDeployer;
+import org.jboss.deployers.spi.DeploymentException;
+import org.jboss.deployers.spi.classloader.ClassLoaderFactory;
+import org.jboss.deployers.spi.deployer.DeploymentUnit;
+import org.jboss.deployers.spi.structure.DeploymentContext;
+import org.jboss.metadata.WebMetaData;
+import org.jboss.virtual.VirtualFile;
+import org.jboss.web.tomcat.tc6.TomcatInjectionContainer;
+import org.jboss.web.tomcat.tc6.WebAppLoader;
+import org.jboss.web.tomcat.tc6.WebCtxLoader;
+
+/**
+ * A class loader deployer for wars that handles installing a war first class
+ * loader unless the WebMetaData indicates otherwise.
+ * AbstractClassLoaderDeployer
+ *
+ * @author Scott.Stark at jboss.org
+ * @version $Revision:$
+ */
+public class WarClassLoaderDeployer extends AbstractSimpleDeployer
+ implements ClassLoaderFactory
+{
+ /** The parent class loader first model flag */
+ private boolean java2ClassLoadingCompliance = false;
+ private boolean useJBossWebLoader;
+ /** Package names that should be ignored for class loading */
+ private String[] filteredPackages;
+
+ public WarClassLoaderDeployer()
+ {
+ // Should be after the default class loading deployer to pickup parent cl
+ super.setRelativeOrder(CLASSLOADER_DEPLOYER - 1);
+ }
+
+ public boolean isJava2ClassLoadingCompliance()
+ {
+ return java2ClassLoadingCompliance;
+ }
+ public void setJava2ClassLoadingCompliance(boolean flag)
+ {
+ this.java2ClassLoadingCompliance = flag;
+ }
+
+ public String[] getFilteredPackages()
+ {
+ return filteredPackages;
+ }
+ public void setFilteredPackages(String[] pkgs)
+ {
+ this.filteredPackages = pkgs;
+ }
+
+ public boolean isUseJBossWebLoader()
+ {
+ return useJBossWebLoader;
+ }
+ public void setUseJBossWebLoader(boolean useJBossWebLoader)
+ {
+ this.useJBossWebLoader = useJBossWebLoader;
+ }
+
+
+ @Override
+ public void deploy(DeploymentUnit unit) throws DeploymentException
+ {
+ WebMetaData metaData = unit.getAttachment(WebMetaData.class);
+ if( metaData != null )
+ {
+ unit.addAttachment(ClassLoaderFactory.class, this);
+ }
+ }
+
+ public ClassLoader createClassLoader(DeploymentContext context) throws Exception
+ {
+ ClassLoader loader = null;
+ try
+ {
+ DeploymentUnit unit = context.getDeploymentUnit();
+ WebMetaData metaData = unit.getAttachment(WebMetaData.class);
+ loader = createClassLoader(metaData, context);
+ if( loader != null )
+ context.setClassLoader(loader);
+ }
+ catch(Exception e)
+ {
+ log.warn("", e);
+ }
+ return loader;
+ }
+
+ public void removeClassLoader(DeploymentContext context) throws Exception
+ {
+
+ }
+
+ /**
+ *
+ */
+ protected ClassLoader createClassLoader(WebMetaData metaData, DeploymentContext context)
+ throws Exception
+ {
+ ClassLoader loader = null;
+ if (metaData != null)
+ {
+ ClassLoader parent = context.getClassLoader();
+ if( parent == null )
+ parent = context.getTopLevel().getClassLoader();
+ if( parent == null )
+ parent = Thread.currentThread().getContextClassLoader();
+ Loader webLoader = getWebLoader(parent, metaData, context.getClassPath());
+ context.getDeploymentUnit().addAttachment(Loader.class, webLoader);
+ loader = webLoader.getClassLoader();
+ }
+ return loader;
+ }
+
+ /**
+ * Create the web app class loader.
+ *
+ * @param loader
+ * @param metaData
+ * @param classpath
+ * @return
+ * @throws MalformedURLException
+ */
+ protected Loader getWebLoader(ClassLoader loader, WebMetaData metaData,
+ List<VirtualFile> classpath)
+ throws Exception
+ {
+ Loader webLoader = null;
+ TomcatInjectionContainer injectionContainer = null;
+ if (useJBossWebLoader)
+ {
+ WebCtxLoader jbossLoader = new WebCtxLoader(loader, injectionContainer);
+ ArrayList<URL> cp = new ArrayList<URL>();
+ for(VirtualFile vf : classpath)
+ {
+ try
+ {
+ URL path = vf.toURL();
+ cp.add(path);
+ }
+ catch(Exception e)
+ {
+ log.debug("Ignoring path element: "+vf, e);
+ }
+ }
+ jbossLoader.setClasspath(cp);
+ webLoader = jbossLoader;
+ }
+ else
+ {
+ WebAppLoader jbossLoader = new WebAppLoader(loader, filteredPackages, injectionContainer);
+ jbossLoader.setDelegate(java2ClassLoadingCompliance);
+ jbossLoader.start();
+ webLoader = jbossLoader;
+ }
+ return webLoader;
+ }
+
+}
More information about the jboss-cvs-commits
mailing list