KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > aop > standalone > AOPTransformer


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

22 package org.jboss.aop.standalone;
23
24 import org.jboss.aop.AspectManager;
25
26 import java.lang.instrument.ClassFileTransformer JavaDoc;
27 import java.lang.instrument.IllegalClassFormatException JavaDoc;
28 import java.security.ProtectionDomain JavaDoc;
29
30 /**
31  * Comment
32  *
33  * @author <a HREF="mailto:bill@jboss.org">Bill Burke</a>
34  * @version $Revision: 44099 $
35  */

36 public class AOPTransformer implements ClassFileTransformer JavaDoc
37 {
38    public boolean isNonAdvisableClassName(String JavaDoc classname)
39    {
40       return (classname.startsWith("org.jboss.aop") ||
41       classname.endsWith("$aop") ||
42       classname.startsWith("javassist") ||
43       classname.startsWith("org.jboss.util.") ||
44       classname.startsWith("gnu.trove.") ||
45       classname.startsWith("EDU.oswego.cs.dl.util.concurrent.") ||
46       // System classes
47
classname.startsWith("org.apache.crimson") ||
48       classname.startsWith("org.apache.xalan") ||
49       classname.startsWith("org.apache.xml") ||
50       classname.startsWith("org.apache.xpath") ||
51       classname.startsWith("org.ietf.") ||
52       classname.startsWith("org.omg.") ||
53       classname.startsWith("org.w3c.") ||
54       classname.startsWith("org.xml.sax.") ||
55       classname.startsWith("sunw.") ||
56       classname.startsWith("sun.") ||
57       classname.startsWith("java.") ||
58       classname.startsWith("javax.") ||
59       classname.startsWith("com.sun.")
60       );
61    }
62
63    public byte[] transform(ClassLoader JavaDoc loader, String JavaDoc className, Class JavaDoc<?> classBeingRedefined, ProtectionDomain JavaDoc protectionDomain, byte[] classfileBuffer) throws IllegalClassFormatException JavaDoc
64    {
65       className = className.replace('/', '.');
66       //System.out.println("<<< loading " + className);
67
try
68       {
69          if (classBeingRedefined != null || isNonAdvisableClassName(className))
70          {
71             //System.out.println(" ignoring");
72
return null;
73          }
74          //System.out.println(" transforming");
75
return aspectTransform(className, loader, classBeingRedefined, protectionDomain, classfileBuffer);
76       }
77       finally
78       {
79          //System.out.println("finished " + className + ">>>");
80
}
81    }
82
83    private byte[] aspectTransform(String JavaDoc className, ClassLoader JavaDoc loader, Class JavaDoc<?> classBeingRedefined, ProtectionDomain JavaDoc protectionDomain, byte[] classfileBuffer)
84    {
85       try
86       {
87          //Make sure that we use the correct classloader, in order to get the correct domain if it is a scoped loader
88
return AspectManager.instance(loader).transform(loader, className, classBeingRedefined, protectionDomain, classfileBuffer);
89       }
90       catch (Exception JavaDoc e)
91       {
92          throw new RuntimeException JavaDoc(e);
93       }
94    }
95 }
96
Popular Tags