1 4 package com.tc.aspectwerkz.definition; 5 6 7 import com.tc.aspectwerkz.DeploymentModel; 8 import com.tc.aspectwerkz.expression.ExpressionInfo; 9 import com.tc.aspectwerkz.aspect.DefaultMixinFactory; 10 import com.tc.aspectwerkz.intercept.Advisable; 11 import com.tc.aspectwerkz.intercept.AdvisableImpl; 12 import com.tc.aspectwerkz.reflect.impl.asm.AsmClassInfo; 13 import com.tc.aspectwerkz.reflect.ClassInfoHelper; 14 import com.tc.aspectwerkz.reflect.MethodInfo; 15 import com.tc.aspectwerkz.reflect.ClassInfo; 16 import com.tc.aspectwerkz.transform.TransformationConstants; 17 18 import java.util.ArrayList ; 19 import java.util.Iterator ; 20 import java.util.List ; 21 import java.util.Map ; 22 import java.util.HashMap ; 23 import java.lang.ref.WeakReference ; 24 25 30 public class MixinDefinition { 31 32 private final static String DEFAULT_MIXIN_FACTORY = DefaultMixinFactory.class.getName().replace('/', '.'); 33 36 private DeploymentModel m_deploymentModel; 37 38 41 private boolean m_isTransient; 42 43 46 private final List m_methodsToIntroduce = new ArrayList (); 47 48 51 private final List m_interfaceClassNames = new ArrayList (); 52 53 56 private final String m_mixinImplClassName; 57 58 61 private final WeakReference m_loaderRef; 62 63 66 private ExpressionInfo[] m_expressionInfos = new ExpressionInfo[]{}; 67 68 71 private String m_attribute = ""; 72 73 76 private String m_factoryClassName; 77 78 81 private SystemDefinition m_systemDefinition; 82 83 86 private Map m_parameters = new HashMap (); 87 88 96 public MixinDefinition(ClassInfo mixinClass, 97 final DeploymentModel deploymentModel, 98 final boolean isTransient, 99 final SystemDefinition systemDef) { 100 if (isSystemMixin(mixinClass)) { 101 mixinClass = defineSystemMixin(mixinClass.getClassLoader()); 102 } else { 103 List allInterfaces = ClassInfoHelper.collectInterfaces(mixinClass); 104 for (Iterator iterator = allInterfaces.iterator(); iterator.hasNext();) { 105 ClassInfo interfaceInfo = (ClassInfo) iterator.next(); 106 m_interfaceClassNames.add(interfaceInfo.getName()); 107 } 108 109 List interfaceDeclaredMethods = ClassInfoHelper.collectMethodsFromInterfacesImplementedBy(mixinClass); 110 List sortedMethodList = ClassInfoHelper.createInterfaceDefinedMethodList( 111 mixinClass, interfaceDeclaredMethods 112 ); 113 for (Iterator iterator = sortedMethodList.iterator(); iterator.hasNext();) { 114 MethodInfo methodInfo = (MethodInfo) iterator.next(); 115 m_methodsToIntroduce.add(methodInfo); 116 } 117 } 118 119 m_mixinImplClassName = mixinClass.getName(); 120 m_loaderRef = new WeakReference (mixinClass.getClassLoader()); 121 m_systemDefinition = systemDef; 122 m_expressionInfos = new ExpressionInfo[]{}; 123 124 m_deploymentModel = deploymentModel; 125 m_isTransient = isTransient; 126 127 setFactoryClassName(DEFAULT_MIXIN_FACTORY); 129 } 130 131 136 public void setFactoryClassName(final String factoryClassName) { 137 m_factoryClassName = factoryClassName; 138 } 139 140 145 public String getFactoryClassName() { 146 return m_factoryClassName; 147 } 148 149 154 public List getMethodsToIntroduce() { 155 return m_methodsToIntroduce; 156 } 157 158 163 public DeploymentModel getDeploymentModel() { 164 return m_deploymentModel; 165 } 166 167 172 public void setDeploymentModel(final DeploymentModel deploymentModel) { 173 m_deploymentModel = deploymentModel; 174 } 175 176 181 public boolean isTransient() { 182 return m_isTransient; 183 } 184 185 190 public void setTransient(boolean isTransient) { 191 m_isTransient = isTransient; 192 } 193 194 199 public ClassInfo getMixinImpl() { 200 return AsmClassInfo.getClassInfo(m_mixinImplClassName, (ClassLoader ) m_loaderRef.get()); 201 } 202 203 208 public ExpressionInfo[] getExpressionInfos() { 209 return m_expressionInfos; 210 } 211 212 217 public List getInterfaceClassNames() { 218 return m_interfaceClassNames; 219 } 220 221 226 public String getAttribute() { 227 return m_attribute; 228 } 229 230 235 public void setAttribute(final String attribute) { 236 m_attribute = attribute; 237 } 238 239 244 public SystemDefinition getSystemDefinition() { 245 return m_systemDefinition; 246 } 247 248 253 public void addExpressionInfo(final ExpressionInfo expression) { 254 final ExpressionInfo[] tmpExpressions = new ExpressionInfo[m_expressionInfos.length + 1]; 255 java.lang.System.arraycopy(m_expressionInfos, 0, tmpExpressions, 0, m_expressionInfos.length); 256 tmpExpressions[m_expressionInfos.length] = expression; 257 m_expressionInfos = new ExpressionInfo[m_expressionInfos.length + 1]; 258 java.lang.System.arraycopy(tmpExpressions, 0, m_expressionInfos, 0, tmpExpressions.length); 259 } 260 261 266 public void addExpressionInfos(final ExpressionInfo[] expressions) { 267 final ExpressionInfo[] tmpExpressions = new ExpressionInfo[m_expressionInfos.length + expressions.length]; 268 java.lang.System.arraycopy(m_expressionInfos, 0, tmpExpressions, 0, m_expressionInfos.length); 269 java.lang.System.arraycopy(expressions, 0, tmpExpressions, m_expressionInfos.length, expressions.length); 270 m_expressionInfos = new ExpressionInfo[m_expressionInfos.length + expressions.length]; 271 java.lang.System.arraycopy(tmpExpressions, 0, m_expressionInfos, 0, tmpExpressions.length); 272 } 273 274 280 private ClassInfo defineSystemMixin(final ClassLoader loader) { 281 ClassInfo mixinClass = AsmClassInfo.getClassInfo(AdvisableImpl.class.getName(), loader); 283 MethodInfo[] methods = mixinClass.getMethods(); 284 for (int i = 0; i < methods.length; i++) { 285 MethodInfo method = methods[i]; 286 if (method.getName().startsWith(TransformationConstants.SYNTHETIC_MEMBER_PREFIX) 287 || method.getName().startsWith("aw_")) { m_methodsToIntroduce.add(method); 289 } 290 } 291 m_interfaceClassNames.add(Advisable.class.getName()); 292 return mixinClass; 293 } 294 295 301 private boolean isSystemMixin(final ClassInfo mixinClass) { 302 return mixinClass.getName().equals(AdvisableImpl.class.getName()); 303 } 304 305 311 public void addParameter(final String name, final String value) { 312 m_parameters.put(name, value); 313 } 314 315 320 public Map getParameters() { 321 return m_parameters; 322 } 323 324 } | Popular Tags |