jackrabbit-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Felix Meschberger (JIRA)" <j...@apache.org>
Subject [jira] Commented: (JCR-561) Add support to provide custom classloader for class instantiation from configuration
Date Mon, 04 Sep 2006 11:04:23 GMT
    [ http://issues.apache.org/jira/browse/JCR-561?page=comments#action_12432487 ] 
            
Felix Meschberger commented on JCR-561:
---------------------------------------

Added said extension in Rev. 440026.

Use of this functionality is very crude as the default class loader has to be set before loading
the configuration:

    BeanConfig.setDefaultClassLoader(someNewClassLoader)
    RepositoryConfig crc = RepositoryConfig.create(ins, home);

This way, all BeanConfig instances (actually all configurtion objects extending BeanConfig)
are set with the given someNewClassLoader. Of course, for this to work, the class loader set
must also see the Jackrabbit classes.

The default class loader used, if the setDefaultClassLoader is not called, is the class loader
of the BeanConfig class. As such, this enhancement is fully backwards compatible.

> Add support to provide custom classloader for class instantiation from configuration
> ------------------------------------------------------------------------------------
>
>                 Key: JCR-561
>                 URL: http://issues.apache.org/jira/browse/JCR-561
>             Project: Jackrabbit
>          Issue Type: Improvement
>          Components: config
>    Affects Versions: 0.9, 1.0, 1.0.1
>            Reporter: Felix Meschberger
>         Assigned To: Felix Meschberger
>             Fix For: 1.1
>
>
> The configuration framework is based around a BaseConfig class, which provides functionality
to instantiate a class whose name is configured in the repository configuration file. Examples
of such classes are the FileSystem or the PersistenceManager elements.
> The current implementation of the BeanConfig.newInstance() method is to use the "default
classloader" to load configured classes. That is, the class loader of the BeanConfig class
is actually used. This is - generally - the class loader which loads the repository. In certain
environments, classes may be provided from outside the core repository class loader. An example
fo such an environment is an OSGi setup where each bundle gets its own class laoder, which
is separate from all other class loaders except declared by configuration.
> I propose to enhance the BeanConfig class as follows:
> public class BeanConfig {
>  ...
>  // Current default class loader, default is BeanConfig's class loader
>  private static ClassLoader defaultClassLoader =
> BeanConfig.class.getClassLoader();
>  // Current instance class loader
>  private ClassLoader classLoader;
>  ...
>  // Sets the default class loader for new BeanConfig instances
>  public static void setDefaultClassLoader(ClassLoader loader);
>  // Returns the default class loader for new BeanConfig instances
>  public static ClassLoader getClassLoader();
>  // Sets the class loader of this BeanConfig instance
>  public void setClassLoader(ClassLoader loader);
>  // Returns the class loader of this BeanConfig instance
>  public ClassLoader getClassLoader();
> }
> The BeanConfig.newInstance method would then use the following to use the class:
> public Object newInstance() throws ConfigurationException {
>  Class clazz = Class.forName(getClassName(), true, getClassLoader());
>  ...
> }
> This has also been discussed on the dev list: http://mail-archives.apache.org/mod_mbox/jackrabbit-dev/200607.mbox/%3cae03024e0607272341l52aff9b2h3957131411790bc9@mail.gmail.com%3e

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Mime
View raw message