KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.jboss.aop.AspectManager;
25 import org.jboss.aop.Domain;
26 import org.jboss.aop.classpool.AOPScopedClassLoaderHelper;
27 import org.jboss.mx.loading.HeirarchicalLoaderRepository3;
28 import org.jboss.mx.loading.LoaderRepository;
29 import org.jboss.mx.loading.RepositoryClassLoader;
30
31 /**
32  *
33  * @author <a HREF="kabir.khan@jboss.com">Kabir Khan</a>
34  * @version $Revision$
35  */

36 public class JBossScopedClassLoaderHelper implements AOPScopedClassLoaderHelper
37 {
38    public ClassLoader JavaDoc ifScopedDeploymentGetScopedParentUclForCL(ClassLoader JavaDoc loader)
39    {
40       ClassLoader JavaDoc parent = loader;
41       //The web classloader will be a child of the unified classloader - find out if that is scoped
42
while (parent != null)
43       {
44          if (isScopedClassLoader(parent))
45          {
46             return parent;
47          }
48          if (parent instanceof RepositoryClassLoader)
49          {
50             //We were a repository classloader, but not scoped - ignore the parents like a sulky teenager
51
return null;
52          }
53          parent = parent.getParent();
54       }
55       return null;
56    }
57    
58    public static boolean isScopedClassLoader(ClassLoader JavaDoc loader)
59    {
60       boolean scoped = false;
61       if (loader instanceof RepositoryClassLoader)
62       {
63          LoaderRepository repository = ((RepositoryClassLoader)loader).getLoaderRepository();
64          if (repository instanceof HeirarchicalLoaderRepository3)
65          {
66             scoped = true;
67             HeirarchicalLoaderRepository3 hlr = (HeirarchicalLoaderRepository3)repository;
68             boolean parentFirst = hlr.getUseParentFirst();
69          }
70       }
71       return scoped;
72    }
73    
74
75    public ClassLoader JavaDoc getTopLevelJBossClassLoader()
76    {
77       ClassLoader JavaDoc loader = Thread.currentThread().getContextClassLoader();
78       RepositoryClassLoader topRcl = null;
79       while (loader != null)
80       {
81          if (loader instanceof RepositoryClassLoader)
82          {
83             topRcl = (RepositoryClassLoader)loader;
84          }
85          loader = loader.getParent();
86       }
87       return topRcl;
88    }
89
90    public Domain getScopedClassLoaderDomain(ClassLoader JavaDoc cl, AspectManager parent)
91    {
92       boolean parentDelegation = true;
93       if (cl instanceof RepositoryClassLoader)
94       {
95          HeirarchicalLoaderRepository3 repository = (HeirarchicalLoaderRepository3)((RepositoryClassLoader)cl).getLoaderRepository();
96          parentDelegation = repository.getUseParentFirst();
97       }
98       String JavaDoc name = String.valueOf(System.identityHashCode(cl));
99       return new ScopedClassLoaderDomain(cl, name, parentDelegation, parent, false);
100    }
101
102 }
103
Popular Tags