/** {@inheritDoc} */ @Override public void inject(GridResourceMethod mtd, Object target, Class<?> depCls, GridDeployment dep) throws GridException { GridResourceUtils.inject(mtd.getMethod(), target, rsrc); }
/** * Creates new bean. * * @param field Field where resource should be injected. * @param ann Resource annotation. */ GridResourceField(Field field, Annotation ann) { assert field != null; assert ann != null || GridResourceUtils.mayRequireResources(field); this.field = field; this.ann = ann; }
/** {@inheritDoc} */ @Override public void inject(GridResourceField field, Object target, Class<?> depCls, GridDeployment dep) throws GridException { GridResourceUtils.inject(field.getField(), target, rsrc); }
/** * Gets all entries from the specified class or its super-classes that have * been annotated with annotation provided. * * @param cls Class in which search for methods. * @param dep Deployment. * @param annCls Annotation. * @return Set of entries with given annotations. */ private List<GridResourceField> getFieldsWithAnnotation(@Nullable GridDeployment dep, Class<?> cls, Class<? extends Annotation> annCls) { List<GridResourceField> fields = getFieldsFromCache(cls, annCls); if (fields == null) { fields = new ArrayList<>(); for (Class cls0 = cls; !cls0.equals(Object.class); cls0 = cls0.getSuperclass()) { for (Field field : cls0.getDeclaredFields()) { Annotation ann = field.getAnnotation(annCls); if (ann != null || GridResourceUtils.mayRequireResources(field)) // Account for anonymous inner classes. fields.add(new GridResourceField(field, ann)); } } cacheFields(dep, cls, annCls, fields); } return fields; }
/** {@inheritDoc} */ @Override public void inject(GridResourceField field, Object target, Class<?> depCls, GridDeployment dep) throws GridException { GridResourceUtils.inject(field.getField(), target, resource((GridLoggerResource)field.getAnnotation(), target)); }
Field f = field.getField(); if (GridResourceUtils.mayRequireResources(f)) { f.setAccessible(true);
/** {@inheritDoc} */ @Override public void inject(GridResourceMethod mtd, Object target, Class<?> depCls, GridDeployment dep) throws GridException { GridResourceUtils.inject(mtd.getMethod(), target, resource((GridLoggerResource)mtd.getAnnotation(), target)); }
/** {@inheritDoc} */ @Override public void inject(GridResourceField field, Object target, Class<?> cls, GridDeployment depCls) throws GridException { GridSpringResource ann = (GridSpringResource)field.getAnnotation(); assert ann != null; // Note: injected non-serializable user resources should not mark // injected spring beans with transient modifier. // Check for 'transient' modifier only in serializable classes. if (!Modifier.isTransient(field.getField().getModifiers()) && Serializable.class.isAssignableFrom(field.getField().getDeclaringClass())) { throw new GridException("@GridSpringResource must only be used with 'transient' fields: " + field.getField()); } String name = ann.resourceName(); if (springCtx != null) { Object bean = springCtx.getBean(name); GridResourceUtils.inject(field.getField(), target, bean); } }
/** {@inheritDoc} */ @Override public void inject(GridResourceMethod mtd, Object target, Class<?> cls, GridDeployment depCls) throws GridException { GridSpringResource ann = (GridSpringResource)mtd.getAnnotation(); assert ann != null; if (mtd.getMethod().getParameterTypes().length != 1) throw new GridException("Method injection setter must have only one parameter: " + mtd.getMethod()); String name = ann.resourceName(); if (springCtx != null) { Object bean = springCtx.getBean(name); GridResourceUtils.inject(mtd.getMethod(), target, bean); } }
/** {@inheritDoc} */ @Override public void inject(GridResourceMethod mtd, Object target, Class<?> depCls, GridDeployment dep) throws GridException { assert dep != null; GridUserResource ann = (GridUserResource)mtd.getAnnotation(); if (mtd.getMethod().getParameterTypes().length != 1) throw new GridException("Method injection setter must have only one parameter: " + mtd.getMethod()); Class<?> rsrcCls = !ann.resourceClass().equals(Void.class) ? ann.resourceClass() : mtd.getMethod().getParameterTypes()[0]; String rsrcName = ann.resourceName(); GridResourceUtils.inject(mtd.getMethod(), target, getResource(dep, depCls, rsrcCls, rsrcName)); }
/** {@inheritDoc} */ @Override public void inject(GridResourceField field, Object target, Class<?> depCls, GridDeployment dep) throws GridException { assert dep != null; GridUserResource ann = (GridUserResource)field.getAnnotation(); assert ann != null; if (!Modifier.isTransient(field.getField().getModifiers())) { throw new GridException("@GridUserResource must only be used with 'transient' fields: " + field.getField()); } Class<?> rsrcCls = !ann.resourceClass().equals(Void.class) ? ann.resourceClass() : field.getField().getType(); String rsrcName = ann.resourceName(); GridResourceUtils.inject(field.getField(), target, getResource(dep, depCls, rsrcCls, rsrcName)); }
/** {@inheritDoc} */ @Override public void inject(GridResourceMethod mtd, Object target, Class<?> depCls, GridDeployment dep) throws GridException { GridServiceResource ann = (GridServiceResource)mtd.getAnnotation(); Class svcItf = ann.proxyInterface(); Object svc; if (svcItf == Void.class) svc = grid.services().service(ann.serviceName()); else svc = grid.services().serviceProxy(ann.serviceName(), svcItf, ann.proxySticky()); Class<?>[] types = mtd.getMethod().getParameterTypes(); if (types.length != 1) throw new GridException("Setter does not have single parameter of required type [type=" + svc.getClass().getName() + ", setter=" + mtd + ']'); if (svc != null) GridResourceUtils.inject(mtd.getMethod(), target, svc); } }
/** {@inheritDoc} */ @Override public void inject(GridResourceField field, Object target, Class<?> depCls, GridDeployment dep) throws GridException { GridServiceResource ann = (GridServiceResource)field.getAnnotation(); Class svcItf = ann.proxyInterface(); Object svc; if (svcItf == Void.class) svc = grid.services().service(ann.serviceName()); else svc = grid.services().serviceProxy(ann.serviceName(), svcItf, ann.proxySticky()); if (svc != null) GridResourceUtils.inject(field.getField(), target, svc); }