1 22 package org.jboss.aop.advice; 23 24 import java.lang.reflect.Modifier ; 25 26 import org.jboss.aop.Advisor; 27 import org.jboss.aop.ClassAdvisor; 28 import org.jboss.aop.GeneratedClassAdvisor; 29 import org.jboss.aop.joinpoint.FieldJoinpoint; 30 import org.jboss.aop.joinpoint.Joinpoint; 31 32 38 public class ScopedInterceptorFactory implements InterceptorFactory 39 { 40 private AspectDefinition aspect; 41 42 public ScopedInterceptorFactory(AspectDefinition aspect) 43 { 44 this.aspect = aspect; 45 } 46 47 public AspectDefinition getAspect() 48 { 49 return aspect; 50 } 51 52 public String getAdvice() 53 { 54 return "invoke"; 55 } 56 57 public boolean isDeployed() 58 { 59 return aspect.isDeployed(); 60 } 61 62 public Interceptor create(Advisor advisor, Joinpoint joinpoint) 63 { 64 if (aspect.getScope() == Scope.PER_VM) 65 { 66 return (Interceptor) advisor.getManager().getPerVMAspect(aspect); 67 } 68 else if (aspect.getScope() == Scope.PER_CLASS) 69 { 70 Interceptor interceptor = advisor.getAdviceInterceptor(aspect, "invoke", null); 71 if (interceptor != null) return interceptor; 72 advisor.addPerClassAspect(aspect); 73 interceptor = (Interceptor)advisor.getPerClassAspect(aspect); 74 advisor.addAdviceInterceptor(aspect, "invoke", interceptor, null); 75 return interceptor; 76 77 } 78 else if (aspect.getScope() == Scope.PER_INSTANCE) 79 { 80 return new PerInstanceInterceptor(aspect, advisor); 81 } 82 else if (aspect.getScope() == Scope.PER_JOINPOINT) 83 { 84 try 85 { 86 return PerJoinpointInterceptor.createInterceptor(advisor, joinpoint, aspect); 87 } 88 catch (Exception e) 89 { 90 throw new RuntimeException (e); } 92 } 93 else if (aspect.getScope() == Scope.PER_CLASS_JOINPOINT) 94 { 95 if (advisor instanceof GeneratedClassAdvisor) 96 { 97 Object icptr = ((GeneratedClassAdvisor)advisor).getPerClassJoinpointAspect(aspect, joinpoint); 99 if (icptr == null) 100 { 101 ((GeneratedClassAdvisor)advisor).addPerClassJoinpointAspect(aspect, joinpoint); 102 icptr = ((GeneratedClassAdvisor)advisor).getPerClassJoinpointAspect(aspect, joinpoint); 103 } 104 return (Interceptor)icptr; 105 } 106 else if (joinpoint instanceof FieldJoinpoint) 107 { 108 FieldJoinpoint field = (FieldJoinpoint) joinpoint; 109 ClassAdvisor classAdvisor = (ClassAdvisor) advisor; 110 return (Interceptor) classAdvisor.getFieldAspect(field, aspect); 111 } 112 113 return (Interceptor) aspect.getFactory().createPerJoinpoint(advisor, joinpoint); 114 } 115 else 116 { 117 } 119 return null; 120 } 121 122 public String getName() 123 { 124 return aspect.getName(); 125 } 126 127 public boolean equals(Object obj) 128 { 129 if (this == obj) return true; 130 if (!(obj instanceof ScopedInterceptorFactory)) return false; 131 132 AspectDefinition otherAspect = ((GenericInterceptorFactory)obj).getAspect(); 133 134 if (!this.aspect.getName().equals(otherAspect.getName())) return false; 135 if (!this.aspect.getFactory().getName().equals(otherAspect.getFactory().getName()))return false; 136 137 return true; 138 } 139 } 140 | Popular Tags |