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