You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@pivot.apache.org by "Sandro Martini (JIRA)" <ji...@apache.org> on 2010/12/19 02:17:01 UTC
[jira] Commented: (PIVOT-687) BXMLSerializer, would like to be able
to specify a classloader for loading custom components
[ https://issues.apache.org/jira/browse/PIVOT-687?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12972883#action_12972883 ]
Sandro Martini commented on PIVOT-687:
--------------------------------------
In an multi-layered application, a good thing would be to have a way for a caller to pass its (or maybe even a custom) Classloader instance to BXMLSerializer, so anytime a dynamic load of a class is needed, when that classloader is not null BXMLSerializer can use it instead of the default one (good for all standard cases).
Examples of Classloaders (for callers, to pass):
// ClassLoader classLoader = ClassLoader.getSystemClassLoader(); // clSystem
// ClassLoader classLoader = this.getClass().getClassLoader(); // clCurrent
// ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); // clContext
Currently BXMLSerializer by default uses this:
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
Note that probably this is a good feature even in other places inside Pivot, whenever a dynamic load of a class has to be done, but this could be a later evolution (if needed here).
For example, I had a dedicated class for this, with the following methods (extract):
public DynamicLoader(String className, String variantName, int namingStrategy, boolean exceptionOnNull)
that was much more complex than needed here because I had to handle different naming strategies for class names.
In my custom bean factory OptionalVariantBeanFactory i was loading classes using using DynamicLoader, and before loading the requested class I tried to load the optional variant version (specific for the given customer code) and if not found try to load the default class.
Probably all this is too business-specific for inclusion in Pivot, but a simplified version of DynamicLoader could be useful (maybe in the future).
protected transient boolean initClassToLoad = true;
protected transient ClassLoader classloader = null;
public void useClassloaderEnhanced(boolean initClass, ClassLoader cl)
this was using to enable the "enhanced" classloading, so later (inside the real load method) I could use
if (classloader != null)
clazz = Class.forName(fullClassName, initClassToLoad, classloader);
else
clazz = Class.forName(fullClassName);
just as a sample ...
> BXMLSerializer, would like to be able to specify a classloader for loading custom components
> --------------------------------------------------------------------------------------------
>
> Key: PIVOT-687
> URL: https://issues.apache.org/jira/browse/PIVOT-687
> Project: Pivot
> Issue Type: Improvement
> Components: core-beans
> Affects Versions: 2.0
> Environment: all
> Reporter: GBivins
> Fix For: 2.0.1
>
>
> I'm running into issues trying to load my pivot window into a swing application. Some background,
> since pivot 2.0 can load components into a swing application, I've been trying to integrate pivot into a netbeans platform application.
> Only been at it a couple of hours but I'm stuck on an class loader issue. Basically, because I have pivot wrapped in separate module it's classloader
> can't references classes in any modules that depend on it. See here:
> http://bits.netbeans.org/dev/javadoc/org-openide-modules/org/openide/modules/doc-files/classpath.html#loader-hier
> I looked briefly in the docs but I'm not sure if I missed a readObject() signature that will allow me to pass in the classloader to use when de-serializing.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.