Source Code Cross Referenced for EWorldUtil.java in  » Aspect-oriented » aspectwerkz-2.0 » org » codehaus » aspectwerkz » extension » hotswap » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Aspect oriented » aspectwerkz 2.0 » org.codehaus.aspectwerkz.extension.hotswap 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**************************************************************************************
002:         * Copyright (c) Jonas Bon?r, Alexandre Vasseur. All rights reserved.                 *
003:         * http://aspectwerkz.codehaus.org                                                    *
004:         * ---------------------------------------------------------------------------------- *
005:         * The software in this package is published under the terms of the LGPL license      *
006:         * a copy of which has been included with this distribution in the license.txt file.  *
007:         **************************************************************************************/package org.codehaus.aspectwerkz.extension.hotswap;
008:
009:        import org.codehaus.aspectwerkz.definition.*;
010:        import org.codehaus.aspectwerkz.hook.impl.ClassPreProcessorHelper;
011:        import org.codehaus.aspectwerkz.transform.AspectWerkzPreProcessor;
012:        import org.codehaus.aspectwerkz.transform.ClassCacheTuple;
013:        import org.codehaus.aspectwerkz.transform.inlining.deployer.Deployer;
014:        import org.codehaus.aspectwerkz.transform.inlining.deployer.DeploymentHandle;
015:
016:        import java.util.Iterator;
017:        import java.util.List;
018:        import java.util.Map;
019:        import java.util.HashMap;
020:        import java.util.Set;
021:
022:        /**
023:         * eworld/wlw/aop
024:         *
025:         * @author <a href="mailto:alex@gnilux.com">Alexandre Vasseur </a>
026:         */
027:        public class EWorldUtil {
028:
029:            private static final Map s_weaveStatus = new HashMap();
030:
031:            public static boolean isWeaved(final String uuid,
032:                    final String aspectName) {
033:                Map aspects = (Map) s_weaveStatus.get(uuid);
034:                if (aspects == null || aspects.keySet().size() == 0) {
035:                    return false;
036:                } else {
037:                    Boolean status = (Boolean) aspects.get(aspectName);
038:                    if (status == null) {
039:                        return false;
040:                    } else {
041:                        return status.booleanValue();
042:                    }
043:                }
044:            }
045:
046:            public static void activate(final String uuid,
047:                    final String aspectName, final String adviceName,
048:                    final String expression, final String pointcutName) {
049:                ClassLoader loader = EWorldUtil.class.getClassLoader();
050:                DeploymentScope scope = SystemDefinitionContainer
051:                        .getDefinitionFor(loader, uuid).getDeploymentScope(
052:                                "demo");
053:
054:                try {
055:                    Class aspect = Class.forName(aspectName, false, loader);
056:                    Deployer.deploy(aspect, "<aspect class=\"" + aspectName
057:                            + "\">" + "<advice name=\"" + adviceName
058:                            + "\" type=\"around\" bind-to=\"" + expression
059:                            + "\"/>" + "</aspect>", scope);
060:                    setStatus(uuid, aspectName, Boolean.TRUE);
061:                } catch (Throwable t) {
062:                    t.printStackTrace();
063:                }
064:
065:                //        System.out.println(
066:                //                "activate = " + uuid + "," + aspectName + "." + adviceName + " @ " + expression + "," +
067:                // pointcutName
068:                //        );
069:                //        SystemDefinition sysDef = SystemDefinitionContainer.getSystemDefinition(
070:                //                ClassLoader.getSystemClassLoader(), uuid
071:                //        );
072:                //        if (sysDef == null) {
073:                //            return;
074:                //        }
075:                //        AspectDefinition aspectDef = sysDef.getAspectDefinition(aspectName);
076:                //
077:                //        Expression pcExpression =
078:                // ExpressionNamespace.getExpressionNamespace(aspectDef).createExpression(
079:                //                expression,
080:                //                "",
081:                //                pointcutName
082:                //        );
083:                //
084:                //        AdviceDefinition newDef = null;
085:                //        boolean found = false;
086:                //        for (Iterator arounds = aspectDef.getAroundAdviceDefinitions().iterator(); arounds.hasNext();) {
087:                //            AdviceDefinition around = (AdviceDefinition)arounds.next();
088:                //            if (around.getName().equals(aspectName + "." + adviceName)) {
089:                //                // copy the logMethod advice
090:                //                // note: we could add a totally new advice as well
091:                //                newDef = around.copyAt(pcExpression);
092:                //
093:                //                // take care of the runtime Pointcut mirror if any
094:                //                CflowStack as = SystemLoader.getCflowStack(ClassLoader.getSystemClassLoader());
095:                //                AspectManager am = as.getAspectManager(uuid);
096:                //                Pointcut pc =
097:                // am.getPointcutManager(aspectDef.getName()).getPointcut(newDef.getExpression().getExpression());
098:                //                if (pc!=null) {
099:                //                    pc.addAroundAdvice(aspectDef.getName() + "/" + around.getName());
100:                //                }
101:                //
102:                //                System.out.println("<adding> " + around.getName() + " at " + pointcutName);
103:                //                found = true;
104:                //                break;
105:                //            }
106:                //        }
107:                //        if (!found) {
108:                //            System.err.println(" advice not found");
109:                //        }
110:                //        else {
111:                //            aspectDef.addAroundAdvice(newDef);
112:                //            StartupManager.reinitializeSystem(ClassLoader.getSystemClassLoader(), sysDef);
113:                //        }
114:                //        setStatus(uuid, aspectName, Boolean.TRUE);
115:            }
116:
117:            public static void deactivate(final String uuid,
118:                    final String aspectName, final String adviceName,
119:                    final String pointcutName) {
120:                ClassLoader loader = EWorldUtil.class.getClassLoader();
121:                DeploymentScope scope = SystemDefinitionContainer
122:                        .getDefinitionFor(loader, uuid).getDeploymentScope(
123:                                "demo");
124:
125:                try {
126:                    Class aspect = Class.forName(aspectName, false, loader);
127:                    Deployer.undeploy(aspect);
128:                    setStatus(uuid, aspectName, Boolean.FALSE);
129:                } catch (Throwable t) {
130:                    t.printStackTrace();
131:                }
132:                //
133:                //        System.out.println("deactivate = " + uuid + "," + aspectName + "." + adviceName + " @ " +
134:                // pointcutName);
135:                //        SystemDefinition sysDef = SystemDefinitionContainer.getSystemDefinition(
136:                //                ClassLoader.getSystemClassLoader(), uuid
137:                //        );
138:                //        if (sysDef == null) {
139:                //            return;
140:                //        }
141:                //        AspectDefinition aspectDef = sysDef.getAspectDefinition(aspectName);
142:                //
143:                //        List removedAdviceDefs = new ArrayList();
144:                //        boolean found = false;
145:                //        for (Iterator arounds = aspectDef.getAroundAdviceDefinitions().iterator(); arounds.hasNext();) {
146:                //            AdviceDefinition around = (AdviceDefinition)arounds.next();
147:                //            if (around.getName().equals(aspectName + "." + adviceName)) {
148:                //                found = true;
149:                //                if (pointcutName.equals(around.getExpression().getName()) ||
150:                //                    pointcutName.equals(around.getExpression().getExpression())) {
151:                //
152:                //                    // take care of the runtime Pointcut mirror if any
153:                //                    CflowStack as = SystemLoader.getCflowStack(ClassLoader.getSystemClassLoader());
154:                //                    AspectManager am = as.getAspectManager(uuid);
155:                //                    Pointcut pc =
156:                // am.getPointcutManager(aspectDef.getName()).getPointcut(around.getExpression().getExpression());
157:                //                    pc.removeAroundAdvice(aspectDef.getName() + "/" + around.getName());
158:                //
159:                //                    System.out.println("<removing> " + around.getName() + " at " + pointcutName);
160:                //                    removedAdviceDefs.add(around);
161:                //                }
162:                //            }
163:                //        }
164:                //        if (!found) {
165:                //            System.err.println(" advice not found");
166:                //        }
167:                //        for (Iterator arounds = removedAdviceDefs.iterator(); arounds.hasNext();) {
168:                //            aspectDef.removeAroundAdvice((AdviceDefinition)arounds.next());
169:                //        }
170:                //        StartupManager.reinitializeSystem(ClassLoader.getSystemClassLoader(), sysDef);
171:                //
172:                //        setStatus(uuid, aspectName, Boolean.FALSE);
173:            }
174:
175:            public static void activateCache(String expression,
176:                    String pointcutName) {
177:                activate("eworld/wlw/aop", "examples.caching.CachingAspect",
178:                        "cache", expression, pointcutName);
179:            }
180:
181:            public static void deactivateCache(String pointcutName) {
182:                deactivate("eworld/wlw/aop", "examples.caching.CachingAspect",
183:                        "cache", pointcutName);
184:            }
185:
186:            public static void activateTrace(String expression,
187:                    String pointcutName) {
188:                activate("eworld/wlw/aop", "examples.logging.LoggingAspect",
189:                        "logMethod", expression, pointcutName);
190:            }
191:
192:            public static void deactivateTrace(String pointcutName) {
193:                deactivate("eworld/wlw/aop", "examples.logging.LoggingAspect",
194:                        "logMethod", pointcutName);
195:            }
196:
197:            public static void hotswap(String classPattern) {
198:                ClassLoader loader = EWorldUtil.class.getClassLoader();
199:                DeploymentScope scope = SystemDefinitionContainer
200:                        .getDefinitionFor(loader, "eworld/wlw/aop")
201:                        .getDeploymentScope("demo");
202:                //throw new UnsupportedOperationException("not supported in AW 2.0");
203:            }
204:
205:            public static void dumpSystemDefinitions(ClassLoader loader) {
206:                java.io.PrintStream out = System.out;
207:                out.println("dumpSystemDefinitions [ " + loader + " ]");
208:                Set defs = SystemDefinitionContainer.getDefinitionsFor(loader);
209:                for (Iterator sysDefs = defs.iterator(); sysDefs.hasNext();) {
210:                    SystemDefinition sysDef = (SystemDefinition) sysDefs.next();
211:                    out.print(sysDef.getUuid());
212:                    out.println("");
213:                    for (Iterator prepares = sysDef.getPreparePackages()
214:                            .iterator(); prepares.hasNext();) {
215:                        out.print("[Prepare] " + prepares.next());
216:                        out.println("");
217:                    }
218:                    for (Iterator aspectDefs = sysDef.getAspectDefinitions()
219:                            .iterator(); aspectDefs.hasNext();) {
220:                        AspectDefinition aspectDef = (AspectDefinition) aspectDefs
221:                                .next();
222:                        out.print("[Aspect] " + aspectDef.getName());
223:                        out.println("");
224:                        for (Iterator arounds = aspectDef
225:                                .getAroundAdviceDefinitions().iterator(); arounds
226:                                .hasNext();) {
227:                            AdviceDefinition around = (AdviceDefinition) arounds
228:                                    .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,
241:                    final String aspectName, final Boolean status) {
242:                Map aspects = (Map) s_weaveStatus.get(uuid);
243:                if (aspects == null) {
244:                    aspects = new HashMap();
245:                    s_weaveStatus.put(uuid, aspects);
246:                }
247:                aspects.put(aspectName, status);
248:            }
249:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.