KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jsmtpd > core > common > filter > FilterTreeNode


1 /*
2  *
3  * Jsmtpd, Java SMTP daemon
4  * Copyright (C) 2005 Jean-Francois POUX, jf.poux@laposte.net
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19  *
20  */

21 package org.jsmtpd.core.common.filter;
22
23 import org.apache.commons.logging.Log;
24 import org.apache.commons.logging.LogFactory;
25 import org.jsmtpd.core.mail.Email;
26
27 /**
28  * Jsmtpd<br>
29  * A node of the filter chain.<br>
30  * The whole tree is an image of the configuration file element filterchain<br>
31  * A true empty child causes the chain to be validated<br>
32  * A false empty child causes the chain to be rejected<br>
33  * @author Jean-Francois POUX
34  */

35 public class FilterTreeNode {
36
37     private FilterTreeNode parent = null;
38     private FilterTreeNode trueNode = null;
39     private FilterTreeNode falseNode = null;
40
41     private IFilter filter;
42     private Log log = LogFactory.getLog(FilterTreeNode.class);
43
44     public void doFilter(Email in) throws FilterTreeFailureException, FilterTreeSuccesException, Throwable JavaDoc {
45         if (filter.doFilter(in)) {
46             log.debug("Filter true with " + filter.getPluginName());
47             if (trueNode == null)//No filter apended, EOC succes
48
{
49                 log.debug("FILTER END OK by " + filter.getPluginName());
50                 throw new FilterTreeSuccesException();
51             }
52             trueNode.doFilter(in);
53         } else {
54             log.debug("Filter false with " + filter.getPluginName());
55             if (falseNode == null) {
56                 log.debug("FILTER END FAIL by " + filter.getPluginName());
57                 throw new FilterTreeFailureException();
58             }
59             falseNode.doFilter(in);
60         }
61     }
62
63     public FilterTreeNode getFalseNode() {
64         return falseNode;
65     }
66
67     public void setFalseNode(FilterTreeNode falseNode) {
68         this.falseNode = falseNode;
69     }
70
71     public FilterTreeNode getParent() {
72         return parent;
73     }
74
75     public void setParent(FilterTreeNode parent) {
76         this.parent = parent;
77     }
78
79     public FilterTreeNode getTrueNode() {
80         return trueNode;
81     }
82
83     public void setTrueNode(FilterTreeNode trueNode) {
84         this.trueNode = trueNode;
85     }
86
87     public IFilter getFilter() {
88         return filter;
89     }
90
91     public void setFilter(IFilter filter) {
92         this.filter = filter;
93     }
94 }
Popular Tags