Java 类javax.enterprise.inject.CreationException 实例源码

项目:Camel    文件:XmlCdiBeanFactory.java   
private SyntheticBean<?> proxyFactoryBean(Bean<?> context, CamelProxyFactoryDefinition proxy, URL url) {
    if (isEmpty(proxy.getServiceRef()) && isEmpty(proxy.getServiceUrl())) {
        throw new CreationException(
            format("Missing [%s] or [%s] attribute for imported bean [%s] from resource [%s]",
                "serviceRef", "serviceUrl", proxy.getId(), url));
    }

    return new XmlProxyFactoryBean<>(manager,
        new SyntheticAnnotated(proxy.getServiceInterface(),
            manager.createAnnotatedType(proxy.getServiceInterface()).getTypeClosure(),
            APPLICATION_SCOPED, ANY, NamedLiteral.of(proxy.getId())),
        proxy.getServiceInterface(), bean ->
            "imported bean [" + proxy.getId() + "] "
            + "from resource [" + url + "] "
            + "with qualifiers " + bean.getQualifiers(),
        context, proxy);
}
项目:camel-cdi    文件:XmlErrorHandlerFactoryBean.java   
@Override
public ErrorHandlerBuilder create(CreationalContext<ErrorHandlerBuilder> creationalContext) {
    try {
        ErrorHandlerBuilder builder = handler.getType().getTypeAsClass().newInstance();

        switch (handler.getType()) {
            case DefaultErrorHandler:
            case DeadLetterChannel:
                setProperties((DefaultErrorHandlerBuilder) builder);
                break;
            case LoggingErrorHandler:
                setProperties((LoggingErrorHandlerBuilder) builder);
                break;
            case NoErrorHandler:
                // No configuration required
                break;
            case TransactionErrorHandler:
                break;
        }

        return builder;
    } catch (Exception cause) {
        throw new CreationException("Error while creating instance for " + this, cause);
    }
}
项目:confit    文件:LookupProvider.java   
public final <T> T lookup(Class<T> clazz) {
    if (!cdiEnabled) {
        return null;
    }
    try {
        // lookup first instance found
        return CDI.current().select(clazz).get();
    } catch (Exception e) {
        if (e instanceof CreationException) {
            throw e;
        }
        // may fail if CDI was not setup correctly
        // which is acceptable so return nothing..
        // fix: new Weld().initialize() at bootstrap
        return null;
    }
}
项目:confit    文件:LookupProvider.java   
@Override
public <T> Collection<T> lookupAll(Class<T> clazz) {
    if (!cdiEnabled) {
        return Lists.newArrayList();
    }
    // return all instances found
    try {
        if (clazz.getName().equals(RECURSION_SHORTCIRCUIT.get())) {
            return new ArrayList<>();
        } else {
            RECURSION_SHORTCIRCUIT.set(clazz.getName());
            return Lists.newArrayList(CDI.current().select(clazz));
        }
    } catch (Exception e) {
        if (e instanceof CreationException) {
            throw e;
        }
        // may fail if CDI was not setup correctly
        // which is acceptable so return nothing..
        // fix: new Weld().initialize() at bootstrap
        return new ArrayList<>();
    } finally {
        RECURSION_SHORTCIRCUIT.remove();
    }
}
项目:Camel    文件:XmlCdiBeanFactory.java   
private SyntheticBean<?> camelContextBean(CamelContextFactoryBean factory, URL url) {
    Set<Annotation> annotations = new HashSet<>();
    annotations.add(ANY);
    if (hasId(factory)) {
        addAll(annotations,
            ContextName.Literal.of(factory.getId()), NamedLiteral.of(factory.getId()));
    } else {
        annotations.add(DEFAULT);
        factory.setImplicitId(true);
        factory.setId(new CdiCamelContextNameStrategy().getNextName());
    }

    annotations.add(APPLICATION_SCOPED);
    SyntheticAnnotated annotated = new SyntheticAnnotated(DefaultCamelContext.class,
        manager.createAnnotatedType(DefaultCamelContext.class).getTypeClosure(),
        annotations);
    return new SyntheticBean<>(manager, annotated, DefaultCamelContext.class,
        environment.camelContextInjectionTarget(
            new SyntheticInjectionTarget<>(() -> {
                DefaultCamelContext context = new DefaultCamelContext();
                factory.setContext(context);
                factory.setBeanManager(manager);
                return context;
            }, context -> {
                try {
                    factory.afterPropertiesSet();
                } catch (Exception cause) {
                    throw new CreationException(cause);
                }
            }),
            annotated, manager, extension), bean ->
            "imported Camel context with "
            + (factory.isImplicitId() ? "implicit " : "")
            + "id [" + factory.getId() + "] "
            + "from resource [" + url + "] "
            + "with qualifiers " + bean.getQualifiers());
}
项目:Camel    文件:SyntheticBean.java   
@Override
public T create(CreationalContext<T> creationalContext) {
    try {
        T instance = target.produce(creationalContext);
        target.inject(instance, creationalContext);
        target.postConstruct(instance);
        return instance;
    } catch (Exception cause) {
        throw new CreationException("Error while instantiating " + this, cause);
    }
}
项目:Camel    文件:XmlErrorHandlerFactoryBean.java   
@Override
public ErrorHandlerBuilder create(CreationalContext<ErrorHandlerBuilder> creationalContext) {
    try {
        ErrorHandlerBuilder builder = handler.getType().getTypeAsClass().newInstance();

        switch (handler.getType()) {
        case DefaultErrorHandler:
        case DeadLetterChannel:
            setProperties((DefaultErrorHandlerBuilder) builder);
            break;
        case LoggingErrorHandler:
            setProperties((LoggingErrorHandlerBuilder) builder);
            break;
        case NoErrorHandler:
            // No configuration required
            break;
        case TransactionErrorHandler:
            break;
        default:
            break;
        }

        return builder;
    } catch (Exception cause) {
        throw new CreationException("Error while creating instance for " + this, cause);
    }
}
项目:axon-cdi    文件:AutoConfiguringSagaRepositoryProducer.java   
@Override
protected X configure(final X repository) {
    Method setter = MethodUtils.getAccessibleMethod(repository.getClass(),
            RESOURCE_INJECTOR_SETTER,
            ResourceInjector.class);
    if (setter != null) {
        try {
            setter.invoke(repository, new CdiResourceInjector(getBeanManager()));
        } catch (ReflectiveOperationException e) {
            throw new CreationException(e);
        }
    }
    return repository;
}
项目:camel-cdi    文件:XmlCdiBeanFactory.java   
private SyntheticBean<?> camelContextBean(CamelContextFactoryBean factory, URL url) {
    Set<Annotation> annotations = new HashSet<>();
    annotations.add(ANY);
    if (hasId(factory)) {
        addAll(annotations,
            ContextName.Literal.of(factory.getId()), NamedLiteral.of(factory.getId()));
    } else {
        annotations.add(DEFAULT);
        factory.setImplicitId(true);
        factory.setId(new CdiCamelContextNameStrategy().getNextName());
    }

    annotations.add(APPLICATION_SCOPED);
    SyntheticAnnotated annotated = new SyntheticAnnotated(DefaultCamelContext.class,
        manager.createAnnotatedType(DefaultCamelContext.class).getTypeClosure(),
        annotations);
    return new SyntheticBean<>(manager, annotated, DefaultCamelContext.class,
        environment.camelContextInjectionTarget(
            new SyntheticInjectionTarget<>(() -> {
                DefaultCamelContext context = new DefaultCamelContext();
                factory.setContext(context);
                factory.setBeanManager(manager);
                return context;
            }, context -> {
                try {
                    factory.afterPropertiesSet();
                } catch (Exception cause) {
                    throw new CreationException(cause);
                }
            }),
            annotated, manager),
        bean -> "imported Camel context with "
            + (factory.isImplicitId() ? "implicit " : "")
            + "id [" + factory.getId() + "] "
            + "from resource [" + url + "] "
            + "with qualifiers " + bean.getQualifiers());
}
项目:camel-cdi    文件:SyntheticBean.java   
@Override
public T create(CreationalContext<T> creationalContext) {
    try {
        T instance = target.produce(creationalContext);
        target.inject(instance, creationalContext);
        target.postConstruct(instance);
        return instance;
    } catch (Exception cause) {
        throw new CreationException("Error while instantiating " + this, cause);
    }
}
项目:Camel    文件:XmlCdiBeanFactory.java   
private static CreationException attributeNotSupported(String attribute, ErrorHandlerType type, String id) {
    return new CreationException(
        format("Attribute [%s] is not supported by error handler type [%s], in error handler with id [%s]",
            attribute, type, id));
}