You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@camel.apache.org by Christian Müller <ch...@gmail.com> on 2011/01/21 12:46:01 UTC
ClassResolver.resolveClass() vs. ObjectHelper.loadClass()
Hello!
Maybe you could help me with two questions:
My understanding is that we should prefer to use
"ClassResolver.resolveClass()" instead of "ObjectHelper.loadClass()" to make
sure Camel operate well in different environments. Maybe the ClassResolver
delegate the call to ObjectHelper. Is this correct? Any known exceptions?
In our JmsComponent, I found the following code snippet (keep an eye on the
line with the '<--'):
{code:title=org.apache.camel.component.jms.JmsComponent}
protected static QueueBrowseStrategy
tryCreateDefaultQueueBrowseStrategy(CamelContext context) {
// lets try instantiate the default implementation
// use the class loading this class from camel-jms to work in OSGi
environments as the camel-jms
// should import the spring-jms jars.
if (JmsHelper.isSpring20x()) {
// not possible with spring 2.0.x
return null;
} else {
// lets try instantiate the default implementation
Class<?> type =
ObjectHelper.loadClass(DEFAULT_QUEUE_BROWSE_STRATEGY,
JmsComponent.class.getClassLoader()); // <--
if (type != null) {
return ObjectHelper.newInstance(type,
QueueBrowseStrategy.class);
} else {
return null;
}
}
}
{code}
Should this line be changed to:
{code:title=org.apache.camel.component.jms.JmsComponent}
protected static QueueBrowseStrategy
tryCreateDefaultQueueBrowseStrategy(CamelContext context) {
// lets try instantiate the default implementation
// use the class loading this class from camel-jms to work in OSGi
environments as the camel-jms
// should import the spring-jms jars.
if (JmsHelper.isSpring20x()) {
// not possible with spring 2.0.x
return null;
} else {
// lets try instantiate the default implementation
Class<?> type =
context.getClassResolver().resolveClass(DEFAULT_QUEUE_BROWSE_STRATEGY,
JmsComponent.class.getClassLoader()); // <--
if (type != null) {
return ObjectHelper.newInstance(type,
QueueBrowseStrategy.class);
} else {
return null;
}
}
}
{code}
Thank you in advance for the clarification,
Christian
Re: ClassResolver.resolveClass() vs. ObjectHelper.loadClass()
Posted by Christian Mueller <ch...@gmail.com>.
Raised JIRA https://issues.apache.org/jira/browse/CAMEL-3573
--
View this message in context: http://camel.465427.n5.nabble.com/ClassResolver-resolveClass-vs-ObjectHelper-loadClass-tp3351219p3351279.html
Sent from the Camel Development mailing list archive at Nabble.com.
Re: ClassResolver.resolveClass() vs. ObjectHelper.loadClass()
Posted by Christian Müller <ch...@gmail.com>.
Ok, I will raise a JIRA for it and go through the entire code. I will commit
the fix for 2.7...
Christian
Re: ClassResolver.resolveClass() vs. ObjectHelper.loadClass()
Posted by Claus Ibsen <cl...@gmail.com>.
Hi
Yeah it should.
We will be able to get rid of the code when we discard Spring 2.0.x support.
On Fri, Jan 21, 2011 at 12:46 PM, Christian Müller
<ch...@gmail.com> wrote:
> Hello!
>
> Maybe you could help me with two questions:
> My understanding is that we should prefer to use
> "ClassResolver.resolveClass()" instead of "ObjectHelper.loadClass()" to make
> sure Camel operate well in different environments. Maybe the ClassResolver
> delegate the call to ObjectHelper. Is this correct? Any known exceptions?
>
> In our JmsComponent, I found the following code snippet (keep an eye on the
> line with the '<--'):
>
> {code:title=org.apache.camel.component.jms.JmsComponent}
> protected static QueueBrowseStrategy
> tryCreateDefaultQueueBrowseStrategy(CamelContext context) {
> // lets try instantiate the default implementation
> // use the class loading this class from camel-jms to work in OSGi
> environments as the camel-jms
> // should import the spring-jms jars.
> if (JmsHelper.isSpring20x()) {
> // not possible with spring 2.0.x
> return null;
> } else {
> // lets try instantiate the default implementation
> Class<?> type =
> ObjectHelper.loadClass(DEFAULT_QUEUE_BROWSE_STRATEGY,
> JmsComponent.class.getClassLoader()); // <--
> if (type != null) {
> return ObjectHelper.newInstance(type,
> QueueBrowseStrategy.class);
> } else {
> return null;
> }
> }
> }
> {code}
>
> Should this line be changed to:
>
> {code:title=org.apache.camel.component.jms.JmsComponent}
> protected static QueueBrowseStrategy
> tryCreateDefaultQueueBrowseStrategy(CamelContext context) {
> // lets try instantiate the default implementation
> // use the class loading this class from camel-jms to work in OSGi
> environments as the camel-jms
> // should import the spring-jms jars.
> if (JmsHelper.isSpring20x()) {
> // not possible with spring 2.0.x
> return null;
> } else {
> // lets try instantiate the default implementation
> Class<?> type =
> context.getClassResolver().resolveClass(DEFAULT_QUEUE_BROWSE_STRATEGY,
> JmsComponent.class.getClassLoader()); // <--
> if (type != null) {
> return ObjectHelper.newInstance(type,
> QueueBrowseStrategy.class);
> } else {
> return null;
> }
> }
> }
> {code}
>
> Thank you in advance for the clarification,
> Christian
>
--
Claus Ibsen
-----------------
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/