1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package org.apache.james.transport;
23 import javax.mail.MessagingException;
24
25 import org.apache.avalon.framework.configuration.Configuration;
26 import org.apache.avalon.framework.configuration.ConfigurationException;
27 import org.apache.mailet.MailetException;
28 import org.apache.mailet.Matcher;
29
30
31
32
33 public class JamesMatcherLoader extends Loader implements MatcherLoader {
34
35
36
37 public void configure(Configuration conf) throws ConfigurationException {
38 getPackages(conf,MATCHER_PACKAGE);
39 }
40
41
42
43
44 public Matcher getMatcher(String matchName) throws MessagingException {
45 try {
46 String condition = (String) null;
47 int i = matchName.indexOf('=');
48 if (i != -1) {
49 condition = matchName.substring(i + 1);
50 matchName = matchName.substring(0, i);
51 }
52 for (i = 0; i < packages.size(); i++) {
53 String className = (String) packages.elementAt(i) + matchName;
54 try {
55 Matcher matcher = (Matcher) Thread.currentThread().getContextClassLoader().loadClass(className).newInstance();
56 MatcherConfigImpl configImpl = new MatcherConfigImpl();
57 configImpl.setMatcherName(matchName);
58 configImpl.setCondition(condition);
59 configImpl.setMailetContext(new MailetContextWrapper(mailetContext, getLogger().getChildLogger(matchName)));
60 matcher.init(configImpl);
61 return matcher;
62 } catch (ClassNotFoundException cnfe) {
63
64 }
65 }
66 StringBuffer exceptionBuffer =
67 new StringBuffer(128)
68 .append("Requested matcher not found: ")
69 .append(matchName)
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 matcher (").append(matchName).append(
78 ")");
79 throw new MailetException(exceptionBuffer.toString(), e);
80 }
81 }
82 }