camel-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christian Müller <christian.muel...@gmail.com>
Subject ClassResolver.resolveClass() vs. ObjectHelper.loadClass()
Date Fri, 21 Jan 2011 11:46:01 GMT
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

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message