support decorator cloning for WebAppContext templates

git-svn-id: svn+ssh://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk@2171 7e9141cc-0065-0410-87d8-b60c137991c4
This commit is contained in:
Greg Wilkins 2010-07-22 06:33:54 +00:00
parent 5e49b01b93
commit 3ca0c6806a
5 changed files with 33 additions and 7 deletions

View File

@ -19,6 +19,7 @@ import javax.servlet.Filter;
import javax.servlet.Servlet;
import javax.servlet.ServletException;
import org.eclipse.jetty.server.handler.ContextHandler;
import org.eclipse.jetty.servlet.FilterHolder;
import org.eclipse.jetty.servlet.ServletHolder;
import org.eclipse.jetty.servlet.ServletContextHandler.Decorator;
@ -47,6 +48,13 @@ public class WebAppDecoratorWrapper implements Decorator
_introspector.registerHandler(new PreDestroyAnnotationHandler(context));
_introspector.registerHandler(new DeclareRolesAnnotationHandler(context));
}
/* ------------------------------------------------------------ */
public Decorator cloneFor(ContextHandler context)
{
WebAppContext wac = (WebAppContext)context;
return new WebAppDecoratorWrapper(wac,_wrappedDecorator.cloneFor(context));
}
/* ------------------------------------------------------------ */
/**

View File

@ -40,7 +40,7 @@ public class Configuration implements org.eclipse.jetty.webapp.Configuration
public void preConfigure (WebAppContext context)
throws Exception
{
WebAppDecorator decorator = new WebAppDecorator(context);
WebAppDecorator decorator = new WebAppDecorator();
InjectionCollection injections = new InjectionCollection();
context.setAttribute(InjectionCollection.INJECTION_COLLECTION, injections);
decorator.setInjections(injections);

View File

@ -22,6 +22,7 @@ import javax.servlet.ServletException;
import org.eclipse.jetty.plus.annotation.InjectionCollection;
import org.eclipse.jetty.plus.annotation.LifeCycleCallbackCollection;
import org.eclipse.jetty.plus.annotation.RunAsCollection;
import org.eclipse.jetty.server.handler.ContextHandler;
import org.eclipse.jetty.servlet.FilterHolder;
import org.eclipse.jetty.servlet.ServletHolder;
import org.eclipse.jetty.servlet.ServletContextHandler.Decorator;
@ -35,18 +36,26 @@ import org.eclipse.jetty.webapp.WebAppContext;
*/
public class WebAppDecorator implements Decorator
{
private WebAppContext _context;
private InjectionCollection _injections;
private LifeCycleCallbackCollection _callbacks;
private RunAsCollection _runAses;
public WebAppDecorator (WebAppContext context)
public WebAppDecorator ()
{
_context = context;
}
/* ------------------------------------------------------------ */
/**
* @see org.eclipse.jetty.servlet.ServletContextHandler.Decorator#cloneFor(org.eclipse.jetty.server.handler.ContextHandler)
*/
public Decorator cloneFor(ContextHandler context)
{
// TODO maybe need to check for non-shared classloader???
return this;
}
public InjectionCollection getInjections()
{
return _injections;

View File

@ -745,5 +745,7 @@ public class ServletContextHandler extends ContextHandler
void destroyServletInstance(Servlet s);
void destroyFilterInstance(Filter f);
void destroyListenerInstance(EventListener f);
public Decorator cloneFor(ContextHandler context);
}
}

View File

@ -168,11 +168,14 @@ public class WebAppContext extends ServletContextHandler implements WebAppClassL
throw new IllegalArgumentException("template is started");
_scontext=new Context();
setErrorHandler(new ErrorPageErrorHandler());
//Make a new MetaData to hold descriptor and annotation metadata
_metadata = template.getMetaData();
_configurations = new Configuration[]{new MetaDataConfiguration(template)};
System.err.println("webapp "+getContextPath()+" @ "+hashCode());
// TODO we need some better way to work out what attributes should be copied at this stage.
setAliases(template.isAliases());
setBaseResource(template.getBaseResource());
setClassLoader(template.getClassLoader()); // TODO maybe not share classloader?
@ -182,6 +185,10 @@ public class WebAppContext extends ServletContextHandler implements WebAppClassL
setLogger(template.getLogger()); // TODO maybe not shared ???
setMaxFormContentSize(template.getMaxFormContentSize());
Decorator decorator = template.getDecorator();
if (decorator!=null)
setDecorator(decorator.cloneFor(this));
Enumeration names=template.getAttributeNames();
while(names.hasMoreElements())
{