KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jsmtpd > core > common > PluginStore


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;
22
23 import java.util.Iterator JavaDoc;
24 import java.util.LinkedList JavaDoc;
25 import java.util.List JavaDoc;
26
27 import org.jsmtpd.config.ModuleNotFoundException;
28 import org.jsmtpd.core.common.acl.IACL;
29 import org.jsmtpd.core.common.delivery.IDeliveryService;
30 import org.jsmtpd.core.common.dnsService.IDNSResolver;
31 import org.jsmtpd.core.common.filter.FilterTreeNode;
32 import org.jsmtpd.core.common.inputIPFilter.IFilterIP;
33 import org.jsmtpd.core.common.smtpExtension.ISmtpExtension;
34
35 /**
36  * Stores the instances of all plugins. By conveniance this is a singleton.
37  * Not synchronized in any way as long as plugins are dispatched within one unique thread.
38  * @author Jean-Francois POUX
39  */

40 public class PluginStore {
41
42     private static PluginStore instance = null;
43     private IACL acl = null;
44     private IDNSResolver resolver = null;
45     private IDeliveryService localDeliveryService = null;
46     private IDeliveryService remoteDeliveryService = null;
47     private LinkedList JavaDoc<LoadedPlugin> plugins = new LinkedList JavaDoc<LoadedPlugin>();
48     private FilterTreeNode rootFilter = null;
49     private List JavaDoc<IFilterIP> inputIPFilterChain = new LinkedList JavaDoc<IFilterIP>();
50     private List JavaDoc<ISmtpExtension> smtpExtensions = new LinkedList JavaDoc<ISmtpExtension>();
51
52     private PluginStore() {
53
54     }
55
56     public void addPlugin(IGenericPlugin module, String JavaDoc logicalName) {
57         LoadedPlugin pl = new LoadedPlugin(module, logicalName);
58         plugins.add(pl);
59     }
60
61     public List JavaDoc<IGenericPlugin> getFilterList() {
62         LinkedList JavaDoc<IGenericPlugin> fl = new LinkedList JavaDoc<IGenericPlugin>();
63         for (Iterator JavaDoc iter = plugins.iterator(); iter.hasNext();) {
64             LoadedPlugin element = (LoadedPlugin) iter.next();
65             fl.add(element.getModule());
66         }
67         return fl;
68     }
69
70     public IGenericPlugin getPluginByLogicalName(String JavaDoc logicalName) throws ModuleNotFoundException {
71         for (Iterator JavaDoc iter = plugins.iterator(); iter.hasNext();) {
72             LoadedPlugin element = (LoadedPlugin) iter.next();
73             if (element.getLogicalName().equals(logicalName))
74                 return element.getModule();
75         }
76
77         throw new ModuleNotFoundException(logicalName);
78     }
79
80     public static PluginStore getInstance() {
81         if (instance == null)
82             instance = new PluginStore();
83
84         return instance;
85     }
86
87     public IACL getAcl() {
88         return acl;
89     }
90
91     public void setAcl(IACL acl) {
92         this.acl = acl;
93     }
94
95     public IDNSResolver getResolver() {
96         return resolver;
97     }
98
99     public void setResolver(IDNSResolver resolver) {
100         this.resolver = resolver;
101     }
102
103     public IDeliveryService getLocalDeliveryService() {
104         return localDeliveryService;
105     }
106
107     public void setLocalDeliveryService(IDeliveryService localDeliveryService) {
108         this.localDeliveryService = localDeliveryService;
109     }
110
111     public IDeliveryService getRemoteDeliveryService() {
112         return remoteDeliveryService;
113     }
114
115     public void setRemoteDeliveryService(IDeliveryService remoteDeliveryService) {
116         this.remoteDeliveryService = remoteDeliveryService;
117     }
118
119     public FilterTreeNode getRootFilter() {
120         return rootFilter;
121     }
122
123     public void setRootFilter(FilterTreeNode rootFilter) {
124         this.rootFilter = rootFilter;
125     }
126
127     public List JavaDoc<IFilterIP> getInputIPFilters() {
128         return inputIPFilterChain;
129     }
130
131     public void addInputIPFilters(IFilterIP in) {
132         inputIPFilterChain.add(in);
133     }
134
135     public void addSmtpExtensions(ISmtpExtension ext) {
136         smtpExtensions.add(ext);
137         return;
138     }
139
140     public List JavaDoc<ISmtpExtension> getSmtpExtensions() {
141         return smtpExtensions;
142     }
143 }
Popular Tags