Search in sources :

Example 1 with Injectee

use of org.glassfish.hk2.api.Injectee in project jersey by jersey.

the class InjectionResolverWrapper method resolve.

@Override
public Object resolve(Injectee injectee, ServiceHandle root) {
    InjecteeImpl injecteeWrapper = new InjecteeImpl();
    injecteeWrapper.setRequiredType(injectee.getRequiredType());
    injecteeWrapper.setParent(injectee.getParent());
    injecteeWrapper.setRequiredQualifiers(injectee.getRequiredQualifiers());
    injecteeWrapper.setOptional(injectee.isOptional());
    injecteeWrapper.setPosition(injectee.getPosition());
    injecteeWrapper.setFactory(ReflectionHelper.isSubClassOf(injectee.getRequiredType(), Factory.class));
    injecteeWrapper.setInjecteeDescriptor(new ForeignDescriptorImpl(injectee.getInjecteeDescriptor()));
    Object instance = jerseyResolver.resolve(injecteeWrapper);
    if (injecteeWrapper.isFactory()) {
        return asFactory(instance);
    } else {
        return instance;
    }
}
Also used : InjecteeImpl(org.glassfish.jersey.internal.inject.InjecteeImpl) Factory(org.glassfish.hk2.api.Factory) ForeignDescriptorImpl(org.glassfish.jersey.internal.inject.ForeignDescriptorImpl)

Example 2 with Injectee

use of org.glassfish.hk2.api.Injectee in project jersey by jersey.

the class ContextInjectionResolverImpl method resolve.

@Override
public Object resolve(Injectee injectee, ServiceHandle<?> root) {
    Type requiredType = injectee.getRequiredType();
    boolean isHk2Factory = ReflectionHelper.isSubClassOf(requiredType, Factory.class);
    Injectee newInjectee;
    if (isHk2Factory) {
        newInjectee = getFactoryInjectee(injectee, ReflectionHelper.getTypeArgument(requiredType, 0));
    } else {
        newInjectee = foreignRequestScopedInjecteeCache.apply(injectee);
    }
    ActiveDescriptor<?> ad = descriptorCache.apply(newInjectee);
    if (ad != null) {
        final ServiceHandle handle = serviceLocator.getServiceHandle(ad, newInjectee);
        if (isHk2Factory) {
            return asFactory(handle);
        } else {
            return handle.getService();
        }
    }
    return null;
}
Also used : GenericType(javax.ws.rs.core.GenericType) Type(java.lang.reflect.Type) Injectee(org.glassfish.hk2.api.Injectee) ServiceHandle(org.glassfish.hk2.api.ServiceHandle)

Example 3 with Injectee

use of org.glassfish.hk2.api.Injectee in project jersey by jersey.

the class ContextInjectionResolverImpl method resolve.

/**
     * Jersey Injection Resolver method that just populate HK2 injectee object and delegates the processing to HK2 Injection
     * Resolver.
     *
     * @param injectee The injection point this value is being injected into
     * @return result of the injection processing.
     */
@Override
public Object resolve(org.glassfish.jersey.internal.inject.Injectee injectee) {
    InjecteeImpl hk2injectee = new InjecteeImpl() {

        @Override
        public Class<?> getInjecteeClass() {
            return injectee.getInjecteeClass();
        }
    };
    hk2injectee.setRequiredType(injectee.getRequiredType());
    hk2injectee.setRequiredQualifiers(injectee.getRequiredQualifiers());
    if (injectee.getInjecteeDescriptor() != null) {
        hk2injectee.setInjecteeDescriptor((ActiveDescriptor<?>) injectee.getInjecteeDescriptor().get());
    }
    // Delegate the call to HK2 Resolver, Service Handle is not need in the delegated processing.
    return resolve(hk2injectee, null);
}
Also used : InjecteeImpl(org.glassfish.hk2.utilities.InjecteeImpl)

Aggregations

Type (java.lang.reflect.Type)1 GenericType (javax.ws.rs.core.GenericType)1 Factory (org.glassfish.hk2.api.Factory)1 Injectee (org.glassfish.hk2.api.Injectee)1 ServiceHandle (org.glassfish.hk2.api.ServiceHandle)1 InjecteeImpl (org.glassfish.hk2.utilities.InjecteeImpl)1 ForeignDescriptorImpl (org.glassfish.jersey.internal.inject.ForeignDescriptorImpl)1 InjecteeImpl (org.glassfish.jersey.internal.inject.InjecteeImpl)1