当前位置: 首页>>代码示例>>Java>>正文


Java BeanProvider类代码示例

本文整理汇总了Java中org.apache.deltaspike.core.api.provider.BeanProvider的典型用法代码示例。如果您正苦于以下问题:Java BeanProvider类的具体用法?Java BeanProvider怎么用?Java BeanProvider使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


BeanProvider类属于org.apache.deltaspike.core.api.provider包,在下文中一共展示了BeanProvider类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: execute

import org.apache.deltaspike.core.api.provider.BeanProvider; //导入依赖的package包/类
/**
 * Executes the pipeline stage with the given pipeline context and returns the result.
 * <p>
 * Invokes the prepare method on the stage and returns the result. The stage is invoked in it's own transaction. If an exception is caught the transaction is rolled back and the stage is marked
 * as FAILED.
 * </p>
 *
 * @param pipelineContext
 *         the pipeline context
 * @param pipelineStage
 *         the pipeline stage class
 * @return a {@link PipelineStageResult}
 */
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public PipelineStageResult execute(PipelineContext pipelineContext, Class<PipelineStage> pipelineStage) {
    DependentProvider<PipelineStage> dependentProvider = null;
    try {
        logBefore(pipelineContext, pipelineStage, "preparing");
        dependentProvider = BeanProvider.getDependent(pipelineStage);
        PipelineStageResult result = dependentProvider.get().prepare(pipelineContext);
        logAfter(pipelineContext, pipelineStage, result);
        return result;
    } catch (Exception e) {
        ejbContext.setRollbackOnly();

        String message = "Pipeline execution failed at stage " + pipelineStage.getName() + ". Reason " + e.getMessage();
        LOGGER.error(message, e);
        return PipelineStageResult.builder(pipelineContext.getPipelineId(), PipelineStageStatus.FAILED).addMessages(ImmutableSet.of(message)).build();
    } finally {
        if (dependentProvider != null) {
            dependentProvider.destroy();
        }
    }
}
 
开发者ID:projectomakase,项目名称:omakase,代码行数:35,代码来源:PipelineStageExecutor.java

示例2: onCallback

import org.apache.deltaspike.core.api.provider.BeanProvider; //导入依赖的package包/类
/**
 * Executes the pipeline stage with the given pipeline context and callback event before returning the result.
 * <p>
 * Invoke the callback method on the stage and returns the result. The stage is invoked in it's own transaction. If an exception is caught the transaction is rolled back and the stage is marked
 * as FAILED.
 * </p>
 *
 * @param pipelineContext
 *         the pipeline context
 * @param pipelineStage
 *         the pipeline stage
 * @param callbackEvent
 *         the callback event
 * @return a {@link PipelineStageResult}
 */
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public PipelineStageResult onCallback(PipelineContext pipelineContext, Class<PipelineStage> pipelineStage, CallbackEvent callbackEvent) {
    DependentProvider<PipelineStage> dependentProvider = null;
    try {
        logBefore(pipelineContext, pipelineStage, "resuming");
        dependentProvider = BeanProvider.getDependent(pipelineStage);
        PipelineStageResult result = dependentProvider.get().onCallback(pipelineContext, callbackEvent);
        logAfter(pipelineContext, pipelineStage, result);
        return result;
    } catch (Exception e) {
        ejbContext.setRollbackOnly();

        String message = "Pipeline execution failed at stage " + pipelineStage.getName() + ". Reason " + e.getMessage();
        LOGGER.error(message, e);
        return PipelineStageResult.builder(pipelineContext.getPipelineId(), PipelineStageStatus.FAILED).addMessages(ImmutableSet.of(message)).build();
    } finally {
        if (dependentProvider != null) {
            dependentProvider.destroy();
        }
    }
}
 
开发者ID:projectomakase,项目名称:omakase,代码行数:37,代码来源:PipelineStageExecutor.java

示例3: onFailure

import org.apache.deltaspike.core.api.provider.BeanProvider; //导入依赖的package包/类
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public void onFailure(PipelineContext pipelineContext, Class<PipelineFailureStage> pipelineFailureStage) {
    DependentProvider<PipelineFailureStage> dependentProvider = null;
    try {
        LOGGER.debug("executing pipeline failure stage " + pipelineFailureStage.getName());
        dependentProvider = BeanProvider.getDependent(pipelineFailureStage);
        dependentProvider.get().onFailure(pipelineContext);
        LOGGER.debug("executed pipeline failure stage " + pipelineFailureStage.getName());
    } catch (Exception e) {
        ejbContext.setRollbackOnly();
        String message = "Failed to execute pipeline failure stage " + pipelineFailureStage.getName() + ". Reason " + e.getMessage();
        LOGGER.error(message, e);

    } finally {
        if (dependentProvider != null) {
            dependentProvider.destroy();
        }
    }
}
 
开发者ID:projectomakase,项目名称:omakase,代码行数:20,代码来源:PipelineStageExecutor.java

示例4: should_hit_cache

import org.apache.deltaspike.core.api.provider.BeanProvider; //导入依赖的package包/类
@Test
public void should_hit_cache() {

    CacheableService service = BeanProvider.getContextualReference(CacheableService.class);

    assertThat(service.get(1L, "1st call")).isEqualTo("1 1st call");
    assertThat(service.get(2L, "1st call")).isEqualTo("2 1st call");
    assertThat(service.get(1L, "2nd call")).isEqualTo("1 1st call");
    assertThat(service.get(1L, "3rd call")).isEqualTo("1 1st call");
    assertThat(service.get(2L, "2nd call")).isEqualTo("2 1st call");

    CallCounter callCounter = BeanProvider.getContextualReference(CallCounter.class);
    assertThat(callCounter.calls()).isEqualTo(2);

    service.removeAll();
    callCounter.reset();
}
 
开发者ID:gpein,项目名称:jcache-jee7,代码行数:18,代码来源:JCacheTest.java

示例5: should_evict_cache

import org.apache.deltaspike.core.api.provider.BeanProvider; //导入依赖的package包/类
@Test
public void should_evict_cache() {

    CacheableService service = BeanProvider.getContextualReference(CacheableService.class);

    assertThat(service.get(1L, "1st call")).isEqualTo("1 1st call");
    assertThat(service.get(1L, "2nd call")).isEqualTo("1 1st call");
    assertThat(service.get(2L, "1st call")).isEqualTo("2 1st call");

    service.update(1L, "update");

    assertThat(service.get(1L, "3rd call")).isEqualTo("1 3rd call");
    assertThat(service.get(2L, "2nd call")).isEqualTo("2 1st call");

    CallCounter callCounter = BeanProvider.getContextualReference(CallCounter.class);
    assertThat(callCounter.calls()).isEqualTo(3);

    service.removeAll();
    callCounter.reset();
}
 
开发者ID:gpein,项目名称:jcache-jee7,代码行数:21,代码来源:JCacheTest.java

示例6: setUp

import org.apache.deltaspike.core.api.provider.BeanProvider; //导入依赖的package包/类
@Before
public final void setUp() throws Exception {
    System.out.printf("AbstractCdiContainerTest#setUp() containerRefCount=%d, cdiContainer=%s\n", containerRefCount.get(), cdiContainer );

    if ( cdiContainer != null ) {
        containerRefCount.incrementAndGet();

        final ContextControl ctxCtrl = BeanProvider.getContextualReference(ContextControl.class);

        //stop the RequestContext to dispose of the @RequestScoped EntityManager
        ctxCtrl.stopContext(RequestScoped.class);

        //immediately restart the context again
        ctxCtrl.startContext(RequestScoped.class);

        // perform injection into the very own test class
        final BeanManager beanManager = cdiContainer.getBeanManager();
        final CreationalContext creationalContext = beanManager.createCreationalContext(null);

        final AnnotatedType annotatedType = beanManager.createAnnotatedType(this.getClass());
        final InjectionTarget injectionTarget = beanManager.createInjectionTarget(annotatedType);
        injectionTarget.inject(this, creationalContext);
    }
}
 
开发者ID:peterpilgrim,项目名称:javaee7-developer-handbook,代码行数:25,代码来源:AbstractCdiContainerTest.java

示例7: tearDown

import org.apache.deltaspike.core.api.provider.BeanProvider; //导入依赖的package包/类
@After
    public final void tearDown() throws Exception {
        System.out.printf("AbstractCdiContainerTest#tearDown() containerRefCount=%d, cdiContainer=%s\n", containerRefCount.get(), cdiContainer );
        if (cdiContainer != null) {
            final ContextControl ctxCtrl = BeanProvider.getContextualReference(ContextControl.class);

            //stop the RequestContext to dispose of the @RequestScoped EntityManager
            ctxCtrl.stopContext(RequestScoped.class);

            //immediately restart the context again
            ctxCtrl.startContext(RequestScoped.class);

//            cdiContainer.getContextControl().stopContext(RequestScoped.class);
//            cdiContainer.getContextControl().startContext(RequestScoped.class);
            containerRefCount.decrementAndGet();
        }
    }
 
开发者ID:peterpilgrim,项目名称:javaee7-developer-handbook,代码行数:18,代码来源:AbstractCdiContainerTest.java

示例8: createTest

import org.apache.deltaspike.core.api.provider.BeanProvider; //导入依赖的package包/类
@Override
protected Object createTest() throws Exception
{
    BeanManager beanManager = BeanManagerProvider.getInstance().getBeanManager();

    Class<?> type = getTestClass().getJavaClass();
    Set<Bean<?>> beans = beanManager.getBeans(type);

    Object result;
    if (!USE_TEST_CLASS_AS_CDI_BEAN || beans == null || beans.isEmpty())
    {
        result = super.createTest();
        BeanProvider.injectFields(result); //fallback to simple injection
    }
    else
    {
        Bean<Object> bean = (Bean<Object>) beanManager.resolve(beans);
        CreationalContext<Object> creationalContext = beanManager.createCreationalContext(bean);
        result = beanManager.getReference(bean, type, creationalContext);
    }
    return result;
}
 
开发者ID:apache,项目名称:deltaspike,代码行数:23,代码来源:CdiTestRunner.java

示例9: produce

import org.apache.deltaspike.core.api.provider.BeanProvider; //导入依赖的package包/类
@Override
public T produce(CreationalContext<T> creationalContext)
{
    DynamicMockManager mockManager =
        BeanProvider.getContextualReference(this.beanManager, DynamicMockManager.class, false);

    for (Type beanType : this.beanTypes)
    {
        Object mockInstance = mockManager.getMock(
            (Class)beanType, this.qualifiers.toArray(new Annotation[this.qualifiers.size()]));

        if (mockInstance != null)
        {
            return (T)mockInstance;
        }
    }

    return wrapped.produce(creationalContext);
}
 
开发者ID:apache,项目名称:deltaspike,代码行数:20,代码来源:MockAwareProducerWrapper.java

示例10: finalCheck

import org.apache.deltaspike.core.api.provider.BeanProvider; //导入依赖的package包/类
@AfterClass
public static void finalCheck()
{
    int value = BeanProvider.getContextualReference(ApplicationScopedTestBean.class).getValue();
    int nextValue = BeanProvider.getContextualReference(ApplicationScopedTestBeanClient.class).getNextValue();

    if (value == 0)
    {
        throw new IllegalStateException("new application-scoped bean instance was created");
    }

    if (nextValue == 1)
    {
        throw new IllegalStateException("new application-scoped bean instance was created");
    }
}
 
开发者ID:apache,项目名称:deltaspike,代码行数:17,代码来源:ApplicationScopedBeanTest.java

示例11: injectionViaConfigProperty

import org.apache.deltaspike.core.api.provider.BeanProvider; //导入依赖的package包/类
@Test
public void injectionViaConfigProperty()
{
    SettingsBean settingsBean = BeanProvider.getContextualReference(SettingsBean.class, false);

    assertEquals(14, settingsBean.getProperty1());
    assertEquals(7L, settingsBean.getProperty2());
    assertEquals(-7L, settingsBean.getInverseProperty2());

    // also check the ones with defaultValue
    assertEquals("14", settingsBean.getProperty3Filled());
    assertEquals("myDefaultValue", settingsBean.getProperty3Defaulted());
    assertEquals(42, settingsBean.getProperty4Defaulted());

    assertEquals("some setting for prodDB", settingsBean.getDbConfig());
}
 
开发者ID:apache,项目名称:deltaspike,代码行数:17,代码来源:InjectableConfigPropertyTest.java

示例12: finalCheckAndCleanup

import org.apache.deltaspike.core.api.provider.BeanProvider; //导入依赖的package包/类
@AfterClass
public static void finalCheckAndCleanup()
{
    int testCount = TestUtils.getTestMethodCount(SessionScopePerTestClassTest.class);

    if (RequestScopedBean.getInstanceCount() != testCount)
    {
        throw new IllegalStateException("unexpected instance count");
    }
    RequestScopedBean.resetInstanceCount();

    if (BeanProvider.getContextualReference(ApplicationScopedBean.class).getCount() != testCount)
    {
        throw new IllegalStateException("unexpected count");
    }

    if (BeanProvider.getContextualReference(SessionScopedBean.class).getCount() != testCount)
    {
        throw new IllegalStateException("unexpected count");
    }
    BeanProvider.getContextualReference(ApplicationScopedBean.class).resetCount();
}
 
开发者ID:apache,项目名称:deltaspike,代码行数:23,代码来源:SessionScopePerTestClassTest.java

示例13: invocationOfMultipleSecuredStereotypes

import org.apache.deltaspike.core.api.provider.BeanProvider; //导入依赖的package包/类
@Test
public void invocationOfMultipleSecuredStereotypes()
{
    SecuredBean4 testBean = BeanProvider.getContextualReference(SecuredBean4.class, false);

    TestAccessDecisionVoter1 voter1 = BeanProvider.getContextualReference(TestAccessDecisionVoter1.class, false);
    TestAccessDecisionVoter2 voter2 = BeanProvider.getContextualReference(TestAccessDecisionVoter2.class, false);

    Assert.assertFalse(voter1.isCalled());
    Assert.assertFalse(voter2.isCalled());

    Assert.assertEquals("result", testBean.getResult());

    Assert.assertTrue(voter1.isCalled());
    Assert.assertTrue(voter2.isCalled());
}
 
开发者ID:apache,项目名称:deltaspike,代码行数:17,代码来源:SecuredAnnotationTest.java

示例14: doGet

import org.apache.deltaspike.core.api.provider.BeanProvider; //导入依赖的package包/类
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
{

    /*
     * The ServletObjectInjectionBean is manually looked up using BeanProvider because not all containers may
     * support injection into servlets.
     */
    ServletObjectInjectionBean bean =
            BeanProvider.getContextualReference(ServletObjectInjectionBean.class);

    ServletOutputStream stream = resp.getOutputStream();
    logDetails(stream, "ServletRequest", bean.getServletRequest());
    logDetails(stream, "HttpServletRequest", bean.getHttpServletRequest());
    logDetails(stream, "ServletResponse", bean.getServletResponse());
    logDetails(stream, "HttpServletResponse", bean.getHttpServletResponse());
    logDetails(stream, "HttpSession", bean.getHttpSession());
    logDetails(stream, "Principal", bean.getPrincipal());

}
 
开发者ID:apache,项目名称:deltaspike,代码行数:21,代码来源:ServletObjectInjectionServlet.java

示例15: notify

import org.apache.deltaspike.core.api.provider.BeanProvider; //导入依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public void notify(final ExceptionEvent<T> event, BeanManager beanManager) throws Exception
{
    CreationalContext<?> ctx = null;
    try
    {
        ctx = beanManager.createCreationalContext(null);
        @SuppressWarnings("unchecked")
        Object handlerInstance = BeanProvider.getContextualReference(declaringBeanClass);
        InjectableMethod<?> im = createInjectableMethod(handler, getDeclaringBean(), beanManager);
        im.invoke(handlerInstance, ctx, new OutboundParameterValueRedefiner(event, this));
    }
    finally
    {
        if (ctx != null)
        {
            ctx.release();
        }
    }
}
 
开发者ID:apache,项目名称:deltaspike,代码行数:24,代码来源:HandlerMethodImpl.java


注:本文中的org.apache.deltaspike.core.api.provider.BeanProvider类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。