KickJava   Java API By Example, From Geeks To Geeks.

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


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 javassist.CannotCompileException;
25 import javassist.ClassPool;
26 import javassist.CtClass;
27 import javassist.NotFoundException;
28 import javassist.scopedpool.ScopedClassPoolRepository;
29
30 import org.jboss.aop.classpool.AOPClassPool;
31
32 /**
33  * Comment
34  *
35  * @author <a HREF="mailto:bill@jboss.org">Bill Burke</a>
36  * @version $Revision: 46253 $
37  * @deprecated Will be removed when Javassist is upgraded past 3.0 beta2
38  */

39 public class StandaloneClassPool extends AOPClassPool
40 {
41    public StandaloneClassPool(ClassLoader JavaDoc cl, ClassPool src, ScopedClassPoolRepository repository)
42    {
43       super(cl, src, repository);
44    }
45
46    public StandaloneClassPool(ClassPool src, ScopedClassPoolRepository repository)
47    {
48       super(src, repository);
49    }
50
51    //KAB: removed NotFoundException, IOException from throws clause, as
52
//they are not defined by javassist.ClassPool
53
public Class JavaDoc toClass(CtClass ctClass) throws CannotCompileException/*, NotFoundException, IOException*/
54    {
55       try
56       {
57          byte[] b = ctClass.toBytecode();
58          Class JavaDoc cl = Class.forName("java.lang.ClassLoader");
59          java.lang.reflect.Method JavaDoc method
60                  = cl.getDeclaredMethod("defineClass",
61                          new Class JavaDoc[]{String JavaDoc.class, byte[].class,
62                                      int.class, int.class});
63          method.setAccessible(true);
64          Object JavaDoc[] args = new Object JavaDoc[]{ctClass.getName(), b, new Integer JavaDoc(0),
65                                       new Integer JavaDoc(b.length)};
66          Class JavaDoc clazz = (Class JavaDoc) method.invoke(getClassLoader(), args);
67          method.setAccessible(false);
68          return clazz;
69       }
70       catch (RuntimeException JavaDoc e)
71       {
72          throw e;
73       }
74       catch (java.lang.reflect.InvocationTargetException JavaDoc e)
75       {
76          throw new CannotCompileException(e);
77       }
78       catch (Exception JavaDoc e)
79       {
80          throw new CannotCompileException(e);
81       }
82    }
83
84    public synchronized CtClass getLocally(String JavaDoc classname) throws NotFoundException
85    {
86       return super.getLocally(classname);
87    }
88 }
89
Popular Tags