use of com.jim.framework.rpc.client.RpcReference in project jim-framework by jiangmin168168.
the class BeanPostPrcessorReference method initRpcReferenceBean.
public Object initRpcReferenceBean(Object bean, String beanName) {
Class<?> clazz = bean.getClass();
if (isProxyBean(bean)) {
clazz = AopUtils.getTargetClass(bean);
}
Method[] methods = clazz.getMethods();
for (Method method : methods) {
String name = method.getName();
if (name.length() > 3 && name.startsWith("set") && method.getParameterTypes().length == 1 && Modifier.isPublic(method.getModifiers()) && !Modifier.isStatic(method.getModifiers())) {
try {
RpcReference reference = method.getAnnotation(RpcReference.class);
if (reference != null) {
Object value = this.rpcClient.createProxy(method.getParameterTypes()[0], reference);
if (value != null) {
method.invoke(bean, new Object[] { value });
}
}
} catch (Exception e) {
throw new BeanInitializationException("Failed to init remote service reference at method " + name + " in class " + bean.getClass().getName(), e);
}
}
}
Field[] fields = clazz.getDeclaredFields();
for (Field field : fields) {
try {
if (!field.isAccessible()) {
field.setAccessible(true);
}
RpcReference reference = field.getAnnotation(RpcReference.class);
if (reference != null) {
Object value = this.rpcClient.createProxy(field.getType(), reference);
if (value != null) {
field.set(bean, value);
}
}
} catch (Exception e) {
throw new BeanInitializationException("Failed to init remote service reference at filed " + field.getName() + " in class " + bean.getClass().getName(), e);
}
}
return bean;
}
Aggregations