You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@jackrabbit.apache.org by "Felix Meschberger (JIRA)" <ji...@apache.org> on 2006/09/04 12:40:24 UTC

[jira] Created: (JCR-561) Add support to provide custom classloader for class instantiation from configuration

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

        

[jira] Resolved: (JCR-561) Add support to provide custom classloader for class instantiation from configuration

Posted by "Felix Meschberger (JIRA)" <ji...@apache.org>.
     [ http://issues.apache.org/jira/browse/JCR-561?page=all ]

Felix Meschberger resolved JCR-561.
-----------------------------------

    Resolution: Fixed

As committed in Rev. 440026.

> 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

        

[jira] Closed: (JCR-561) Add support to provide custom classloader for class instantiation from configuration

Posted by "Felix Meschberger (JIRA)" <ji...@apache.org>.
     [ http://issues.apache.org/jira/browse/JCR-561?page=all ]

Felix Meschberger closed JCR-561.
---------------------------------


I think this can be closed now.

> 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: 1.0, 1.0.1, 0.9
>            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

        

[jira] Commented: (JCR-561) Add support to provide custom classloader for class instantiation from configuration

Posted by "Felix Meschberger (JIRA)" <ji...@apache.org>.
    [ 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