org.apache.commons.jelly.impl
Class DefaultTagLibraryResolver

java.lang.Object
  extended by org.apache.commons.jelly.impl.DefaultTagLibraryResolver
All Implemented Interfaces:
TagLibraryResolver

public class DefaultTagLibraryResolver
extends java.lang.Object
implements TagLibraryResolver

DefaultTagLibraryResolver is a default implemenation which attempts to interpret the URI as a String called 'jelly:className' and class load the given Java class. Otherwise META-INF/services/jelly/uri is searched for on the thread context's class path and, if found, that class will be loaded.

Version:
$Revision: 1807798 $
Author:
James Strachan

Field Summary
private  java.lang.ClassLoader classLoader
          The class loader to use for instantiating application objects.
private  org.apache.commons.discovery.resource.classes.DiscoverClasses discovery
           
private static org.apache.commons.logging.Log log
          The Log to which logging calls will be made.
private  boolean useContextClassLoader
          Do we want to use the Context ClassLoader when loading classes for instantiating new objects? Default is false.
 
Constructor Summary
DefaultTagLibraryResolver()
           
 
Method Summary
 java.lang.ClassLoader getClassLoader()
          Return the class loader to be used for instantiating application objects when required.
 org.apache.commons.discovery.resource.classes.DiscoverClasses getDiscoverClasses()
           
 boolean getUseContextClassLoader()
          Return the boolean as to whether the context classloader should be used.
protected  TagLibrary loadClass(java.lang.String uri, java.lang.String className)
          Instantiates the given class name.
protected  TagLibrary newInstance(java.lang.String uri, java.lang.Class theClass)
          Creates a new instance of the given TagLibrary class or return null if it could not be instantiated.
 TagLibrary resolveTagLibrary(java.lang.String uri)
          Attempts to resolve the given URI to be associated with a TagLibrary otherwise null is returned to indicate no tag library could be found so that the namespace URI should be treated as just vanilla XML.
 void setClassLoader(java.lang.ClassLoader classLoader)
          Set the class loader to be used for instantiating application objects when required.
 void setDiscoverClasses(org.apache.commons.discovery.resource.classes.DiscoverClasses discovery)
          Sets the fully configured DiscoverClasses instance to be used to lookup services
 void setUseContextClassLoader(boolean use)
          Determine whether to use the Context ClassLoader (the one found by calling Thread.currentThread().getContextClassLoader()) to resolve/load classes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

private static final org.apache.commons.logging.Log log
The Log to which logging calls will be made.


discovery

private org.apache.commons.discovery.resource.classes.DiscoverClasses discovery

classLoader

private java.lang.ClassLoader classLoader
The class loader to use for instantiating application objects. If not specified, the context class loader, or the class loader used to load this class itself, is used, based on the value of the useContextClassLoader variable.


useContextClassLoader

private boolean useContextClassLoader
Do we want to use the Context ClassLoader when loading classes for instantiating new objects? Default is false.

Constructor Detail

DefaultTagLibraryResolver

public DefaultTagLibraryResolver()
Method Detail

resolveTagLibrary

public TagLibrary resolveTagLibrary(java.lang.String uri)
Attempts to resolve the given URI to be associated with a TagLibrary otherwise null is returned to indicate no tag library could be found so that the namespace URI should be treated as just vanilla XML.

Specified by:
resolveTagLibrary in interface TagLibraryResolver

getClassLoader

public java.lang.ClassLoader getClassLoader()
Return the class loader to be used for instantiating application objects when required. This is determined based upon the following rules:


setClassLoader

public void setClassLoader(java.lang.ClassLoader classLoader)
Set the class loader to be used for instantiating application objects when required.

Parameters:
classLoader - The new class loader to use, or null to revert to the standard rules

getUseContextClassLoader

public boolean getUseContextClassLoader()
Return the boolean as to whether the context classloader should be used.


setUseContextClassLoader

public void setUseContextClassLoader(boolean use)
Determine whether to use the Context ClassLoader (the one found by calling Thread.currentThread().getContextClassLoader()) to resolve/load classes. If not using Context ClassLoader, then the class-loading defaults to using the calling-class' ClassLoader.

Parameters:
boolean - determines whether to use JellyContext ClassLoader.

getDiscoverClasses

public org.apache.commons.discovery.resource.classes.DiscoverClasses getDiscoverClasses()
Returns:
the DiscoverClasses instance to use to locate services. This object is lazily created if it has not been configured.

setDiscoverClasses

public void setDiscoverClasses(org.apache.commons.discovery.resource.classes.DiscoverClasses discovery)
Sets the fully configured DiscoverClasses instance to be used to lookup services


loadClass

protected TagLibrary loadClass(java.lang.String uri,
                               java.lang.String className)
Instantiates the given class name. Otherwise an exception is logged and null is returned


newInstance

protected TagLibrary newInstance(java.lang.String uri,
                                 java.lang.Class theClass)
Creates a new instance of the given TagLibrary class or return null if it could not be instantiated.