1 8 package org.codehaus.aspectwerkz.extension.hotswap; 9 10 import org.codehaus.aspectwerkz.definition.*; 11 import org.codehaus.aspectwerkz.hook.impl.ClassPreProcessorHelper; 12 import org.codehaus.aspectwerkz.transform.AspectWerkzPreProcessor; 13 import org.codehaus.aspectwerkz.transform.ClassCacheTuple; 14 import org.codehaus.aspectwerkz.transform.inlining.deployer.Deployer; 15 import org.codehaus.aspectwerkz.transform.inlining.deployer.DeploymentHandle; 16 17 import java.util.Iterator ; 18 import java.util.List ; 19 import java.util.Map ; 20 import java.util.HashMap ; 21 import java.util.Set ; 22 23 28 public class EWorldUtil { 29 30 private static final Map s_weaveStatus = new HashMap (); 31 32 public static boolean isWeaved(final String uuid, final String aspectName) { 33 Map aspects = (Map ) s_weaveStatus.get(uuid); 34 if (aspects == null || aspects.keySet().size() == 0) { 35 return false; 36 } else { 37 Boolean status = (Boolean ) aspects.get(aspectName); 38 if (status == null) { 39 return false; 40 } else { 41 return status.booleanValue(); 42 } 43 } 44 } 45 46 public static void activate(final String uuid, 47 final String aspectName, 48 final String adviceName, 49 final String expression, 50 final String pointcutName) { 51 ClassLoader loader = EWorldUtil.class.getClassLoader(); 52 DeploymentScope scope = SystemDefinitionContainer.getDefinitionFor(loader, uuid).getDeploymentScope("demo"); 53 54 try { 55 Class aspect = Class.forName(aspectName, false, loader); 56 Deployer.deploy(aspect, 57 "<aspect class=\""+aspectName+"\">" 58 + "<advice name=\""+adviceName+"\" type=\"around\" bind-to=\""+expression+"\"/>" 59 + "</aspect>", 60 scope); 61 setStatus(uuid, aspectName, Boolean.TRUE); 62 } catch (Throwable t) { 63 t.printStackTrace(); 64 } 65 66 67 } 118 119 public static void deactivate(final String uuid, 120 final String aspectName, 121 final String adviceName, 122 final String pointcutName) { 123 ClassLoader loader = EWorldUtil.class.getClassLoader(); 124 DeploymentScope scope = SystemDefinitionContainer.getDefinitionFor(loader, uuid).getDeploymentScope("demo"); 125 126 try { 127 Class aspect = Class.forName(aspectName, false, loader); 128 Deployer.undeploy(aspect); 129 setStatus(uuid, aspectName, Boolean.FALSE); 130 } catch (Throwable t) { 131 t.printStackTrace(); 132 } 133 } 175 176 public static void activateCache(String expression, String pointcutName) { 177 activate( 178 "eworld/wlw/aop", 179 "examples.caching.CachingAspect", 180 "cache", 181 expression, 182 pointcutName 183 ); 184 } 185 186 public static void deactivateCache(String pointcutName) { 187 deactivate("eworld/wlw/aop", "examples.caching.CachingAspect", "cache", pointcutName); 188 } 189 190 public static void activateTrace(String expression, String pointcutName) { 191 activate( 192 "eworld/wlw/aop", 193 "examples.logging.LoggingAspect", 194 "logMethod", 195 expression, 196 pointcutName 197 ); 198 } 199 200 public static void deactivateTrace(String pointcutName) { 201 deactivate("eworld/wlw/aop", "examples.logging.LoggingAspect", "logMethod", pointcutName); 202 } 203 204 public static void hotswap(String classPattern) { 205 ClassLoader loader = EWorldUtil.class.getClassLoader(); 206 DeploymentScope scope = SystemDefinitionContainer.getDefinitionFor(loader, "eworld/wlw/aop").getDeploymentScope("demo"); 207 } 209 210 public static void dumpSystemDefinitions(ClassLoader loader) { 211 java.io.PrintStream out = System.out; 212 out.println("dumpSystemDefinitions [ " + loader + " ]"); 213 Set defs = SystemDefinitionContainer.getDefinitionsFor(loader); 214 for (Iterator sysDefs = defs.iterator(); sysDefs.hasNext();) { 215 SystemDefinition sysDef = (SystemDefinition) sysDefs.next(); 216 out.print(sysDef.getUuid()); 217 out.println(""); 218 for (Iterator prepares = sysDef.getPreparePackages().iterator(); prepares.hasNext();) { 219 out.print("[Prepare] " + prepares.next()); 220 out.println(""); 221 } 222 for (Iterator aspectDefs = sysDef.getAspectDefinitions().iterator(); aspectDefs 223 .hasNext();) { 224 AspectDefinition aspectDef = (AspectDefinition) aspectDefs.next(); 225 out.print("[Aspect] " + aspectDef.getName()); 226 out.println(""); 227 for (Iterator arounds = aspectDef.getAroundAdviceDefinitions().iterator(); arounds.hasNext();) { 228 AdviceDefinition around = (AdviceDefinition) arounds.next(); 229 out.print(" [AroundAdvice] " + around.getName()); 230 out.print(" "); 231 out.print(around.getExpressionInfo().toString()); 232 out.println(""); 233 } 234 out.println("\n-"); 235 } 236 out.println("\n----"); 237 } 238 } 239 240 private static void setStatus(final String uuid, final String aspectName, final Boolean status) { 241 Map aspects = (Map ) s_weaveStatus.get(uuid); 242 if (aspects == null) { 243 aspects = new HashMap (); 244 s_weaveStatus.put(uuid, aspects); 245 } 246 aspects.put(aspectName, status); 247 } 248 } | Popular Tags |