1 22 package org.jboss.aop.proxy.container; 23 24 import java.lang.ref.WeakReference ; 25 26 public class AOPProxyFactoryMixin 27 { 28 private String construction; 29 private WeakReference mixinClassRef; 30 private WeakReference [] interfaceClassRefs; 31 private int hashcode; 32 33 public AOPProxyFactoryMixin(Class mixin, Class [] interfaces) 34 { 35 mixinClassRef = new WeakReference (mixin); 36 interfaceClassRefs = ContainerCacheUtil.getSortedWeakReferenceForInterfaces(interfaces); 37 } 38 39 public AOPProxyFactoryMixin(Class mixin, Class [] interfaces, String parameters) 40 { 41 this(mixin, interfaces); 42 StringBuffer construction = new StringBuffer (" new "); 43 construction.append(mixin.getName()); 44 45 if (!parameters.startsWith("(")) 46 { 47 construction.append("("); 48 } 49 50 construction.append(parameters); 51 52 if (!parameters.endsWith(")")) 53 { 54 construction.append(")"); 55 } 56 this.construction = construction.toString(); 57 } 58 59 public String getConstruction() 60 { 61 return construction; 62 } 63 64 65 public Class [] getInterfaces() 66 { 67 if (interfaceClassRefs != null) 68 { 69 Class [] interfaces = new Class [interfaceClassRefs.length]; 70 for (int i = 0 ; i < interfaces.length ; i++) 71 { 72 interfaces[i] = (Class )interfaceClassRefs[i].get(); 73 } 74 return interfaces; 75 } 76 return null; 77 } 78 79 public Class getMixin() 80 { 81 return (Class )mixinClassRef.get(); 82 } 83 84 public boolean equals(Object obj) 85 { 86 if (this == obj) 87 { 88 return true; 89 } 90 91 if (!(obj instanceof AOPProxyFactoryMixin)) 92 { 93 return false; 94 } 95 96 AOPProxyFactoryMixin other = (AOPProxyFactoryMixin)obj; 97 98 if (!compareConstruction(other)) 99 { 100 return false; 101 } 102 if (!ContainerCacheUtil.compareClassRefs(this.mixinClassRef, other.mixinClassRef)) 103 { 104 return false; 105 } 106 if (!ContainerCacheUtil.compareInterfaceRefs(this.interfaceClassRefs, other.interfaceClassRefs)) 107 { 108 return false; 109 } 110 return true; 111 } 112 113 public int hashCode() 114 { 115 if (hashcode == 0) 116 { 117 118 Class clazz = (Class )mixinClassRef.get(); 119 StringBuffer sb = new StringBuffer (); 120 121 if (clazz != null) 122 { 123 sb.append(clazz.getName()); 124 } 125 126 if (interfaceClassRefs != null) 127 { 128 for (int i = 0 ; i < interfaceClassRefs.length ; i++) 129 { 130 sb.append(";"); 131 sb.append(((Class )interfaceClassRefs[i].get()).getName()); 132 } 133 } 134 hashcode = sb.toString().hashCode(); 135 if (construction != null) 136 { 137 hashcode += construction.hashCode(); 138 } 139 } 140 141 return hashcode; 142 } 143 144 public String toString() 145 { 146 return super.toString(); 147 } 148 149 private boolean compareConstruction(AOPProxyFactoryMixin other) 150 { 151 if (this.construction == null && other.construction != null) 152 { 153 return false; 154 } 155 if (this.construction != null && other.construction == null) 156 { 157 return false; 158 } 159 if (this.construction != null) 160 { 161 if (!this.construction.equals(other.construction)) 162 { 163 return false; 164 } 165 } 166 return true; 167 } 168 } | Popular Tags |