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.MatcherConfigImpl; 25 import org.apache.mailet.MailetContext; 26 import org.apache.mailet.MailetException; 27 import org.apache.mailet.Matcher; 28 32 public class MatchLoader extends Loader implements Configurable { 33 36 public void configure(Configuration conf) throws ConfigurationException { 37 getPackages(conf,MATCHER_PACKAGE); 38 configureMailetClassLoader(); 39 } 40 41 42 51 public Matcher getMatcher(String matchName, MailetContext context) throws MessagingException { 52 try { 53 String condition = (String ) null; 54 int i = matchName.indexOf('='); 55 if (i != -1) { 56 condition = matchName.substring(i + 1); 57 matchName = matchName.substring(0, i); 58 } 59 for (i = 0; i < packages.size(); i++) { 60 String className = (String ) packages.elementAt(i) + matchName; 61 try { 62 MatcherConfigImpl configImpl = new MatcherConfigImpl(); 63 configImpl.setMatcherName(matchName); 64 configImpl.setCondition(condition); 65 configImpl.setMailetContext(context); 66 Matcher matcher = (Matcher) mailetClassLoader.loadClass(className).newInstance(); 67 matcher.init(configImpl); 68 return matcher; 69 } catch (ClassNotFoundException cnfe) { 70 } 72 } 73 StringBuffer exceptionBuffer = 74 new StringBuffer (128) 75 .append("Requested matcher not found: ") 76 .append(matchName) 77 .append(". looked in ") 78 .append(packages.toString()); 79 throw new ClassNotFoundException (exceptionBuffer.toString()); 80 } catch (MessagingException me) { 81 throw me; 82 } catch (Exception e) { 83 StringBuffer exceptionBuffer = 84 new StringBuffer (128).append("Could not load matcher (").append(matchName).append( 85 ")"); 86 throw new MailetException(exceptionBuffer.toString(), e); 87 } 88 } 89 } 90 | Popular Tags |