[
https://issues.apache.org/jira/browse/PIVOT-742?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13050479#comment-13050479
]
Andrei Pozolotin commented on PIVOT-742:
----------------------------------------
Sandro:
1) the original solution PIVOT-687
had an error, namely, it ignored proper class loader in this part of
BXMLSerializer:
protected Serializer<?> newIncludeSerializer(Class<? extends Serializer<?>>
type)
throws InstantiationException, IllegalAccessException {
return type.newInstance();
}
this error results, in my case, that in osgi environment, I can not load nested
bxml at all;
(since the snippet above ignores the classloader set via BXMLSerializer(loader)
constructor)
2) instead of trying to retain compatibility PIVOT-687, I suggest to drop it
completely;
also, patch_2011-06-15_bxml-classloader.patch is more consistent with how
pivot-wtk
is using TCCL now all over the place, for example:
http://svn.apache.org/repos/asf/pivot/trunk/wtk/src/org/apache/pivot/wtk/ImageView.java
public final void setImage(String imageName) {
if (imageName == null) {
throw new IllegalArgumentException("imageName is null.");
}
ClassLoader classLoader =
Thread.currentThread().getContextClassLoader();
setImage(classLoader.getResource(imageName.substring(1)));
}
the use of TCCL in pivot-wtk and BXMLSerializer(loader) in pivot-core is
totally misleading & confusing :-)
3) so with patch_2011-06-15_bxml-classloader.patch there is only one way to
deal with class loaders, not two;
and the current code which is using PIVOT-687 must be re-written to use what
Richard above calls a "TCCL bracket", like this:
@Override
public final void run() {
final Thread thread = Thread.currentThread();
final ClassLoader pastLoader = thread.getContextClassLoader();
final ClassLoader thisLoader = getClass().getClassLoader();
try {
thread.setContextClassLoader(thisLoader);
/* INIT YOUR BXML HERE; BOTH PIVOT-CORE & PIVOT-WTK
WILL USE thisLoader NOW */
} catch (Throwable e) {
log.error("", e);
} finally {
thread.setContextClassLoader(pastLoader);
}
}
am I making sense? :-)
Andrei.
> pluggable classloader
> ---------------------
>
> Key: PIVOT-742
> URL: https://issues.apache.org/jira/browse/PIVOT-742
> Project: Pivot
> Issue Type: Improvement
> Reporter: Andrei Pozolotin
> Assignee: Sandro Martini
> Fix For: 2.0.1
>
> Attachments: CLPlugin.java, CLPluginTCCL.java, CLProvider.java,
> UseCase.java, patch_2011-06-15_bxml-classloader.patch
>
>
> pluggable classloader:
> 1) in current pivot trunk, TCCL,
> Thread.currentThread().getContextClassLoader().... is mentioned 105 times
> I suggest to centralize it and replace with pluggable classloader (which can
> use TCCL by default);
> 2) review all other uses of Class.getResource(), which are not using TCCL,
> and convert when possible;
> motivation:
> https://issues.apache.org/jira/browse/PIVOT-22
> https://issues.apache.org/jira/browse/FELIX-2951
> http://njbartlett.name/2010/08/30/osgi-readiness-loading-classes.html
> http://wiki.eclipse.org/index.php/Context_Class_Loader_Enhancements
> http://stackoverflow.com/questions/2198928/better-handling-of-thread-context-classloader-in-osgi
> http://mail-archives.apache.org/mod_mbox/pivot-user/201105.mbox/%[email protected]%3E
--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira