001: /*
002: *
003: * Jsmtpd, Java SMTP daemon
004: * Copyright (C) 2005 Jean-Francois POUX, jf.poux@laposte.net
005: *
006: * This program is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU General Public License
008: * as published by the Free Software Foundation; either version 2
009: * of the License, or (at your option) any later version.
010: *
011: * This program is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014: * GNU General Public License for more details.
015: *
016: * You should have received a copy of the GNU General Public License
017: * along with this program; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
019: *
020: */
021: package org.jsmtpd.core.common;
022:
023: import java.util.Iterator;
024: import java.util.LinkedList;
025: import java.util.List;
026:
027: import org.jsmtpd.config.ModuleNotFoundException;
028: import org.jsmtpd.core.common.acl.IACL;
029: import org.jsmtpd.core.common.delivery.IDeliveryService;
030: import org.jsmtpd.core.common.dnsService.IDNSResolver;
031: import org.jsmtpd.core.common.filter.FilterTreeNode;
032: import org.jsmtpd.core.common.inputIPFilter.IFilterIP;
033: import org.jsmtpd.core.common.smtpExtension.ISmtpExtension;
034:
035: /**
036: * Stores the instances of all plugins. By conveniance this is a singleton.
037: * Not synchronized in any way as long as plugins are dispatched within one unique thread.
038: * @author Jean-Francois POUX
039: */
040: public class PluginStore {
041:
042: private static PluginStore instance = null;
043: private IACL acl = null;
044: private IDNSResolver resolver = null;
045: private IDeliveryService localDeliveryService = null;
046: private IDeliveryService remoteDeliveryService = null;
047: private LinkedList<LoadedPlugin> plugins = new LinkedList<LoadedPlugin>();
048: private FilterTreeNode rootFilter = null;
049: private List<IFilterIP> inputIPFilterChain = new LinkedList<IFilterIP>();
050: private List<ISmtpExtension> smtpExtensions = new LinkedList<ISmtpExtension>();
051:
052: private PluginStore() {
053:
054: }
055:
056: public void addPlugin(IGenericPlugin module, String logicalName) {
057: LoadedPlugin pl = new LoadedPlugin(module, logicalName);
058: plugins.add(pl);
059: }
060:
061: public List<IGenericPlugin> getFilterList() {
062: LinkedList<IGenericPlugin> fl = new LinkedList<IGenericPlugin>();
063: for (Iterator iter = plugins.iterator(); iter.hasNext();) {
064: LoadedPlugin element = (LoadedPlugin) iter.next();
065: fl.add(element.getModule());
066: }
067: return fl;
068: }
069:
070: public IGenericPlugin getPluginByLogicalName(String logicalName)
071: throws ModuleNotFoundException {
072: for (Iterator iter = plugins.iterator(); iter.hasNext();) {
073: LoadedPlugin element = (LoadedPlugin) iter.next();
074: if (element.getLogicalName().equals(logicalName))
075: return element.getModule();
076: }
077:
078: throw new ModuleNotFoundException(logicalName);
079: }
080:
081: public static PluginStore getInstance() {
082: if (instance == null)
083: instance = new PluginStore();
084:
085: return instance;
086: }
087:
088: public IACL getAcl() {
089: return acl;
090: }
091:
092: public void setAcl(IACL acl) {
093: this .acl = acl;
094: }
095:
096: public IDNSResolver getResolver() {
097: return resolver;
098: }
099:
100: public void setResolver(IDNSResolver resolver) {
101: this .resolver = resolver;
102: }
103:
104: public IDeliveryService getLocalDeliveryService() {
105: return localDeliveryService;
106: }
107:
108: public void setLocalDeliveryService(
109: IDeliveryService localDeliveryService) {
110: this .localDeliveryService = localDeliveryService;
111: }
112:
113: public IDeliveryService getRemoteDeliveryService() {
114: return remoteDeliveryService;
115: }
116:
117: public void setRemoteDeliveryService(
118: IDeliveryService remoteDeliveryService) {
119: this .remoteDeliveryService = remoteDeliveryService;
120: }
121:
122: public FilterTreeNode getRootFilter() {
123: return rootFilter;
124: }
125:
126: public void setRootFilter(FilterTreeNode rootFilter) {
127: this .rootFilter = rootFilter;
128: }
129:
130: public List<IFilterIP> getInputIPFilters() {
131: return inputIPFilterChain;
132: }
133:
134: public void addInputIPFilters(IFilterIP in) {
135: inputIPFilterChain.add(in);
136: }
137:
138: public void addSmtpExtensions(ISmtpExtension ext) {
139: smtpExtensions.add(ext);
140: return;
141: }
142:
143: public List<ISmtpExtension> getSmtpExtensions() {
144: return smtpExtensions;
145: }
146: }
|