Package org.jboss.weld.environment.se

Examples of org.jboss.weld.environment.se.Weld


    WeldContainer container;

    @Before
    public void before() {
        TestConsumer.resetCount();
        container = new Weld().initialize();
    }
View Full Code Here


public class CDIExampleTest {

    @Test
    public void testGo() {
        Weld w = new Weld();
        WeldContainer wc = w.initialize();

        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        PrintStream ps = new PrintStream(baos);

        CDIExample bean = wc.instance().select(CDIExample.class).get();
        bean.go(ps);

        ps.close();

        String actual = new String(baos.toByteArray());
        String expected = "" +
                          "Dave: Hello, HAL. Do you read me, HAL?\n" +
                          "HAL: Dave. I read you.\n";
        assertEquals(expected, actual);

        w.shutdown();
    }
View Full Code Here

public class CDIInstanceExampleTest {

    @Test
    public void testGo() {
        Weld w = new Weld();
        WeldContainer wc = w.initialize();

        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        PrintStream ps = new PrintStream(baos);

        CDIInstanceExample bean = wc.instance().select(CDIInstanceExample.class).get();
        bean.go(ps);

        ps.close();

        String actual = new String(baos.toByteArray());
        String expected = "" +
                          "Dave: Hello, HAL. Do you read me, HAL?\n" +
                          "HAL: Dave. I read you.\n";
        assertEquals(expected, actual);

        w.shutdown();
    }
View Full Code Here

               initLogging();

               boolean restarting = restartRequested;
               restartRequested = false;

               Weld weld = new ModularWeld();
               BeanManager manager = null;

               // FIXME this plugin loading scheme causes classloading issues w/weld because weld cannot load classes
               // from its own classloaders before plugins are loaded and pollute the classpath.
               // We can work around it by loading weld before we load plugins, then restarting weld, but this is SLOW.
               try {
                  WeldContainer container = weld.initialize();
                  manager = container.getBeanManager();
                  weld.shutdown();
               }
               catch (Exception e) {}

               try {
                  // TODO verify plugin API versions. only activate compatible plugins.
                  loadPlugins();
                  WeldContainer container = weld.initialize();
                  manager = container.getBeanManager();
               }
               catch (Throwable e) {
                  // Boot up with external plugins disabled.
                  System.out
                           .println("Plugin system disabled due to failure while loading one or more plugins; try removing offending plugins with \"forge remove-plugin <TAB>\".");
                  e.printStackTrace();

                  Thread.currentThread().setContextClassLoader(mainClassLoader);

                  initLogging();
                  WeldContainer container = weld.initialize();
                  manager = container.getBeanManager();
               }

               manager.fireEvent(new PreStartup());
               manager.fireEvent(new Startup(workingDir, restarting));
               manager.fireEvent(new PostStartup());
               manager.fireEvent(new AcceptUserInput());
               weld.shutdown();
            }
         });

         currentShell.start();
         try
View Full Code Here

               initLogging();

               boolean restarting = restartRequested;
               restartRequested = false;

               Weld weld = new ModularWeld();
               BeanManager manager = null;

               // FIXME this plugin loading scheme causes classloading issues w/weld because weld cannot load classes
               // from its own classloaders before plugins are loaded and pollute the classpath.
               // We can work around it by loading weld before we load plugins, then restarting weld, but this is SLOW.
               try
               {
                  WeldContainer container = weld.initialize();
                  manager = container.getBeanManager();
                  weld.shutdown();
               }
               catch (Exception e)
               {
               }

               try
               {
                  // TODO verify plugin API versions. only activate compatible plugins.
                  loadPlugins();
                  WeldContainer container = weld.initialize();
                  manager = container.getBeanManager();
               }
               catch (Throwable e)
               {
                  // Boot up with external plugins disabled.
                  System.out
                           .println("Plugin system disabled due to failure while loading one or more plugins; try removing offending plugins with \"forge remove-plugin <TAB>\".");
                  e.printStackTrace();

                  Thread.currentThread().setContextClassLoader(mainClassLoader);

                  initLogging();
                  WeldContainer container = weld.initialize();
                  manager = container.getBeanManager();
               }
               try
               {
                  manager.fireEvent(new PreStartup());
               }
               catch (Throwable t)
               {
                  System.out.println("Error during PreStartup event");
                  t.printStackTrace();
               }
               try
               {
                  manager.fireEvent(new Startup(workingDir, restarting));
               }
               catch (Throwable t)
               {
                  System.out.println("Error during Startup event");
                  t.printStackTrace();
               }
               try
               {

                  manager.fireEvent(new PostStartup());
               }
               catch (Throwable t)
               {
                  System.out.println("Error during PostStartup event");
                  t.printStackTrace();
               }
               try
               {
                  manager.fireEvent(new AcceptUserInput());
               }
               catch (Throwable t)
               {
                  System.out.println("Error during AcceptUserInput event");
                  t.printStackTrace();
               }
               weld.shutdown();
            }
         });

         currentShell.start();
         try
View Full Code Here

        kSession.insert(new Message("Dave", "Open the pod bay doors, HAL."));
        kSession.fireAllRules();
    }

    public static void main(String[] args) {
        Weld w = new Weld();

        WeldContainer wc = w.initialize();
        CDIExampleWithInclusion bean = wc.instance().select(CDIExampleWithInclusion.class).get();
        bean.go(System.out);

        w.shutdown();
    }
View Full Code Here

               + " To enable the Weld Integration please define an WeldContainerHelper");
         }
      }
      else
      {
         Weld weld = new Weld();
         weld.addExtension(new WeldExtension(this));
         WeldContainerHelper helper = super.getComponentInstanceOfType(WeldContainerHelper.class, false);
         List<Extension> extensions = helper.getExtensions();
         if (extensions != null)
         {
            for (Extension e : extensions)
            {
               weld.addExtension(e);
            }
         }
         this.helper = helper;
         this.container = weld.initialize();
         // This is an ugly hack to make sure that the BeanManagerProxy is initialized with the right Container
         // This is needed especially when we intend to initialize several weld containers within the same instance
         container.getBeanManager().getBeans(org.jboss.weld.environment.se.WeldContainer.class);
         this.weldContainer = org.jboss.weld.Container.instance();
         this.weld = weld;
View Full Code Here

public class CDIBeanProvider implements BeanProvider {

   private final BeanManager beanManager;

   public CDIBeanProvider() {
      final WeldContainer weldContainer = new Weld().initialize();
      beanManager = weldContainer.getBeanManager();
   }
View Full Code Here

import javax.enterprise.inject.spi.BeanManager;

public class CDITest {
    @Test
    public void testInitWeld() {
        Weld weld = new Weld();
        WeldContainer weldContainer = weld.initialize();
        BeanManager bm = CdiInjectorFactory.lookupBeanManagerCDIUtil();
        Assert.assertNotNull(bm);
        weld.shutdown();
    }
View Full Code Here


    private WeldContainer getWeldContainer() {
        if (weldContainer == null) {
            try {
                weldContainer = (new Weld()).initialize();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return weldContainer;
View Full Code Here

TOP

Related Classes of org.jboss.weld.environment.se.Weld

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.