Java Code Examples for org.apache.cxf.jaxrs.utils.InjectionUtils#invokeLifeCycleMethod()

The following examples show how to use org.apache.cxf.jaxrs.utils.InjectionUtils#invokeLifeCycleMethod() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SingletonResourceProvider.java    From cxf with Apache License 2.0 6 votes vote down vote up
public void init(Endpoint ep) {
    if (resourceInstance instanceof Constructor) {
        Constructor<?> c = (Constructor<?>)resourceInstance;
        Message m = new MessageImpl();
        ExchangeImpl exchange = new ExchangeImpl();
        exchange.put(Endpoint.class, ep);
        m.setExchange(exchange);
        Object[] values = 
            ResourceUtils.createConstructorArguments(c, m, false, Collections.emptyMap());
        try {
            resourceInstance = values.length > 0 ? c.newInstance(values) : c.newInstance(new Object[]{});
        } catch (Exception ex) {
            throw new ServiceConstructionException(ex);
        }
    }
    if (callPostConstruct) {
        InjectionUtils.invokeLifeCycleMethod(resourceInstance,
            ResourceUtils.findPostConstructMethod(ClassHelper.getRealClass(resourceInstance)));
    }    
}
 
Example 2
Source File: CdiResourceProvider.java    From tomee with Apache License 2.0 6 votes vote down vote up
protected void doInit() throws OpenEJBException {
    injector = new InjectionProcessor<>(instance, new ArrayList<>(injections), InjectionProcessor.unwrap(context));
    instance = injector.createInstance();

    final BeanManager bm = webbeansContext == null ? null : webbeansContext.getBeanManagerImpl();
    if (bm != null) {
        creationalContext = bm.createCreationalContext(null);

        try {
            OWBInjector.inject(bm, instance, creationalContext);
        } catch (final Exception e) {
            // ignored
        }
    }

    // injector.postConstruct(); // it doesn't know it
    InjectionUtils.invokeLifeCycleMethod(instance, postConstructMethod);
}
 
Example 3
Source File: BlueprintResourceFactory.java    From cxf with Apache License 2.0 5 votes vote down vote up
public Object getInstance(Message m) {
    //TODO -- This is not the BP way.
    ProviderInfo<?> application = m == null ? null
        : (ProviderInfo<?>)m.getExchange().getEndpoint().get(Application.class.getName());
    Map<Class<?>, Object> mapValues = CastUtils.cast(application == null ? null
        : Collections.singletonMap(Application.class, application.getProvider()));
    Object[] values = ResourceUtils.createConstructorArguments(c, m, !isSingleton(), mapValues);
    //TODO Very springish...
    Object instance = values.length > 0 ? blueprintContainer.getComponentInstance(beanId)
        : blueprintContainer.getComponentInstance(beanId);
    if (!isSingleton() || m == null) {
        InjectionUtils.invokeLifeCycleMethod(instance, postConstructMethod);
    }
    return instance;
}
 
Example 4
Source File: CdiResourceProvider.java    From tomee with Apache License 2.0 5 votes vote down vote up
@Override
public void release() {
    // we can't give it to the injector so let's do it manually
    try {
        InjectionUtils.invokeLifeCycleMethod(instance, preDestroyMethod);
    } finally {
        if (injector != null) {
            injector.preDestroy();
        }
        if (creationalContext != null) {
            creationalContext.release();
        }
    }
}
 
Example 5
Source File: PerRequestResourceProvider.java    From cxf with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void releaseInstance(Message m, Object o) {
    InjectionUtils.invokeLifeCycleMethod(o, preDestroyMethod);
}
 
Example 6
Source File: SpringResourceFactory.java    From cxf with Apache License 2.0 4 votes vote down vote up
protected void initInstance(Message m, Object instance) {
    if (isCallPostConstruct()) {
        InjectionUtils.invokeLifeCycleMethod(ClassHelper.getRealObject(instance), postConstructMethod);
    }
}
 
Example 7
Source File: SpringResourceFactory.java    From cxf with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void releaseInstance(Message m, Object o) {
    if (doCallPreDestroy()) {
        InjectionUtils.invokeLifeCycleMethod(o, preDestroyMethod);
    }
}
 
Example 8
Source File: BlueprintResourceFactory.java    From cxf with Apache License 2.0 4 votes vote down vote up
public void releaseInstance(Message m, Object o) {
    if (!isSingleton()) {
        InjectionUtils.invokeLifeCycleMethod(o, preDestroyMethod);
    }
}