本文整理匯總了Java中org.jboss.weld.environment.se.WeldContainer類的典型用法代碼示例。如果您正苦於以下問題:Java WeldContainer類的具體用法?Java WeldContainer怎麽用?Java WeldContainer使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
WeldContainer類屬於org.jboss.weld.environment.se包,在下文中一共展示了WeldContainer類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: initWeldContainer
import org.jboss.weld.environment.se.WeldContainer; //導入依賴的package包/類
protected WeldContainer initWeldContainer(Weld weld) {
// Register mock injection services if needed
if (!resources.isEmpty()) {
weld.addServices(new MockResourceInjectionServices(resources));
}
if (ejbFactory != null) {
weld.addServices(new MockEjbInjectionServices(ejbFactory));
}
if (persistenceContextFactory != null || persistenceUnitFactory != null) {
weld.addServices(new MockJpaInjectionServices(persistenceUnitFactory, persistenceContextFactory));
}
// Init the container
container = weld.initialize();
injectInstances();
if (extension != null) {
extension.activateContexts();
}
return container;
}
示例2: testCommandDecorator
import org.jboss.weld.environment.se.WeldContainer; //導入依賴的package包/類
@Test
public void testCommandDecorator() {
try (WeldContainer container = new Weld()
// Disable discovery completely
.disableDiscovery()
// Add command context implementation, decorator is enabled globally/automatically
.packages(CommandContext.class)
// Add bean classes manually
.beanClasses(DummyService.class, IdService.class, TestCommand.class)
// Add command extension manually so that we don't need to create META-INF/...
.addExtension(new CommandExtension())
.initialize()) {
// Command is a bean - cotext is activated/deactivated by decorator
container.select(TestCommand.class).get().execute();
}
}
示例3: testCommandDecorator
import org.jboss.weld.environment.se.WeldContainer; //導入依賴的package包/類
@Test
public void testCommandDecorator() {
try (WeldContainer container = new Weld()
// Disable discovery completely
.disableDiscovery()
// Add command context implementation, decorator is enabled globally/automatically
.packages(CommandContext.class)
// Add bean classes manually
.beanClasses(DummyService.class, IdService.class, TestCommand.class)
// Add command extension manually so that we don't need to create META-INF/...
.addExtension(new CommandExtension()).initialize()) {
// Execute non-CDI bean command - context is activated/deactivated by executor
CommandExecutor executor = container.select(CommandExecutor.class).get();
executor.execute(() -> {
assertEquals(container.select(IdService.class).get().getId(), container.select(IdService.class).get().getId());
});
}
}
示例4: apply
import org.jboss.weld.environment.se.WeldContainer; //導入依賴的package包/類
@Override
public Statement apply(final Statement base, Description description) {
return new Statement() {
@Override
public void evaluate() throws Throwable {
WeldContainer container = weld.initialize();
context.setBeanManager(container.getBeanManager());
try {
base.evaluate();
} finally {
container.shutdown();
context.unsetBeanManager();
}
}
};
}
示例5: start
import org.jboss.weld.environment.se.WeldContainer; //導入依賴的package包/類
@Override
public void start(Stage initStage) throws Exception {
final Stage primaryStage = new Stage(StageStyle.DECORATED);
Task<ObservableValue<Stage>> mainStageTask = new Task<ObservableValue<Stage>>() {
@Override
protected ObservableValue<Stage> call() throws Exception {
Weld weld = new Weld();
WeldContainer container = weld.initialize(); // Initialize Weld CDI
primaryStage.setTitle("StudyGuide");
primaryStage.setOnCloseRequest(event -> {
logger.debug("Closing down Weld.");
weld.shutdown();
});
primaryStage.getIcons().add(new Image(StudyGuideApplication.class.getResourceAsStream(logoResource)));
container.event().select(Stage.class, new AnnotationLiteral<StartupStage>() {
}).fire(primaryStage);
return new ReadOnlyObjectWrapper<>(primaryStage);
}
};
mainStageTask.exceptionProperty().addListener((observable, oldValue, newValue) -> {
Platform.runLater(() -> {
throw new IllegalStateException("Main stage loading failed.", newValue);
});
});
showSplashScreen(initStage, mainStageTask);
}
示例6: createNestedInjector
import org.jboss.weld.environment.se.WeldContainer; //導入依賴的package包/類
@Nonnull
@Override
public Injector<WeldContainer> createNestedInjector(final @Nonnull String name, @Nonnull Iterable<Binding<?>> bindings) {
requireNonBlank(name, "Argument 'name' cannot be blank");
requireNonNull(bindings, "Argument 'bindings' cannot be null");
if (isClosed()) {
throw new ClosedInjectorException(this);
}
/*
final InjectorProvider injectorProvider = new InjectorProvider();
WeldInjector injector = new WeldInjector(delegate.createChildInjector(moduleFromBindings(bindings), new AbstractModule() {
@Override
protected void configure() {
bind(Injector.class)
.annotatedWith(new NamedImpl(name))
.toProvider(guicify(injectorProvider));
}
}));
injectorProvider.setInjector(injector);
return injector;
*/
return null;
}
示例7: main
import org.jboss.weld.environment.se.WeldContainer; //導入依賴的package包/類
public static void main(String[] args) {
disableLogging();
SystemAccess system = new RealSystemAccess();
new MigrationTool(new ExternalMigrationService(system),
new ToolConfig.DefaultFactory(),
system,
() -> {
/*
* Work around log4j-api message printed from missing configuration.
*/
PrintStream err = System.err;
// System.setErr(new PrintStream(new NullOutputStream()));
try {
WeldContainer container = new Weld().initialize();
return container;
} finally {
System.setErr(err);
}
}).run(args);
}
示例8: migrateAndExit
import org.jboss.weld.environment.se.WeldContainer; //導入依賴的package包/類
private void migrateAndExit(Path niogitDir) {
int exitStatus = 0;
WeldContainer container = null;
try {
container = containerFactory.get();
InternalMigrationService internalService = loadInternalService(container);
internalService.migrateAllProjects(niogitDir);
} catch (Throwable t) {
exitStatus = 1;
t.printStackTrace(system.err());
} finally {
if (container != null && container.isRunning()) {
quietShutdown(container);
}
}
system.exit(exitStatus);
}
示例9: initWeld
import org.jboss.weld.environment.se.WeldContainer; //導入依賴的package包/類
WeldContainer initWeld(Object testInstance) {
Weld weld = WeldInitiator.this.weld;
if (weld == null) {
weld = createWeld().addPackage(false, testInstance.getClass());
}
// this ensures the test instance is always an InjectionTarget
instancesToInject.add(createToInject(testInstance));
return initWeldContainer(weld);
}
示例10: first
import org.jboss.weld.environment.se.WeldContainer; //導入依賴的package包/類
@Test
public void first() {
if (containerId == null) {
containerId = WeldContainer.current().getId();
} else {
Assertions.assertEquals(containerId, WeldContainer.current().getId());
}
}
示例11: second
import org.jboss.weld.environment.se.WeldContainer; //導入依賴的package包/類
@Test
public void second() {
if (containerId == null) {
containerId = WeldContainer.current().getId();
} else {
Assertions.assertEquals(containerId, WeldContainer.current().getId());
}
}
示例12: main
import org.jboss.weld.environment.se.WeldContainer; //導入依賴的package包/類
public static void main(String[] args) throws Exception {
Weld weld = new Weld();
WeldContainer container = weld.initialize();
TextUI textUI = container.instance().select(TextUI.class).get();
printBanner();
textUI.start();
}
示例13: bootstrapWeldContainer
import org.jboss.weld.environment.se.WeldContainer; //導入依賴的package包/類
@Test
public void bootstrapWeldContainer() {
Weld weld = new Weld();
try (WeldContainer container = weld.initialize()) {
Greeter greeter = container.select(Greeter.class).get();
assertTrue(greeter != null);
}
}
示例14: bootWeldSeContainer
import org.jboss.weld.environment.se.WeldContainer; //導入依賴的package包/類
@Test(expected = UnsatisfiedResolutionException.class)
public void bootWeldSeContainer() {
Extension testExtension = ContainerLifecycleObserver.extensionBuilder()
.add(afterBeanDiscovery((e) -> System.out.println("Bean discovery completed!")))
.add(processAnnotatedType().notify((e) -> {
if (e.getAnnotatedType().getJavaClass().getName().startsWith("com.hantsylab")) {
e.veto();
}
})).build();
try (WeldContainer container = new Weld().addExtension(testExtension).initialize()) {
Greeter greeter = container.select(Greeter.class).get();
//assertTrue(greeter == null);
}
}
示例15: testCommandContextActivatedManually
import org.jboss.weld.environment.se.WeldContainer; //導入依賴的package包/類
@Test
public void testCommandContextActivatedManually() {
try (WeldContainer container = new Weld()
// Disable discovery completely
.disableDiscovery()
// Add command context implementation, decorator is enabled globally/automatically
.packages(CommandContext.class)
// Add bean classes manually
.beanClasses(DummyService.class, IdService.class, TestCommand.class)
// Add command extension manually so that we don't need to create META-INF/...
.addExtension(new CommandExtension()).initialize()) {
// Command cotext is activated/deactivated manually
CommandContext ctx = container.select(CommandContext.class).get();
try {
ctx.activate();
// Note that we actually don't even need to execute any command...
// Use programmatic lookup to simulate @Inject IdService
String id1 = container.select(IdService.class).get().getId();
String id2 = container.select(IdService.class).get().getId();
assertEquals(id1, id2);
} finally {
ctx.deactivate();
}
}
}