类javax.enterprise.inject.InjectionException源码实例Demo

下面列出了怎么用javax.enterprise.inject.InjectionException的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: tomee   文件: CdiResourceProvider.java
public CdiResourceProvider(final ClassLoader loader, final Class<?> clazz, final Collection<Injection> injectionCollection, final Context initialContext, final WebBeansContext owbCtx) {
    injections = injectionCollection;
    webbeansContext = owbCtx;
    classLoader = loader;
    context = (Context) Proxy.newProxyInstance(classLoader, new Class<?>[]{Context.class}, new InitialContextWrapper(initialContext));

    postConstructMethod = ResourceUtils.findPostConstructMethod(clazz);
    preDestroyMethod = ResourceUtils.findPreDestroyMethod(clazz);

    bm = webbeansContext == null ? null : webbeansContext.getBeanManagerImpl();
    this.clazz = clazz;
    if (bm != null && bm.isInUse()) {
        try {
            final Set<Bean<?>> beans = bm.getBeans(clazz);
            bean = bm.resolve(beans);
        } catch (final InjectionException ie) {
            final String msg = "Resource class " + clazz.getName() + " can not be instantiated";
            throw new WebApplicationException(Response.serverError().entity(msg).build());
        }

        if (bean != null && bm.isNormalScope(bean.getScope())) {
            // singleton is faster
            normalScopeCreator = new ProvidedInstanceBeanCreator(bm.getReference(bean, bean.getBeanClass(), bm.createCreationalContext(bean)));
        } else {
            normalScopeCreator = null;
            validateConstructorExists();
        }
    } else {
        bean = null;
        normalScopeCreator = null;
        validateConstructorExists();
    }

    findContexts(clazz);
}
 
源代码2 项目: tomee   文件: CdiResourceProvider.java
@Override
public Object create() {
    try {
        toClean = bm.createCreationalContext(bean);
        return bm.getReference(bean, bean.getBeanClass(), toClean);
    } catch (final InjectionException ie) {
        final String msg = "Failed to instantiate: " + bean;
        Logger.getInstance(LogCategory.OPENEJB_CDI, this.getClass()).error(msg, ie);
        throw new WebApplicationException(Response.serverError().entity(msg).build());
    }
}
 
源代码3 项目: deltaspike   文件: ExceptionControlExtension.java
/**
 * Verifies all injection points for every handler are valid.
 *
 * @param afterDeploymentValidation Lifecycle event
 * @param bm  BeanManager instance
 */
@SuppressWarnings("UnusedDeclaration")
public void verifyInjectionPoints(@Observes final AfterDeploymentValidation afterDeploymentValidation,
                                  final BeanManager bm)
{
    if (!isActivated)
    {
        return;
    }

    for (Map.Entry<Type, Collection<HandlerMethod<? extends Throwable>>> entry : allHandlers.entrySet())
    {
        for (HandlerMethod<? extends Throwable> handler : entry.getValue())
        {
            for (InjectionPoint ip : ((HandlerMethodImpl<? extends Throwable>) handler).getInjectionPoints(bm))
            {
                try
                {
                    bm.validate(ip);
                }
                catch (InjectionException e)
                {
                    afterDeploymentValidation.addDeploymentProblem(e);
                }
            }
        }
    }
}
 
源代码4 项目: tomee   文件: HandlerResolverImpl.java
private List<Handler> buildHandlers(final PortInfo portInfo, final HandlerChainData handlerChain) {
    if (!matchServiceName(portInfo, handlerChain.getServiceNamePattern()) ||
        !matchPortName(portInfo, handlerChain.getPortNamePattern()) ||
        !matchBinding(portInfo, handlerChain.getProtocolBindings())) {
        return Collections.emptyList();
    }

    final List<Handler> handlers = new ArrayList<>(handlerChain.getHandlers().size());
    for (final HandlerData handler : handlerChain.getHandlers()) {
        final WebBeansContext webBeansContext = AppFinder.findAppContextOrWeb(
                Thread.currentThread().getContextClassLoader(), AppFinder.WebBeansContextTransformer.INSTANCE);
        if (webBeansContext != null) { // cdi
            final BeanManagerImpl bm = webBeansContext.getBeanManagerImpl();
            if (bm.isInUse()) {
                try {
                    final Set<Bean<?>> beans = bm.getBeans(handler.getHandlerClass());
                    final Bean<?> bean = bm.resolve(beans);
                    if (bean != null) { // proxy so faster to do it
                        final boolean normalScoped = bm.isNormalScope(bean.getScope());
                        final CreationalContextImpl<?> creationalContext = bm.createCreationalContext(bean);
                        final Handler instance = Handler.class.cast(bm.getReference(bean, bean.getBeanClass(), creationalContext));

                        // hack for destroyHandlers()
                        handlers.add(instance);
                        handlerInstances.add(new InjectionProcessor<Handler>(instance, Collections.<Injection>emptySet(), null) {
                            @Override
                            public void preDestroy() {
                                if (!normalScoped) {
                                    creationalContext.release();
                                }
                            }
                        });
                        continue;
                    }
                } catch (final InjectionException ie) {
                    LOGGER.info(ie.getMessage(), ie);
                }
            }
        }

        try { // old way
            final Class<? extends Handler> handlerClass = handler.getHandlerClass().asSubclass(Handler.class);
            final InjectionProcessor<Handler> processor = new InjectionProcessor<>(handlerClass,
                injections,
                handler.getPostConstruct(),
                handler.getPreDestroy(),
                unwrap(context));
            processor.createInstance();
            processor.postConstruct();
            final Handler handlerInstance = processor.getInstance();

            handlers.add(handlerInstance);
            handlerInstances.add(processor);
        } catch (final Exception e) {
            throw new WebServiceException("Failed to instantiate handler", e);
        }
    }
    return handlers;
}