4 Replies Latest reply on Mar 13, 2008 12:01 PM by Fred Grott

    Jboss class laoding and newInstance

    Fred Grott Newbie

      I have a situation whereas I am using a 3rd party library that makes use of Class.forName

      Pretty easy to change that ot use a context loader..

      The issue is I also have a Class abc=null with the construction of:

      abc.newInstance()

      Any suggestions in how I should change this?

      Thanks

        • 1. Re: Jboss class laoding and newInstance
          Peter Johnson Master

          newInstance() is a static method on that class. How is that method coded (post the source)?

          • 2. Re: Jboss class laoding and newInstance
            Fred Grott Newbie

            Hers is the 3rd party lib source that I was changing, thjis is beofre I fixed the Class.forName:

            package message;

            import java.util.HashMap;

            import org.apache.commons.logging.Log;
            import org.apache.commons.logging.LogFactory;

            /**
            * Generates objects based on configuration settings in MessageConfig
            *
            * @author Michelle Osmond
            * @version 1.2
            */
            public class MessagingFactory
            {
            private static final Log log = LogFactory.getLog(MessagingFactory.class);

            public static HashMap classes = new HashMap();

            /**
            * Get an object to retrieve the user-session-id.
            */
            public static SessionIDRetriever getSessionIDRetriever() throws ClassNotFoundException, InstantiationException,
            IllegalAccessException
            {
            return (SessionIDRetriever) getNewInstance(MessageConfig.SESSION_ID_RETRIEVER);
            }

            /**
            * Get a message centre for the given browser session ID.
            */
            public static MessageCentre getMessageCentre(String sessionID) throws ClassNotFoundException,
            InstantiationException, IllegalAccessException
            {
            MessageStore store = (MessageStore) getNewInstance(MessageConfig.MESSAGE_STORE);
            store.initialise(sessionID);
            MessageCentre mc = new MessageCentreImpl();
            mc.setStore(store);
            return mc;
            }

            protected static Object getNewInstance(String name) throws ClassNotFoundException, InstantiationException,
            IllegalAccessException
            {
            Class retrieverClass = null;

            if (MessagingFactory.classes.containsKey(name))
            {
            retrieverClass = (Class) MessagingFactory.classes.get(name);
            }
            else
            {
            // get class name from config
            retrieverClass = Class.forName(MessageConfig.getConfigProperty(name));
            MessagingFactory.classes.put(name, retrieverClass);
            }

            // instantiate class
            if (log.isDebugEnabled())
            {
            log.debug("MessagingFactory returning instance for " + name + " of class " + retrieverClass.getName());
            }
            return retrieverClass.newInstance();
            }

            }


            As you can see I cannot do a normal cast due to how its cast in other places

            • 3. Re: Jboss class laoding and newInstance
              Peter Johnson Master

              I do not understand what your question is.

              • 4. Re: Jboss class laoding and newInstance
                Fred Grott Newbie

                I have to change CLass.forName due needing it in Jboss context class loader

                The other instance where I get no class loaders found is the newInstance