private CacheKey(Injectee injectee) { this.injectee = injectee; this.hash = Objects.hash(injectee.getInjecteeClass(), injectee.getInjecteeDescriptor(), injectee.getParent(), injectee.getRequiredQualifiers(), injectee.getRequiredType(), injectee.getPosition()); }
private CacheKey(Injectee injectee) { this.injectee = injectee; this.hash = Objects.hash(injectee.getInjecteeClass(), injectee.getInjecteeDescriptor(), injectee.getParent(), injectee.getRequiredQualifiers(), injectee.getRequiredType(), injectee.getPosition()); }
@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; } }
@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; } }
private static String getName(Injectee injectee) { for (Annotation anno : injectee.getRequiredQualifiers()) { if (Named.class.equals(anno.annotationType())) { Named named = (Named) anno; return named.value(); } } return null; }
public <T extends Annotation> Optional<T> findQualifier(Injectee injectee, Class<T> type) { Set<Annotation> qualifiers = injectee.getRequiredQualifiers(); return qualifiers.parallelStream() .filter(p -> type.equals(p.annotationType())) .map(p -> (T) p) .findFirst(); }
final Type requiredType = injectee.getRequiredType(); if ( injectee.getRequiredQualifiers().isEmpty() && requiredType instanceof Class ) { final Class<?> requiredClass = (Class<?>) requiredType;
private void addMe(Class<?> lookForMe, String name, Injectee injectee) { HashSet<Type> contracts = new HashSet<Type>(); contracts.add(injectee.getRequiredType()); Set<Annotation> qualifiers = new HashSet<Annotation>(injectee.getRequiredQualifiers()); SpringServiceHK2Bean<Object> springHK2Bean = new SpringServiceHK2Bean<Object>( name, contracts, qualifiers, lookForMe, beanFactory); ServiceLocatorUtilities.addOneDescriptor(locator, springHK2Bean, false); }
/** * NOTE: There can be only one {@link Annotation} that is a {@link Qualifier} or {@link BindingAnnotation}. * They're the same but HK2 does not know about {@link BindingAnnotation}. * * @see Qualifier * @see BindingAnnotation * @see javax.inject.Named * @see com.google.inject.name.Named */ private static Set<Annotation> getQualifiers(Injectee injectee) { // JSR 330's @Qualifier Set<Annotation> qualifiers = injectee.getRequiredQualifiers(); if (!qualifiers.isEmpty()) { return qualifiers; } AnnotatedElement element = injectee.getParent(); int position = injectee.getPosition(); // Guice's @BindingAnnotation is the same as @Qualifier Annotation annotation = getBindingAnnotation(element, position); if (annotation != null) { return Collections.singleton(annotation); } return Collections.emptySet(); }
/** * NOTE: There can be only one {@link Annotation} that is a {@link Qualifier} or {@link BindingAnnotation}. * They're the same but HK2 does not know about {@link BindingAnnotation}. * * @see Qualifier * @see BindingAnnotation * @see javax.inject.Named * @see com.google.inject.name.Named */ private static Set<Annotation> getQualifiers(Injectee injectee) { // JSR 330's @Qualifier Set<Annotation> qualifiers = injectee.getRequiredQualifiers(); if (!qualifiers.isEmpty()) { return qualifiers; } AnnotatedElement element = injectee.getParent(); int position = injectee.getPosition(); // Guice's @BindingAnnotation is the same as @Qualifier Annotation annotation = getBindingAnnotation(element, position); if (annotation != null) { return Collections.singleton(annotation); } return Collections.emptySet(); }
/** * NOTE: There can be only one {@link Annotation} that is a {@link Qualifier} or {@link BindingAnnotation}. * They're the same but HK2 does not know about {@link BindingAnnotation}. * * @see Qualifier * @see BindingAnnotation * @see javax.inject.Named * @see com.google.inject.name.Named */ private static Set<Annotation> getQualifiers(Injectee injectee) { // JSR 330's @Qualifier Set<Annotation> qualifiers = injectee.getRequiredQualifiers(); if (!qualifiers.isEmpty()) { return qualifiers; } AnnotatedElement element = injectee.getParent(); int position = injectee.getPosition(); // Guice's @BindingAnnotation is the same as @Qualifier Annotation annotation = getBindingAnnotation(element, position); if (annotation != null) { return Collections.singleton(annotation); } return Collections.emptySet(); }
/** * NOTE: There can be only one {@link Annotation} that is a {@link Qualifier} or {@link BindingAnnotation}. * They're the same but HK2 does not know about {@link BindingAnnotation}. * * @see Qualifier * @see BindingAnnotation * @see javax.inject.Named * @see com.google.inject.name.Named */ private static Set<Annotation> getQualifiers(Injectee injectee) { // JSR 330's @Qualifier Set<Annotation> qualifiers = injectee.getRequiredQualifiers(); if (!qualifiers.isEmpty()) { return qualifiers; } AnnotatedElement element = injectee.getParent(); int position = injectee.getPosition(); // Guice's @BindingAnnotation is the same as @Qualifier Annotation annotation = getBindingAnnotation(element, position); if (annotation != null) { return Collections.singleton(annotation); } return Collections.emptySet(); }
private CacheKey(Injectee injectee) { this.injectee = injectee; this.hash = Objects.hash(injectee.getInjecteeClass(), injectee.getInjecteeDescriptor(), injectee.getParent(), injectee.getRequiredQualifiers(), injectee.getRequiredType(), injectee.getPosition()); }
@SuppressWarnings({ "unchecked" }) @Override public boolean justInTimeResolution(Injectee failedInjectionPoint) { Type requiredType = failedInjectionPoint.getRequiredType(); Set<Annotation> setQualifiers = failedInjectionPoint.getRequiredQualifiers(); Annotation qualifiers[] = setQualifiers.toArray(new Annotation[setQualifiers.size()]); BeanManager manager = getCurrentBeanManager(); if (manager == null) return false; Set<Bean<?>> beans = manager.getBeans(requiredType, qualifiers); if (beans == null || beans.isEmpty()) { return false; } DynamicConfiguration config = ServiceLocatorUtilities.createDynamicConfiguration(locator); for (Bean<?> bean : beans) { // Add a bean to the service locator CDIHK2Descriptor<Object> descriptor = new CDIHK2Descriptor<Object>(manager, (Bean<Object>) bean, requiredType); config.addActiveDescriptor(descriptor); } config.commit(); return true; }
/** * This is the copy constructor, which will copy all the values from the incoming Injectee * @param copyMe The non-null Injectee to copy the values from */ public InjecteeImpl(Injectee copyMe) { requiredType = copyMe.getRequiredType(); position = copyMe.getPosition(); parent = copyMe.getParent(); qualifiers = Collections.unmodifiableSet(copyMe.getRequiredQualifiers()); isOptional = copyMe.isOptional(); isSelf = copyMe.isSelf(); injecteeDescriptor = copyMe.getInjecteeDescriptor(); // unqualified = copyMe.getUnqualified(); if (parent == null) { pClass = null; } else if (parent instanceof Field) { pClass = ((Field) parent).getDeclaringClass(); } else if (parent instanceof Constructor) { pClass = ((Constructor<?>) parent).getDeclaringClass(); } else if (parent instanceof Method) { pClass = ((Method) parent).getDeclaringClass(); } }
private CacheKey(Injectee injectee) { this.injectee = injectee; this.hash = Objects.hash(injectee.getInjecteeClass(), injectee.getInjecteeDescriptor(), injectee.getParent(), injectee.getRequiredQualifiers(), injectee.getRequiredType(), injectee.getPosition()); }
/** * @see org.glassfish.hk2.api.InjectionResolver#resolve(org.glassfish.hk2.api.Injectee, * org.glassfish.hk2.api.ServiceHandle) */ @Override public Object resolve(Injectee arg0, ServiceHandle<?> arg1) { Type requiredType = arg0.getRequiredType(); return this.serviceLocator.getService( this.getServiceCosumer((Class<?>) requiredType, arg0.getInjecteeClass(), arg0.getRequiredQualifiers())) .getService(); }
@Override public Object resolve(Injectee injectee, ServiceHandle<?> root) { final String factoryName = ReflectionHelper.getNameFromAllQualifiers( injectee.getRequiredQualifiers(), injectee.getParent()); final ConnectionSource connectionSource = persistenceSessionManager.get().getPersistenceContext( new PersistenceContextKey(new PersistenceContextFactoryKey(factoryName)), ConnectionSource.class, injectee.getInjecteeDescriptor().getScope()); return connectionSource; }
@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; } }
@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; } }