org.jboss.errai.ioc.client.container.IOC类的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(10.2k)|赞(0)|评价(0)|浏览(244)

本文整理了Java中org.jboss.errai.ioc.client.container.IOC类的一些代码示例,展示了IOC类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。IOC类的具体详情如下:
包路径:org.jboss.errai.ioc.client.container.IOC
类名称:IOC

IOC介绍

[英]A simple utility class which provides a static reference in the client to the bean manager.
[中]一个简单的实用程序类,它在客户端向bean管理器提供静态引用。

代码示例

代码示例来源:origin: org.drools/drools-wb-guided-rule-editor-client

WorkingSetManager getWorkingSetManager() {
  if (workingSetManager == null) {
    workingSetManager = IOC.getBeanManager().lookupBean(WorkingSetManager.class).getInstance();
  }
  return workingSetManager;
}

代码示例来源:origin: errai/errai

@IOCProducer
 public AsyncBeanManager get() {
  return IOC.getAsyncBeanManager();
 }
}

代码示例来源:origin: errai/errai

IOC.registerLifecycleListener(beanInstance, beanlifecycleListener);

代码示例来源:origin: errai/errai

@SuppressWarnings("unchecked")
public void testGetInstanceReturnsNullOutsideOfFireAsync() throws Exception {
 final Integer instance = 1337;
 final LifecycleListener<Integer> listener = new LifecycleListener<Integer>() {
  @Override
  public void observeEvent(final LifecycleEvent<Integer> event) {
   assertEquals(instance, event.getInstance());
  }
  @Override
  public boolean isObserveableEventType(Class<? extends LifecycleEvent<Integer>> eventType) {
   return true;
  }
 };
 IOC.registerLifecycleListener(instance, listener);
 final Access<Integer> event = IOC.getBeanManager().lookupBean(Access.class).getInstance();
 assertNull(event.getInstance());
 event.fireAsync(instance, new LifecycleCallback() {
  @Override
  public void callback(final boolean success) {
   assertNull(event.getInstance());
  }
 });
 assertNull(event.getInstance());
}

代码示例来源:origin: errai/errai

public void testDestroyingProducedBeanOfDependentScopedProducerUsingFieldInjectedManagedInstance() throws Exception {
 final OtherDestructableClass producedBean = getBeanManager().lookupBean(OtherDestructableClass.class, c).getInstance();
 assertFalse(producedBean.isDestroyed());
 getBeanManager().destroyBean(producedBean);
 assertTrue(producedBean.isDestroyed());
}

代码示例来源:origin: errai/errai

public void testProducerMethodOfJsType() throws Exception {
 final ConsumesProducedJsType consumer = IOC.getBeanManager().lookupBean(ConsumesProducedJsType.class).getInstance();
 assertNotNull(consumer.instance);
 assertTrue(consumer.instance instanceof ProducedJsType);
 assertEquals(1, IOC.getBeanManager().lookupBeans(ProducedJsType.class).size());
}

代码示例来源:origin: errai/errai

public void testDisposerFailsToDestroyAppScope() {
 final SingletonBeanWithDisposer outerBean = IOC.getBeanManager().lookupBean(SingletonBeanWithDisposer.class).getInstance();
 assertNotNull(outerBean);
 assertNotNull(outerBean.getDependentBeanDisposer());
 final DependentBean innerBean = outerBean.getBean();
 assertNotNull(innerBean);
 outerBean.dispose();
 assertFalse("inner bean should have been disposed", IOC.getBeanManager().isManaged(innerBean));
 assertTrue("outer bean should not have been disposed", IOC.getBeanManager().isManaged(outerBean));
 assertTrue("bean's destructor should have been called", innerBean.isPreDestroyCalled());
}

代码示例来源:origin: errai/errai

public void testBeanManagerInjectable() {
 final BeanManagerDependentBean bean = IOC.getBeanManager().lookupBean(BeanManagerDependentBean.class)
     .getInstance();
 final ClientBeanManager beanManager = (GWT.<IOCEnvironment>create(IOCEnvironment.class).isAsync() ? IOC.getAsyncBeanManager() : IOC.getBeanManager());
 assertSame(beanManager, Factory.maybeUnwrapProxy(bean.getBeanManager()));
}

代码示例来源:origin: errai/errai

public void testBeanActivator() {
 final TestBeanActivator activator = IOC.getBeanManager().lookupBean(TestBeanActivator.class).getInstance();
 activator.setActived(true);
 final SyncBeanDef<ActivatedBean> bean = IOC.getBeanManager().lookupBean(ActivatedBean.class);
 assertTrue(bean.isActivated());
 activator.setActived(false);
 assertFalse(bean.isActivated());
 final SyncBeanDef<ActivatedBeanInterface> qualifiedBean = IOC.getBeanManager().lookupBean(ActivatedBeanInterface.class);
 assertFalse(qualifiedBean.isActivated());
 activator.setActived(true);
 assertTrue(qualifiedBean.isActivated());
}

代码示例来源:origin: errai/errai

@SuppressWarnings("rawtypes")
public void testNoDuplicateJsTypeThroughBeanManager() {
 final WindowInjectionContext wndContext = WindowInjectionContextStorage.createOrGet();
 final Object bean1 = wndContext.getBean(JsTypeNamedBean.class.getName());
 assertNotNull("@JsType bean was not registered in window context", bean1);
 final Collection<SyncBeanDef> beans = IOC.getBeanManager().lookupBeans(JsTypeNamedBean.class.getName());
 assertEquals(1, beans.size());
 assertEquals("olaf", beans.iterator().next().getName());
 assertSame(bean1, beans.iterator().next().getInstance());
}

代码示例来源:origin: errai/errai

/**
 * Stops this sync worker if it is running.
 *
 * @throws IllegalStateException
 *           if this sync worker has not yet been started.
 */
public void stop() {
 if (!started)
  throw new IllegalStateException("This worker was never started");
 stopped = true;
 callbacks.clear();
 if (beanlifecycleListener != null && managedBeanInstance != null) {
  IOC.unregisterLifecycleListener(managedBeanInstance, beanlifecycleListener);
 }
 timer.cancel();
}

代码示例来源:origin: errai/errai

@SuppressWarnings("unchecked")
public void testUnregisterSingleInstanceListenerTwice() throws Exception {
 final Counter listenerCounter = new Counter();
 final LifecycleListener<Integer> listener = new CountingListener(listenerCounter);
 final Access<Integer> event = IOC.getBeanManager().lookupBean(Access.class).getInstance();
 final Integer instance = 1337;
 IOC.registerLifecycleListener(instance, listener);
 // Precondition
 assertEquals(0, listenerCounter.getValue());
 event.fireAsync(instance);
 assertEquals(1, listenerCounter.getValue());
 IOC.unregisterLifecycleListener(instance, listener);
 event.fireAsync(instance);
 assertEquals(1, listenerCounter.getValue());
 // Actual test
 try {
  IOC.unregisterLifecycleListener(instance, listener);
 }
 catch (Exception e) {
  fail("Second unregister call caused an exception: " + e.getMessage());
 }
}

代码示例来源:origin: errai/errai

public void testDisposerMethodCalledOnProviderWhenProvidedBeanIsDestroyed() throws Exception {
 final BeanWithProvidedBeansInjected module = IOC.getBeanManager().lookupBean(BeanWithProvidedBeansInjected.class).getInstance();
 assertFalse("Bean was prematurely destroyed.", module.providedBean.isDestroyed());
 IOC.getBeanManager().destroyBean(module.providedBean);
 assertTrue("Disposer method not called after bean was destroyed.", module.providedBean.isDestroyed());
}

代码示例来源:origin: errai/errai

public void testDisposerWorksWithDependentScope() {
 final DependentBeanWithDisposer outerBean = IOC.getBeanManager().lookupBean(DependentBeanWithDisposer.class).getInstance();
 assertNotNull(outerBean);
 assertNotNull(outerBean.getDependentBeanDisposer());
 final DependentBean innerBean = outerBean.getBean();
 assertNotNull(innerBean);
 outerBean.dispose();
 assertFalse("inner bean should have been disposed", IOC.getBeanManager().isManaged(innerBean));
 assertTrue("outer bean should not have been disposed", IOC.getBeanManager().isManaged(outerBean));
 assertTrue("inner bean's destructor should have been called", innerBean.isPreDestroyCalled());
}

代码示例来源:origin: errai/errai

public void testDependentScopeWithPrivateConstr() throws Exception {
 try {
  IOC.getBeanManager().lookupBean(DependentWithPrivateConstr.class).getInstance();
 } catch (final Throwable t) {
  throw new AssertionError("Could not create instance of bean with private constructor.", t);
 }
}

代码示例来源:origin: errai/errai

@SuppressWarnings("unchecked")
public void testUnregisterSingleInstanceListenerAfterDestruction() throws Exception {
 final Counter listenerCounter = new Counter();
 final LifecycleListener<Integer> listener = new CountingListener(listenerCounter);
 final SyncBeanManager bm = IOC.getBeanManager();
 final Access<Integer> event = bm.lookupBean(Access.class).getInstance();
 final Destruction<Integer> destruction = bm.lookupBean(Destruction.class).getInstance();
 final Integer instance = 1337;
 IOC.registerLifecycleListener(instance, listener);
 // Precondition
 assertEquals(0, listenerCounter.getValue());
 event.fireAsync(instance);
 assertEquals(1, listenerCounter.getValue());
 destruction.fireAsync(instance);
 event.fireAsync(instance);
 assertEquals(1, listenerCounter.getValue());
 // Actual test
 try {
  IOC.unregisterLifecycleListener(instance, listener);
 }
 catch (Exception e) {
  fail("Unregister call caused an exception: " + e.getMessage());
 }
}

代码示例来源:origin: errai/errai

public void testDisposerMethodCalledOnContextualProviderWhenProvidedBeanIsDestroyed() throws Exception {
  final BeanWithProvidedBeansInjected module = IOC.getBeanManager().lookupBean(BeanWithProvidedBeansInjected.class).getInstance();
  assertFalse("Bean was prematurely destroyed.", module.contextuallyProvidedBean.isDestroyed());
  IOC.getBeanManager().destroyBean(module.contextuallyProvidedBean);
  assertTrue("Disposer method not called after bean was destroyed.", module.contextuallyProvidedBean.isDestroyed());
 }
}

代码示例来源:origin: errai/errai

@Override
 protected void destroyProviderInstance(final RequiredRolesProvider instance) {
  if (dependentProviders.contains(instance)) {
   dependentProviders.remove(instance);
   IOC.getAsyncBeanManager().destroyBean(instance);
  }
 }
}

代码示例来源:origin: errai/errai

public void testTextBoxInjection() throws Exception {
 try {
  IOC.getBeanManager().lookupBean(ClassWithInjectedTextBox.class).getInstance();
 } catch (Throwable t) {
  throw new AssertionError("Could not create instance of type with injected TextBox.", t);
 }
}

代码示例来源:origin: errai/errai

@SuppressWarnings("unchecked")
public void testSingleLifecycleListenerIsCalled() {
 // Build listener and generator
 final Counter listenerCounter = new Counter();
 final LifecycleListener<Integer> listener = new CountingListener(listenerCounter);
 final LifecycleListenerGenerator<Integer> generator = new LifecycleListenerGenerator<Integer>() {
  @Override
  public LifecycleListener<Integer> newInstance() {
   return listener;
  }
 };
 // Build event
 final Integer instance = 1337;
 final Access<Integer> event = IOC.getBeanManager().lookupBean(Access.class).getInstance();
 // Register listener
 IOC.registerLifecycleListener(Integer.class, generator);
 // Precondition
 assertEquals(0, listenerCounter.getValue());
 final Counter callbackCounter = new Counter();
 event.fireAsync(instance, new LifecycleCallback() {
  @Override
  public void callback(boolean success) {
   assertTrue(success);
   callbackCounter.add(1);
  }
 });
 assertEquals(1, listenerCounter.getValue());
 assertEquals(1, callbackCounter.getValue());
}

相关文章