KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > suberic > pooka > MessageFilter


1 package net.suberic.pooka;
2 import javax.mail.*;
3 import javax.mail.search.SearchTerm JavaDoc;
4 import net.suberic.pooka.filter.FilterAction;
5 import java.util.List JavaDoc;
6
7 /**
8  * This represents a MessageFilter. It contains a SearchTerm and an Action
9  * which is done on any messages which match the SearchTerm.
10  */

11 public class MessageFilter {
12   private SearchTerm JavaDoc searchTerm;
13   private FilterAction action;
14   
15   private String JavaDoc mProperty;
16
17   /**
18    * Create a MessageFilter from a SearchTerm and a FilterAction.
19    */

20   public MessageFilter(SearchTerm JavaDoc newSearchTerm, FilterAction newAction) {
21     searchTerm = newSearchTerm;
22     action = newAction;
23   }
24   
25   /**
26    * Create a MessageFilter from a String which represents a Pooka
27    * property.
28    *
29    */

30   public MessageFilter(String JavaDoc sourceProperty) {
31     mProperty = sourceProperty;
32
33     try {
34       searchTerm = Pooka.getSearchManager().generateSearchTermFromProperty(sourceProperty + ".searchTerm");
35       
36       action = generateFilterAction(sourceProperty + ".action");
37     } catch (java.text.ParseException JavaDoc pe) {
38       // FIXME: we should actually handle this.
39

40       pe.printStackTrace();
41     } catch (InstantiationException JavaDoc ie) {
42       ie.printStackTrace();
43     } catch (IllegalAccessException JavaDoc iae) {
44       iae.printStackTrace();
45     } catch (ClassNotFoundException JavaDoc cnfe) {
46       cnfe.printStackTrace();
47     }
48   }
49   
50   /**
51    * Generates a FilterAction from the given property.
52    */

53   public static FilterAction generateFilterAction(String JavaDoc actionProperty) throws ClassNotFoundException JavaDoc, InstantiationException JavaDoc , IllegalAccessException JavaDoc {
54     String JavaDoc className = Pooka.getProperty(actionProperty + ".class", "");
55     Class JavaDoc filterClass = Class.forName(className);
56     FilterAction newAction = (FilterAction)filterClass.newInstance();
57     newAction.initializeFilter(actionProperty);
58     return newAction;
59   }
60   
61   // accessor methods.
62

63   public SearchTerm JavaDoc getSearchTerm() {
64     return searchTerm;
65   }
66   
67   public void setSearchTerm(SearchTerm JavaDoc newTerm) {
68     searchTerm = newTerm;
69   }
70   
71   public FilterAction getAction() {
72     return action;
73   }
74   
75   public void setAction(FilterAction newAction) {
76     action=newAction;
77   }
78
79   /**
80    * Returns the source property used to create this.
81    */

82   public String JavaDoc getProperty() {
83     return mProperty;
84   }
85 }
86
Popular Tags