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


Java BeanProvider.injectFields方法代码示例

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


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

示例1: 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

示例2: mixedMocksWithInjection1

import org.apache.deltaspike.core.api.provider.BeanProvider; //导入方法依赖的package包/类
@Test
public void mixedMocksWithInjection1()
{
    SessionScopedBean mockedSessionScopedBean = mock(SessionScopedBean.class);
    when(mockedSessionScopedBean.getCount()).thenReturn(7);
    mockManager.addMock(mockedSessionScopedBean);

    RequestScopedBean mockedRequestScopedBean = new MockedRequestScopedBeanWithInjection();
    BeanProvider.injectFields(mockedRequestScopedBean);
    mockManager.addMock(mockedRequestScopedBean);

    Assert.assertEquals(7, requestScopedBean.getCount());
    requestScopedBean.increaseCount(); //not delegated
    Assert.assertEquals(7, requestScopedBean.getCount());
    sessionScopedBean.increaseCount();
    Assert.assertEquals(7, sessionScopedBean.getCount()); //still mocked
    Assert.assertEquals(7, requestScopedBean.getCount()); //still mocked
}
 
开发者ID:apache,项目名称:deltaspike,代码行数:19,代码来源:MockedRequestScopedBeanWithInjectionTest.java

示例3: mixedMocksWithInjection2

import org.apache.deltaspike.core.api.provider.BeanProvider; //导入方法依赖的package包/类
@Test
public void mixedMocksWithInjection2()
{
    SessionScopedBean mockedSessionScopedBean = mock(SessionScopedBean.class);
    when(mockedSessionScopedBean.getCount()).thenReturn(14);
    mockManager.addMock(mockedSessionScopedBean);

    RequestScopedBean mockedRequestScopedBean = new MockedRequestScopedBeanWithInjection();
    BeanProvider.injectFields(mockedRequestScopedBean);
    mockManager.addMock(mockedRequestScopedBean);

    Assert.assertEquals(14, requestScopedBean.getCount());
    requestScopedBean.increaseCount(); //not delegated
    Assert.assertEquals(14, requestScopedBean.getCount());
    sessionScopedBean.increaseCount();
    Assert.assertEquals(14, sessionScopedBean.getCount()); //still mocked
    Assert.assertEquals(14, requestScopedBean.getCount()); //still mocked
}
 
开发者ID:apache,项目名称:deltaspike,代码行数:19,代码来源:MockedRequestScopedBeanWithInjectionTest.java

示例4: evaluate

import org.apache.deltaspike.core.api.provider.BeanProvider; //导入方法依赖的package包/类
@Override
public void evaluate() throws Throwable
{
    BeanManager beanManager = BeanManagerProvider.getInstance().getBeanManager();
    Class<?> type = this.method.getMethod().getDeclaringClass();
    Set<Bean<?>> beans = beanManager.getBeans(type);

    if (!USE_TEST_CLASS_AS_CDI_BEAN || beans == null || beans.isEmpty())
    {
        if (!ALLOW_INJECTION_POINT_MANIPULATION)
        {
            BeanProvider.injectFields(this.originalTarget); //fallback to simple injection
        }
        invokeMethod(this.originalTarget);
    }
    else
    {
        Bean<Object> bean = (Bean<Object>) beanManager.resolve(beans);

        CreationalContext<Object> creationalContext = beanManager.createCreationalContext(bean);

        Object target = beanManager.getReference(bean, type, creationalContext);

        try
        {
            invokeMethod(target);
        }
        finally
        {
            if (bean.getScope().equals(Dependent.class))
            {
                bean.destroy(target, creationalContext);
            }
        }
    }
}
 
开发者ID:apache,项目名称:deltaspike,代码行数:37,代码来源:CdiTestRunner.java

示例5: manualMockWithInjection

import org.apache.deltaspike.core.api.provider.BeanProvider; //导入方法依赖的package包/类
@Test
public void manualMockWithInjection()
{
    RequestScopedBean mockedRequestScopedBean = new MockedRequestScopedBeanWithInjection();
    BeanProvider.injectFields(mockedRequestScopedBean);
    mockManager.addMock(mockedRequestScopedBean);

    Assert.assertEquals(0, requestScopedBean.getCount());
    requestScopedBean.increaseCount(); //not delegated
    Assert.assertEquals(0, requestScopedBean.getCount());
    sessionScopedBean.increaseCount();
    Assert.assertEquals(1, sessionScopedBean.getCount());
    Assert.assertEquals(1, requestScopedBean.getCount());
}
 
开发者ID:apache,项目名称:deltaspike,代码行数:15,代码来源:MockedRequestScopedBeanWithInjectionTest.java

示例6: restoreState

import org.apache.deltaspike.core.api.provider.BeanProvider; //导入方法依赖的package包/类
@Override
public void restoreState(FacesContext context, Object state)
{
    Object[] wrappedState = (Object[]) state;

    if (this.wrapped == null) //fallback for full state-saving
    {
        Class wrappedClass = ClassUtils.tryToLoadClassForName((String)wrappedState[0]);

        T resolvedInstance = resolveInstanceForClass(context, wrappedClass);

        //TODO re-visit logic for multiple (custom) wrappers
        if (resolvedInstance instanceof AbstractContextualReferenceWrapper)
        {
            resolvedInstance = ((AbstractContextualReferenceWrapper<T>)resolvedInstance).getWrapped();
        }
        this.wrapped = resolvedInstance;
    }

    if (this.wrapped == null)
    {
        this.wrapped = (T)ClassUtils.tryToInstantiateClassForName((String)wrappedState[0]);
        BeanProvider.injectFields(this.wrapped);
    }

    if (this.wrapped instanceof StateHolder)
    {
        ((StateHolder) this.wrapped).restoreState(context, wrappedState[1]);
    }
}
 
开发者ID:apache,项目名称:deltaspike,代码行数:31,代码来源:AbstractContextualReferenceWrapper.java

示例7: jobToBeExecuted

import org.apache.deltaspike.core.api.provider.BeanProvider; //导入方法依赖的package包/类
@Override
public void jobToBeExecuted(JobExecutionContext jobExecutionContext)
{
    Class<?> jobClass = ProxyUtils.getUnproxiedClass(jobExecutionContext.getJobInstance().getClass());
    Scheduled scheduled = jobClass.getAnnotation(Scheduled.class);

    //can happen with manually registered job-instances (via #unwrap)
    if (scheduled == null && !jobClass.equals(DynamicExpressionObserverJob.class))
    {
        scheduled = DEFAULT_SCHEDULED_LITERAL;
    }

    if (scheduled == null)
    {
        return;
    }

    JobListenerContext jobListenerContext = new JobListenerContext();
    currentJobListenerContext.set(jobListenerContext);
    jobListenerContext.startContexts(scheduled);

    boolean jobInstanceIsBean;

    try
    {
        jobInstanceIsBean =
            Boolean.TRUE.equals(jobExecutionContext.getScheduler().getContext().get(jobClass.getName()));
    }
    catch (SchedulerException e)
    {
        jobInstanceIsBean = false;
    }

    if (!jobInstanceIsBean)
    {
        BeanProvider.injectFields(jobExecutionContext.getJobInstance());
    }
}
 
开发者ID:apache,项目名称:deltaspike,代码行数:39,代码来源:AbstractQuartzScheduler.java

示例8: inject

import org.apache.deltaspike.core.api.provider.BeanProvider; //导入方法依赖的package包/类
public <T> T inject(T instance) {
	rc.initResource(instance);
	return BeanProvider.injectFields(instance);
}
 
开发者ID:Blazebit,项目名称:blaze-storage,代码行数:5,代码来源:AbstractResource.java

示例9: postRestart

import org.apache.deltaspike.core.api.provider.BeanProvider; //导入方法依赖的package包/类
@Override
public void postRestart(Throwable reason) {
    BeanProvider.injectFields(this);
}
 
开发者ID:csrinaldi,项目名称:powercode,代码行数:5,代码来源:AwareActor.java

示例10: preStart

import org.apache.deltaspike.core.api.provider.BeanProvider; //导入方法依赖的package包/类
@Override
public void preStart() {
    BeanProvider.injectFields(this);
}
 
开发者ID:csrinaldi,项目名称:powercode,代码行数:5,代码来源:AwareActor.java

示例11: execute

import org.apache.deltaspike.core.api.provider.BeanProvider; //导入方法依赖的package包/类
@Override
public void execute(JobExecutionContext context) throws JobExecutionException
{
    JobDataMap jobDataMap = context.getMergedJobDataMap();
    String configExpression = jobDataMap.getString(CONFIG_EXPRESSION_KEY);
    String triggerId = jobDataMap.getString(TRIGGER_ID_KEY);
    String activeCronExpression = jobDataMap.getString(ACTIVE_CRON_EXPRESSION_KEY);

    String configKey = configExpression.substring(1, configExpression.length() - 1);
    String configuredValue = ConfigResolver.getPropertyAwarePropertyValue(configKey, activeCronExpression);

    if (!activeCronExpression.equals(configuredValue))
    {
        //both #put calls are needed currently
        context.getJobDetail().getJobDataMap().put(ACTIVE_CRON_EXPRESSION_KEY, configuredValue);
        context.getTrigger().getJobDataMap().put(ACTIVE_CRON_EXPRESSION_KEY, configuredValue);

        BeanProvider.injectFields(this);

        JobKey observerJobKey = context.getJobDetail().getKey();
        String observedJobName = observerJobKey.getName()
            .substring(0, observerJobKey.getName().length() - OBSERVER_POSTFIX.length());
        JobKey observedJobKey = new JobKey(observedJobName, observerJobKey.getGroup());

        Trigger trigger = TriggerBuilder.newTrigger()
                .withIdentity(triggerId)
                .forJob(observedJobName, observedJobKey.getGroup())
                .withSchedule(CronScheduleBuilder.cronSchedule(configuredValue))
                .build();

        //use rescheduleJob instead of delete + add
        //(unwrap is ok here, because this class will only get active in case of a quartz-scheduler)
        org.quartz.Scheduler quartzScheduler = scheduler.unwrap(org.quartz.Scheduler.class);
        try
        {
            quartzScheduler.rescheduleJob(trigger.getKey(), trigger);
        }
        catch (SchedulerException e)
        {
            LOG.warning("failed to updated cron-expression for " + observedJobKey);
        }
    }
}
 
开发者ID:apache,项目名称:deltaspike,代码行数:44,代码来源:DynamicExpressionObserverJob.java

示例12: injectBeansInNonManagedInstance

import org.apache.deltaspike.core.api.provider.BeanProvider; //导入方法依赖的package包/类
@Test
public void injectBeansInNonManagedInstance() throws Exception
{
    ManualBean manualBean = new ManualBean();

    Assert.assertNull(manualBean.getTestBean());

    BeanProvider.injectFields(manualBean);

    Assert.assertNotNull(manualBean.getTestBean());

    Assert.assertEquals(4711, manualBean.getTestBean().getI());

    int newValue = 14;

    manualBean.getTestBean().setI(newValue);

    Assert.assertEquals(newValue, manualBean.getTestBean().getI());

    TestBean testBean = BeanProvider.getContextualReference(TestBean.class);

    Assert.assertEquals(newValue, testBean.getI());

    testBean.setI(4711); // reset the value if this test is executed first
}
 
开发者ID:apache,项目名称:deltaspike,代码行数:26,代码来源:BeanProviderTest.java


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