KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > aop > deployment > JBossClassPoolFactory32


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.deployment;
23
24 import java.io.File JavaDoc;
25 import java.io.IOException JavaDoc;
26 import java.net.URL JavaDoc;
27 import org.jboss.mx.loading.UnifiedClassLoader;
28 import javassist.ClassPool;
29 import javassist.scopedpool.ScopedClassPool;
30 import javassist.scopedpool.ScopedClassPoolFactory;
31 import javassist.scopedpool.ScopedClassPoolRepository;
32
33 /**
34  * Comment
35  *
36  * @author <a HREF="mailto:bill@jboss.org">Bill Burke</a>
37  * @version $Revision: 46259 $
38  *
39  **/

40 public class JBossClassPoolFactory32 implements ScopedClassPoolFactory
41 {
42    protected File JavaDoc tmpClassesDir;
43
44    public JBossClassPoolFactory32(File JavaDoc tmpClassesDir) throws IOException JavaDoc
45    {
46       this.tmpClassesDir = tmpClassesDir;
47
48    }
49    public ScopedClassPool create(ClassLoader JavaDoc cl, ClassPool src, ScopedClassPoolRepository repository)
50    {
51       try
52       {
53          File JavaDoc tempdir = createTempDir(cl);
54          return new JBossClassPool32(cl, src, repository, tempdir);
55       }
56       catch (IOException JavaDoc e)
57       {
58          throw new RuntimeException JavaDoc(e);
59       }
60    }
61
62    public ScopedClassPool create(ClassPool src, ScopedClassPoolRepository repository)
63    {
64       return new JBossClassPool32(src, repository);
65    }
66
67    public File JavaDoc createTempDir(ClassLoader JavaDoc cl) throws IOException JavaDoc
68    {
69       if (!(cl instanceof UnifiedClassLoader)) return null;
70       File JavaDoc tempdir = File.createTempFile("ucl", "", tmpClassesDir);
71       tempdir.delete();
72       tempdir.mkdir();
73       tempdir.deleteOnExit();
74       UnifiedClassLoader ucl = (UnifiedClassLoader) cl;
75       URL JavaDoc tmpURL = tempdir.toURL();
76       URL JavaDoc tmpCP = new URL JavaDoc(tmpURL, "?dynamic=true");
77       // we may be shutting down.
78
if (ucl.getLoaderRepository() != null) ucl.addURL(tmpCP);
79       return tempdir;
80    }
81 }
82
Popular Tags