package org.jboss.weld.environment.jetty7; import org.eclipse.jetty.webapp.AbstractConfiguration; import org.eclipse.jetty.webapp.Configuration; import org.eclipse.jetty.webapp.WebAppContext; import org.jboss.weld.environment.servlet.Listener; import java.util.EventListener; /** * Jetty 7 Configuration to setup Weld environment */ public class WeldConfiguration extends AbstractConfiguration { @Override public void preConfigure (WebAppContext context) throws Exception { context.addDecorator(new WeldDecorator(context.getServletContext())); } @Override public void cloneConfigure(WebAppContext template, WebAppContext context) throws Exception { context.addDecorator(new WeldDecorator(context.getServletContext())); } @Override public void configure (WebAppContext context) throws Exception { } @Override public void postConfigure(WebAppContext context) throws Exception { } @Override public void deconfigure (WebAppContext context) throws Exception { // May have to release listeners here } public static void register(WebAppContext wac) throws Exception { final WeldConfiguration configuration = new WeldConfiguration(); configuration.preConfigure(wac); configuration.configure(wac); appendConfiguration(wac, configuration); } private static void appendConfiguration(WebAppContext ctx, Configuration c) { Configuration[] existing = ctx.getConfigurations(); Configuration[] updated = new Configuration[existing.length + 1]; System.arraycopy(existing, 0, updated, 0, existing.length); updated[existing.length] = c; ctx.setConfigurations(updated); } }