[jboss-user] [Beginners Corner] - Re: Jboss class laoding and newInstance
ShareMe
do-not-reply at jboss.com
Thu Mar 13 11:49:55 EDT 2008
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
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4136344#4136344
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4136344
More information about the jboss-user
mailing list