Search in sources :

Example 1 with SubscriptionPublisher

use of io.joynr.provider.SubscriptionPublisher in project joynr by bmwcarit.

the class SubscriptionPublisherProducer method getSubscriptionPublisher.

@Produces
@io.joynr.jeeintegration.api.SubscriptionPublisher
public SubscriptionPublisher getSubscriptionPublisher(InjectionPoint injectionPoint) {
    logger.info("Looking for subscription publisher for: " + injectionPoint);
    logger.info("Type is: " + injectionPoint.getType());
    logger.info("Member is: " + injectionPoint.getMember());
    logger.info("Annotated is: " + injectionPoint.getAnnotated());
    Class beanClass = injectionPoint.getBean() == null ? injectionPoint.getMember().getDeclaringClass() : injectionPoint.getBean().getBeanClass();
    logger.info("Bean class is: " + beanClass);
    if (!subscriptionPublishers.containsKey(beanClass)) {
        Class subscriptionPublisherClass = (Class) injectionPoint.getAnnotated().getBaseType();
        SubscriptionPublisher newSubscriptionPublisher = (SubscriptionPublisher) Proxy.newProxyInstance(subscriptionPublisherClass.getClassLoader(), new Class[] { subscriptionPublisherClass }, new InvocationHandler() {

            @Override
            public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                throw new IllegalStateException("No subscription publisher set for " + subscriptionPublisherClass + " on " + beanClass);
            }
        });
        subscriptionPublishers.putIfAbsent(beanClass, newSubscriptionPublisher);
    }
    return subscriptionPublishers.get(beanClass);
}
Also used : SubscriptionPublisher(io.joynr.provider.SubscriptionPublisher) Method(java.lang.reflect.Method) InvocationHandler(java.lang.reflect.InvocationHandler) Produces(javax.enterprise.inject.Produces)

Example 2 with SubscriptionPublisher

use of io.joynr.provider.SubscriptionPublisher in project joynr by bmwcarit.

the class SubscriptionPublisherInjectionWrapper method createInvocationHandler.

public static SubscriptionPublisherInjectionWrapper createInvocationHandler(Bean<?> bean, BeanManager beanManager) {
    logger.trace("Called with {} and {}", bean, beanManager);
    SubscriptionPublisherProducer subscriptionPublisherProducer = getSubscriptionPublisherProducerReference(beanManager);
    Class proxiedInterface = SubscriptionPublisherInjection.class;
    Class subscriptionPublisherClass = null;
    Class beanClass = bean.getBeanClass();
    for (InjectionPoint injectionPoint : bean.getInjectionPoints()) {
        if (!injectionPoint.getQualifiers().contains(SUBSCRIPTION_PUBLISHER_ANNOTATION_LITERAL)) {
            continue;
        }
        Type baseType = injectionPoint.getAnnotated().getBaseType();
        if (baseType instanceof Class && SubscriptionPublisher.class.isAssignableFrom((Class) baseType)) {
            subscriptionPublisherClass = (Class) baseType;
            break;
        }
    }
    logger.debug("Found injector {} and publisher {} classes.", proxiedInterface, subscriptionPublisherClass);
    if (subscriptionPublisherClass == null || proxiedInterface == null) {
        throw new JoynrIllegalStateException("Cannot create subscription publisher injection wrapper proxy for bean which doesn't inject a concrete SubscriptionPublisher.");
    }
    return new SubscriptionPublisherInjectionWrapper(proxiedInterface, subscriptionPublisherClass, subscriptionPublisherProducer, beanClass);
}
Also used : Type(java.lang.reflect.Type) InjectionPoint(javax.enterprise.inject.spi.InjectionPoint) SubscriptionPublisher(io.joynr.provider.SubscriptionPublisher) SubscriptionPublisherInjection(io.joynr.provider.SubscriptionPublisherInjection) JoynrIllegalStateException(io.joynr.exceptions.JoynrIllegalStateException)

Aggregations

SubscriptionPublisher (io.joynr.provider.SubscriptionPublisher)2 JoynrIllegalStateException (io.joynr.exceptions.JoynrIllegalStateException)1 SubscriptionPublisherInjection (io.joynr.provider.SubscriptionPublisherInjection)1 InvocationHandler (java.lang.reflect.InvocationHandler)1 Method (java.lang.reflect.Method)1 Type (java.lang.reflect.Type)1 Produces (javax.enterprise.inject.Produces)1 InjectionPoint (javax.enterprise.inject.spi.InjectionPoint)1