public Listener() { try { bootstrap = Reflections.newInstance(BOOTSTRAP_IMPL_CLASS_NAME); } catch (IllegalArgumentException e) { throw new IllegalStateException("Error loading Weld bootstrap, check that Weld is on the classpath", e); } try { weldListener = Reflections.newInstance(WELD_LISTENER_CLASS_NAME); } catch (IllegalArgumentException e) { throw new IllegalStateException("Error loading Weld listener, check that Weld is on the classpath", e); } }
public static <T> T newInstance(String className) { try { return Reflections.<T>classForName(className).newInstance(); } catch (InstantiationException e) { throw new IllegalArgumentException("Cannot instantiate instance of " + className + " with no-argument constructor", e); } catch (IllegalAccessException e) { throw new IllegalArgumentException("Cannot instantiate instance of " + className + " with no-argument constructor", e); } }
try Reflections.classForName("org.apache.AnnotationProcessor"); Class<?> clazz = Reflections.classForName(WeldAnnotationProcessor.class.getName()); Object annotationProcessor = clazz.getConstructor(WeldManager.class).newInstance(manager); sce.getServletContext().setAttribute(WeldAnnotationProcessor.class.getName(), annotationProcessor); newInstance("org.jboss.weld.el.WeldELContextListener"));
private void scan(ServletContext servletContext) { Scanner scanner = new URLScanner(Reflections.getClassLoader(), this); scanner.scanResources(new String[] { META_INF_BEANS_XML }); try { URL beans = servletContext.getResource(WEB_INF_BEANS_XML); if (beans != null) { beansXml.add(beans); // this is consistent with how the JBoss weld.deployer works File webInfClasses = Servlets.getRealFile(servletContext, WEB_INF_CLASSES); if (webInfClasses != null) { File[] files = { webInfClasses }; scanner.scanDirectories(files); } } } catch (MalformedURLException e) { throw new IllegalStateException("Error loading resources from servlet context ", e); } }
public WeldApplication(Application application) { this.application = application; // QUESTION should the context listener be registered in init() instead? application.addELContextListener(Reflections.<ELContextListener>newInstance("org.jboss.weld.el.WeldELContextListener")); elResolver = new LazyBeanManagerIntegrationELResolver(); application.addELResolver(elResolver); }
@Override public void contextDestroyed(ServletContextEvent sce) { bootstrap.shutdown(); try { Reflections.classForName("org.apache.AnnotationProcessor"); sce.getServletContext().removeAttribute(WeldAnnotationProcessor.class.getName()); } catch (IllegalArgumentException e) {} super.contextDestroyed(sce); }
private HttpJspBase loadJsp(String forwardedUrl, File compilationDir) throws MalformedURLException, ClassNotFoundException, InstantiationException, IllegalAccessException, ServletException { String jspClassName = toJspClassName(forwardedUrl); URLClassLoader classLoader = URLClassLoader.newInstance(new URL[] { compilationDir.toURI().toURL() }); Class<?> cls = Class.forName(jspClassName, true, classLoader); HttpJspBase instance = (HttpJspBase) cls.newInstance(); MockServletConfig servletConfig = new MockServletConfig(new MockServletContext()); servletConfig.getServletContext().setAttribute(InstanceManager.class.getName(), new InstanceManagerImplementation()); JspApplicationContext jspApplicationContext = JspFactory.getDefaultFactory().getJspApplicationContext( servletConfig.getServletContext()); // Register the ELResolver with JSP jspApplicationContext.addELResolver(manager.getELResolver()); // Register ELContextListener with JSP jspApplicationContext.addELContextListener(Reflections .<ELContextListener> newInstance("org.jboss.weld.el.WeldELContextListener")); // Push the wrapped expression factory into the servlet context so that // Tomcat or Jetty can hook it in using a container code servletConfig.getServletContext().setAttribute(EXPRESSION_FACTORY_NAME, manager.wrapExpressionFactory(jspApplicationContext.getExpressionFactory())); instance.init(servletConfig); JspFactory.setDefaultFactory(new org.apache.jasper.runtime.JspFactoryImpl()); instance._jspInit(); return instance; }