/** {@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); } }
@Override public Method apply(GridResourceMethod rsrcMtd) { return rsrcMtd.getMethod(); } });
/** * Gets set of methods with given annotation. * * @param dep Deployment. * @param cls Class in which search for methods. * @param annCls Annotation. * @return Set of methods with given annotations. */ List<GridResourceMethod> getMethodsWithAnnotation(@Nullable GridDeployment dep, Class<?> cls, Class<? extends Annotation> annCls) { List<GridResourceMethod> mtds = getMethodsFromCache(cls, annCls); if (mtds == null) { mtds = new ArrayList<>(); for (Class cls0 = cls; !cls0.equals(Object.class); cls0 = cls0.getSuperclass()) { for (Method mtd : cls0.getDeclaredMethods()) { Annotation ann = mtd.getAnnotation(annCls); if (ann != null) mtds.add(new GridResourceMethod(mtd, ann)); } } cacheMethods(dep, cls, annCls, mtds); } return mtds; }
/** {@inheritDoc} */ @Override public void inject(GridResourceMethod mtd, Object target, Class<?> depCls, GridDeployment dep) throws GridException { GridResourceUtils.inject(mtd.getMethod(), target, rsrc); }
/** {@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(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(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); } }