1 22 package org.jboss.aop.metadata; 23 24 import java.lang.ref.WeakReference ; 25 import java.util.ArrayList ; 26 import java.util.Iterator ; 27 28 import org.jboss.aop.Advisor; 29 import org.jboss.aop.pointcut.Util; 30 import org.jboss.aop.pointcut.ast.ClassExpression; 31 import javassist.CtClass; 32 import javassist.NotFoundException; 33 34 38 public abstract class ClassMetaDataBinding 39 { 40 protected ClassExpression classExpr; 41 protected String expr; 42 protected String name; 43 protected String tag; 44 protected ArrayList advisors = new ArrayList (); 45 protected ClassMetaDataLoader loader; 46 47 public ClassMetaDataBinding(ClassMetaDataLoader loader, String name, String tag, String exp) 48 { 49 this.name = name; 50 this.tag = tag; 51 this.loader = loader; 52 expr = exp; 53 this.classExpr = new ClassExpression(expr); 54 } 55 56 public ClassMetaDataLoader getLoader() 57 { 58 return loader; 59 } 60 61 public String getName() 62 { 63 return name; 64 } 65 66 public String getTag() 67 { 68 return tag; 69 } 70 71 public void addAdvisor(Advisor advisor) 72 { 73 synchronized (advisors) 76 { 77 Iterator it = advisors.iterator(); 78 while (it.hasNext()) 79 { 80 WeakReference ref = (WeakReference ) it.next(); 81 Object obj = ref.get(); 82 if (obj == null) it.remove(); 83 } 84 advisors.add(new WeakReference (advisor)); 85 } 86 advisor.addClassMetaData(this); 87 } 88 89 public void clearAdvisors() 90 { 91 synchronized (advisors) 92 { 93 for (int i = 0; i < advisors.size(); i++) 94 { 95 WeakReference ref = (WeakReference ) advisors.get(i); 96 Advisor advisor = (Advisor) ref.get(); 97 if (advisor != null) 98 advisor.removeClassMetaData(this); 99 } 100 advisors.clear(); 101 } 102 } 103 104 public boolean equals(Object obj) 105 { 106 if (obj == this) return true; 107 if (!(obj instanceof ClassMetaDataBinding)) return false; 108 return ((ClassMetaDataBinding) obj).getName().equals(name); 109 } 110 111 public int hashCode() 112 { 113 return name.hashCode(); 114 } 115 116 public boolean matches(Advisor advisor, Class clazz) 117 { 118 return Util.matchesClassExpr(classExpr, clazz, advisor); 119 } 120 121 public boolean matches(Advisor advisor, CtClass clazz) throws NotFoundException 122 { 123 return Util.matchesClassExpr(classExpr, clazz, advisor); 124 } 125 126 public String getClassExpr() 127 { 128 return expr; 129 } 130 } 131 | Popular Tags |