1 4 package com.tc.aspectwerkz.transform.inlining.deployer; 5 6 import com.tc.aspectwerkz.definition.AdviceDefinition; 7 import com.tc.aspectwerkz.definition.AspectDefinition; 8 import com.tc.aspectwerkz.definition.SystemDefinition; 9 import com.tc.aspectwerkz.definition.SystemDefinitionContainer; 10 import com.tc.aspectwerkz.expression.ExpressionInfo; 11 import com.tc.aspectwerkz.util.UuidGenerator; 12 13 import java.lang.ref.WeakReference ; 14 import java.util.HashMap ; 15 import java.util.Iterator ; 16 import java.util.Map ; 17 18 27 public final class DeploymentHandle { 28 29 private final String UUID; 30 private final Map m_definitionChangeElements = new HashMap (); 31 private final WeakReference m_loaderRef; 32 private final WeakReference m_classRef; 33 34 39 DeploymentHandle(final Class clazz, final ClassLoader loader) { 40 if (clazz == null) { 41 throw new IllegalArgumentException ("class can not be null"); 42 } 43 if (loader == null) { 44 throw new IllegalArgumentException ("loader can not be null"); 45 } 46 UUID = UuidGenerator.generate(clazz); 48 m_loaderRef = new WeakReference (loader); 49 m_classRef = new WeakReference (clazz); 50 } 51 52 void registerDefinitionChange(final AdviceDefinition adviceDef, final ExpressionInfo oldExpression) { 53 m_definitionChangeElements.put( 54 adviceDef.getQualifiedName(), 55 new DefinitionChangeElement(adviceDef, oldExpression) 56 ); 57 } 58 59 Class getAspectClass() { 60 return (Class ) m_classRef.get(); 61 } 62 63 Map getDefintionChangeElements() { 64 return m_definitionChangeElements; 65 } 66 67 void revertChanges() { 68 final ClassLoader loader = (ClassLoader ) m_loaderRef.get(); 69 SystemDefinition systemDef = SystemDefinitionContainer.getVirtualDefinitionFor(loader); 71 for (Iterator it2 = systemDef.getAspectDefinitions().iterator(); it2.hasNext();) { 72 AspectDefinition aspectDef = (AspectDefinition) it2.next(); 73 for (Iterator it3 = aspectDef.getAfterAdviceDefinitions().iterator(); it3.hasNext();) { 74 AdviceDefinition adviceDef = (AdviceDefinition) it3.next(); 75 DefinitionChangeElement changeElement = 76 (DefinitionChangeElement) m_definitionChangeElements.get(adviceDef.getQualifiedName()); 77 if (changeElement != null) { 78 changeElement.getAdviceDef().setExpressionInfo(changeElement.getOldExpression()); 79 } 80 } 81 } 82 } 83 84 public String toString() { 85 return new StringBuffer ().append("DeploymentHandle ["). 86 append(UUID.toString()).append(','). 87 append(((Class ) m_classRef.get()).getName()).append(','). 88 append(m_loaderRef.get()).append(']').toString(); 89 } 90 91 public int hashCode() { 92 return UUID.hashCode(); 93 } 94 95 public boolean equals(Object o) { 96 return ((DeploymentHandle) o).UUID.equals(UUID); 97 } 98 99 104 static class DefinitionChangeElement { 105 private final AdviceDefinition m_adviceDef; 106 private final ExpressionInfo m_oldExpression; 107 108 public DefinitionChangeElement(final AdviceDefinition adviceDef, final ExpressionInfo oldExpression) { 109 m_adviceDef = adviceDef; 110 m_oldExpression = oldExpression; 111 } 112 113 public ExpressionInfo getOldExpression() { 114 return m_oldExpression; 115 } 116 117 public AdviceDefinition getAdviceDef() { 118 return m_adviceDef; 119 } 120 } 121 } 122 | Popular Tags |