1 17 18 package org.apache.james.transport; 19 import javax.mail.MessagingException ; 20 21 import org.apache.avalon.framework.configuration.Configurable; 22 import org.apache.avalon.framework.configuration.Configuration; 23 import org.apache.avalon.framework.configuration.ConfigurationException; 24 import org.apache.james.core.MailetConfigImpl; 25 import org.apache.mailet.Mailet; 26 import org.apache.mailet.MailetContext; 27 import org.apache.mailet.MailetException; 28 32 public class MailetLoader extends Loader implements Configurable { 33 36 public void configure(Configuration conf) throws ConfigurationException { 37 getPackages(conf,MAILET_PACKAGE); 38 configureMailetClassLoader(); 39 } 40 49 public Mailet getMailet(String mailetName, MailetContext context, Configuration configuration) 50 throws MessagingException { 51 try { 52 for (int i = 0; i < packages.size(); i++) { 53 String className = (String ) packages.elementAt(i) + mailetName; 54 try { 55 MailetConfigImpl configImpl = new MailetConfigImpl(); 56 configImpl.setMailetName(mailetName); 57 configImpl.setConfiguration(configuration); 58 configImpl.setMailetContext(context); 59 Mailet mailet = (Mailet) mailetClassLoader.loadClass(className).newInstance(); 60 mailet.init(configImpl); 61 return mailet; 62 } catch (ClassNotFoundException cnfe) { 63 } 65 } 66 StringBuffer exceptionBuffer = 67 new StringBuffer (128) 68 .append("Requested mailet not found: ") 69 .append(mailetName) 70 .append(". looked in ") 71 .append(packages.toString()); 72 throw new ClassNotFoundException (exceptionBuffer.toString()); 73 } catch (MessagingException me) { 74 throw me; 75 } catch (Exception e) { 76 StringBuffer exceptionBuffer = 77 new StringBuffer (128).append("Could not load mailet (").append(mailetName).append( 78 ")"); 79 throw new MailetException(exceptionBuffer.toString(), e); 80 } 81 } 82 } 83 | Popular Tags |