I would recommend to use a different approach:

Define an interface for the API.

Implement the different protocols in different classes with 
unique names. Load the classes dynamically and store instances 
of the classes in variables. Use the interface to access the api.

public class DomainFactory {
  Hashtable cTldClassNames = new Hashtable();

  static {
    cTldClassNames.put("BIZ", "package.BizProtocol");
    cTldClassNames.put("INFO", "package.InfoProtocol");
  }

  static IProtocol getInstance(String aTld) {
        return Class.forName(getTldClassName(aTld)).newInstance();
  }

  static String getTldClassName(String aTld) {
      return (String) cTldClassNames.get(aTld.toUpperCase());
  }
}


public class BizProtocol implemets IProtocol {
}


IProtocol mProtocol = DomainFactory.getInstance("Biz"));
mProtocol.methosA();

I think that this is more flexible and less error prone
as the complexity of a classloader approach.

> -----Original Message-----
> From: Ola Berg [mailto:[EMAIL PROTECTED]]
> Sent: Thursday, December 12, 2002 9:52 AM
> To: Tomcat Users List
> Subject: [classloading] How to use URLClassLoader within a servlet
> 
> 
> Depending on the top level domain, I need to use different 
> versions (jars) of the same API, since the protocol differs. 
> So I need to dynamically load my classes at runtime. Just 
> putting the jars in lib won't work since there are different 
> implementations of the same classes in them. I have to decide 
> in runtime.
> 

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to