/** * Checks if annotation presents in specified object. * * @param dep Class deployment. * @param target Object to check. * @param annCls Annotation to find. * @return {@code true} if annotation is presented, {@code false} otherwise. */ public boolean isAnnotationPresent(GridDeployment dep, Object target, Class<? extends Annotation> annCls) { return ioc.isAnnotationPresent(target, annCls, dep); }
/** * @param dep Deployment. * @param target Target. * @param annClss Annotations. * @return Filtered set of annotations that present in target. */ @SuppressWarnings({"SuspiciousToArrayCall", "unchecked"}) Class<? extends Annotation>[] filter( @Nullable GridDeployment dep, Object target, Collection<Class<? extends Annotation>> annClss) { assert target != null; assert annClss != null && !annClss.isEmpty(); Class<?> cls = target.getClass(); Class<? extends Annotation>[] res = annCache.get(cls); if (res == null) { Collection<Class<? extends Annotation>> res0 = new HashSet<>(annClss.size(), 1.0f); for (Class<? extends Annotation> annCls : annClss) { if (isAnnotationPresent(target, annCls, dep)) res0.add(annCls); } res = new Class[res0.size()]; res0.toArray(res); annCache.putIfAbsent(cls, res); } return res; }
/** * Injects given resource via field or setter with specified annotations on provided target object. * * @param target Target object. * @param annCls Setter annotation. * @param injector Resource to inject. * @param dep Deployment. * @param depCls Deployment class. * @throws GridException Thrown in case of any errors during injection. */ void inject(Object target, Class<? extends Annotation> annCls, GridResourceInjector injector, @Nullable GridDeployment dep, @Nullable Class<?> depCls) throws GridException { assert target != null; assert annCls != null; assert injector != null; if (isAnnotationPresent(target, annCls, dep)) // Use identity hash set to compare via referential equality. injectInternal(target, annCls, injector, dep, depCls, new GridIdentityHashSet<>(3)); }