org.jboss.deployment.scope
Class ScopedURLClassLoader

java.lang.Object
  |
  +--java.lang.ClassLoader
        |
        +--java.security.SecureClassLoader
              |
              +--java.net.URLClassLoader
                    |
                    +--org.jboss.deployment.scope.ScopedURLClassLoader

public class ScopedURLClassLoader
extends java.net.URLClassLoader

A URLClassLoader that is tight to some J2EE deployment and that is able to share classes/resources under the associated scope. Hey, JDK-S**ckers why did you annotate getResources final?

Version:
0.9
Author:
cgjung

Field Summary
protected  Deployment deployment
          reference to the deployment that is associated with this classloader
protected  Scope scope
          reference to the scope to which resource loading calls can be delegated to.
 
Constructor Summary
ScopedURLClassLoader(java.net.URL[] urls, java.lang.ClassLoader parent, Deployment deployment, Scope scope)
          Creates new ScopedURLClassLoader given a set of urls and a parent, representing a particular deployment
 
Method Summary
 java.lang.String[] getDependingApplications()
          returns a set of relative urls in string spec that point to applications to which this application is (most likely) dependent on.
 java.net.URL getResource(java.lang.String name)
          redirects getResource in case that it could not be found locally
protected  java.net.URL getResourceProperly(java.lang.String name)
          exposes the proper getResource call
protected  java.lang.Class loadClass(java.lang.String name, boolean resolve)
          redirects loadClass in case that it could not be found locally
protected  java.lang.Class loadClassProperly(java.lang.String name, boolean resolve)
          exposes the proper loadClass call
protected  void onDeploy()
          what happens on deploy, could be overridden to setup down meta-data and such
protected  void onUndeploy()
          what happens on undeploy, could be overridden to tear down meta-data and such
 
Methods inherited from class java.net.URLClassLoader
addURL, definePackage, findClass, findResource, findResources, getPermissions, getURLs, newInstance, newInstance
 
Methods inherited from class java.security.SecureClassLoader
defineClass
 
Methods inherited from class java.lang.ClassLoader
defineClass, defineClass, defineClass, definePackage, findLibrary, findLoadedClass, findSystemClass, getPackage, getPackages, getParent, getResourceAsStream, getResources, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, loadClass, resolveClass, setSigners
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

scope

protected final Scope scope
reference to the scope to which resource loading calls can be delegated to.

deployment

protected final Deployment deployment
reference to the deployment that is associated with this classloader
Constructor Detail

ScopedURLClassLoader

public ScopedURLClassLoader(java.net.URL[] urls,
                            java.lang.ClassLoader parent,
                            Deployment deployment,
                            Scope scope)
Creates new ScopedURLClassLoader given a set of urls and a parent, representing a particular deployment
Parameters:
urls - the urls for which this classloader is built.
parent - parent classloader
deployment - deployment to deploy into this loader
scope - the scope that this classloader takes part
Method Detail

loadClassProperly

protected java.lang.Class loadClassProperly(java.lang.String name,
                                            boolean resolve)
                                     throws java.lang.ClassNotFoundException
exposes the proper loadClass call
Parameters:
name - name of the class
resolve - whether the class should be resolved
Returns:
the found class
Throws:
java.lang.ClassNotFoundException - if the class cannot be found

loadClass

protected java.lang.Class loadClass(java.lang.String name,
                                    boolean resolve)
                             throws java.lang.ClassNotFoundException
redirects loadClass in case that it could not be found locally
Overrides:
loadClass in class java.lang.ClassLoader
Parameters:
name - name of the class
resolve - whether the class should be resolved
Returns:
the found java class
Throws:
java.lang.ClassNotFoundException - if the class could not be found

getResourceProperly

protected java.net.URL getResourceProperly(java.lang.String name)
exposes the proper getResource call
Parameters:
name - name of the resource
Returns:
URL pointing to the resource, null if it could not be found

getResource

public java.net.URL getResource(java.lang.String name)
redirects getResource in case that it could not be found locally
Overrides:
getResource in class java.lang.ClassLoader
Parameters:
name - name of the resource
Returns:
URL pointing to the resource, null if it cannot be found

onDeploy

protected void onDeploy()
                 throws J2eeDeploymentException
what happens on deploy, could be overridden to setup down meta-data and such
Throws:
J2eeDeploymentException - if this stage of deployment fails for some reason

onUndeploy

protected void onUndeploy()
                   throws J2eeDeploymentException
what happens on undeploy, could be overridden to tear down meta-data and such
Throws:
J2eeDeploymentException - if this last stage of undeployment fails for some reason

getDependingApplications

public java.lang.String[] getDependingApplications()
returns a set of relative urls in string spec that point to applications to which this application is (most likely) dependent on. Works via analysing the Class-Path: in the Manifest.mf. Marc: Please note that sharing scope works also without having these explicit annotations. However, there may be circular dependencies that are already relevant at deployment time (e.g., bean verification) which you otherwise could never setup manually (i.e., by calling the deploy method).
Returns:
relative string-url specs pointing to ears.


Copyright © 2000 The JBoss Organization. All Rights Reserved.