1
2
3
4
5
6 package org.weda.enhance.impl;
7
8 import java.lang.reflect.Field;
9 import org.jboss.aop.joinpoint.FieldReadInvocation;
10 import org.weda.enhance.InjectHivemindObject;
11 import org.weda.enhance.impl.AspectHelperImpl;
12
13 /**
14 *
15 * @author Mikhail Titov
16 */
17 public class HivemindObjectAspect {
18
19 public Object resolveHivemindObject(FieldReadInvocation joinPoint)
20 throws Throwable
21 {
22 Object res = joinPoint.invokeNext();
23 if (res==null){
24 synchronized (joinPoint.getField()){
25 res = joinPoint.invokeNext();
26 if (res == null){
27 Field field = joinPoint.getField();
28 field.isAnnotationPresent(InjectHivemindObject.class);
29 InjectHivemindObject ann =
30 field.getAnnotation(InjectHivemindObject.class);
31 String objectRef = ann.value();
32 if (objectRef.length()==0)
33 objectRef = "service:"+field.getType().getName();
34 res = AspectHelperImpl.INSTANCE
35 .getHivemindObject(objectRef);
36 field.set(joinPoint.getTargetObject(), res);
37 }
38 }
39 }
40 return res;
41 }
42 }