ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/cms/source/server/uk/org/iscream/cms/server/filter/PluginFilterManager.java
(Generate patch)

Comparing projects/cms/source/server/uk/org/iscream/cms/server/filter/PluginFilterManager.java (file contents):
Revision 1.1 by tdb, Wed Dec 6 22:58:30 2000 UTC vs.
Revision 1.3 by ajm, Wed Dec 13 13:36:46 2000 UTC

# Line 1 | Line 1
1 < //---PACKAGE DECLARATION---
2 < package uk.ac.ukc.iscream.filter;
3 <
4 < //---IMPORTS---
5 < import java.io.*;
6 < import java.util.*;
7 <
8 < import uk.ac.ukc.iscream.util.*;
9 < import uk.ac.ukc.iscream.core.*;
10 <
11 < /**
12 < * the plugin filter manager
13 < * This is a singleton class.
14 < *
15 < * @author  $Author$
16 < * @version $Id$
17 < */
18 < class PluginFilterManager {
19 <
20 < //---FINAL ATTRIBUTES---
21 <
22 <    /**
23 <     * The current CVS revision of this class
24 <     */
25 <    public final String REVISION = "$Revision$";
26 <    
27 < //---STATIC METHODS---
28 <
29 <    // Return a reference to the single class.
30 <    // Construct it if it does not already exist, otherwise just return the reference.
31 <    public static PluginFilterManager getInstance() throws NotInitialisedException {
32 <        if (_instance == null){
33 <            return new PluginFilterManager();
34 <        }
35 <        return _instance;
36 <    }
37 <
38 < //---CONSTRUCTORS---
39 <
40 <    // Private Constructor - this part creates the filter pipeline
41 <    // This is a singleton class, btw.
42 <    private PluginFilterManager(){
43 <        
44 <        _logger.write(toString(), Logger.SYSINIT, "Initialising");
45 <        _logger.write(toString(), Logger.SYSMSG, "Creating filter pipeline for plugin filters ...");
46 <        
47 <        // Get our config
48 <        ReferenceManager refman = ReferenceManager.getInstance();
49 <        Configuration config = refman.getCM().getConfiguration(refman.getName());
50 <        String pluginsPackage = config.getProperty("Filter.PluginsPackage");
51 <        String pluginsList = config.getProperty("Filter.Plugins");
52 <        
53 <        StringTokenizer st = new StringTokenizer(pluginsList, ";");
54 <        
55 <        while(st.hasMoreTokens()) {
56 <            String className = pluginsPackage + "." + st.nextToken() + _suffix;
57 <            _logger.write(toString(), Logger.DEBUG, "Attempting to create plugin: "+className);
58 <            
59 <            // Create an instance of the specified PluginFilter to include
60 <            // within the filterPipe.  Add it to the filterPipeline
61 <            try {
62 <                PluginFilter pf = (PluginFilter)ClassLoader.getSystemClassLoader().loadClass(className).newInstance();
63 <                _filterPipeline.add(pf);
64 <                _logger.write(toString(), Logger.DEBUG, "Added filter: "+className+" ("+pf.getDescription()+")");
65 <            }
66 <            catch (InstantiationException e){
67 <                _logger.write(toString(), Logger.ERROR, "Failed to instantiate "+className+" to the plugin filter pipeline.");
68 <                _logger.write(toString(), Logger.ERROR, e.getMessage());
69 <            }
70 <            catch (Exception e){
71 <                _logger.write(toString(), Logger.ERROR, "Failed to add "+className+" to the plugin filter pipeline.");
72 <                _logger.write(toString(), Logger.ERROR, e.toString());
73 <            }
74 <        }
75 <        _logger.write(toString(), Logger.SYSMSG, "The filter pipeline has been set up with "+_filterPipeline.size()+" plugin filters.");
76 <        
77 <    }
78 <
79 < //---PUBLIC METHODS---
80 <
81 <    // apply all of the filters in the pipeline to the packet.
82 <    // return true if they all accept the packet.
83 <    // return false if any single filter rejects the packet.
84 <    // return true if there are no filters inthe pipeline.
85 <    public boolean runFilters(XMLPacket packet){
86 <        
87 <        // for each filter in the pipeline...
88 <        ListIterator pluginFilters = _filterPipeline.listIterator(0);
89 <        while (pluginFilters.hasNext()){
90 <            PluginFilter filter = (PluginFilter)pluginFilters.next();
91 <            if (!filter.runFilter(packet)){
92 <                return false;
93 <            }
94 <        }
95 <        
96 <        return true;
97 <    }
98 <
99 <    /**
100 <     * Overrides the {@link java.lang.Object#toString() Object.toString()}
101 <     * method to provide clean logging (every class should have this).
102 <     *
103 <     * @return the name of this class and its CVS revision
104 <     */
105 <    public String toString() {
106 <        return this.getClass().getName() + "(" + REVISION.substring(11, REVISION.length() - 2) + ")";
107 <    }
108 <
109 < //---PRIVATE METHODS---
110 <
111 < //---ACCESSOR/MUTATOR METHODS---
112 <
113 < //---ATTRIBUTES---
114 <  
115 <    // file name suffix for plugin filter classes:
116 <    private final String _suffix = "__Plugin";
117 <    
118 <    // LinkedList for holding the PluginFilter objects (the pipeline).
119 <    private LinkedList _filterPipeline = new LinkedList();
120 <    
121 <    // A reference to the single instance of this class
122 <    private static PluginFilterManager _instance;
123 <
124 <    /**
125 <     * Reference to a Logger
126 <     */
127 <    private Logger _logger = ReferenceManager.getInstance().getLogger();
128 <
129 < //---STATIC ATTRIBUTES---
130 <
131 < }
1 > //---PACKAGE DECLARATION---
2 > package uk.ac.ukc.iscream.filter;
3 >
4 > //---IMPORTS---
5 > import java.io.*;
6 > import java.util.*;
7 >
8 > import uk.ac.ukc.iscream.util.*;
9 > import uk.ac.ukc.iscream.core.*;
10 >
11 > /**
12 > * the plugin filter manager
13 > * This is a singleton class.
14 > *
15 > * @author  $Author$
16 > * @version $Id$
17 > */
18 > class PluginFilterManager {
19 >
20 > //---FINAL ATTRIBUTES---
21 >
22 >    /**
23 >     * The current CVS revision of this class
24 >     */
25 >    public final String REVISION = "$Revision$";
26 >    
27 > //---STATIC METHODS---
28 >
29 >    /**
30 >     * Return a reference to the single class.
31 >     * Construct it if it does not already exist, otherwise just return the reference.
32 >     */
33 >    public static PluginFilterManager getInstance() {
34 >        if (_instance == null){
35 >            _instance = new PluginFilterManager();
36 >        }
37 >        return _instance;
38 >    }
39 >
40 > //---CONSTRUCTORS---
41 >
42 >    /**
43 >     * Private Constructor - this part creates the filter pipeline
44 >     * This is a singleton class, btw.
45 >     */
46 >    private PluginFilterManager(){
47 >        
48 >        _logger.write(toString(), Logger.SYSINIT, "Initialising");
49 >        _logger.write(toString(), Logger.SYSMSG, "Creating filter pipeline for plugin filters ...");
50 >        
51 >        Configuration config = _refman.getCM().getConfiguration(FilterMain.NAME);
52 >        String pluginsPackage = config.getProperty("Filter.PluginsPackage");
53 >        String pluginsList = config.getProperty("Filter.Plugins");
54 >        
55 >        StringTokenizer st = new StringTokenizer(pluginsList, ";");
56 >        
57 >        while(st.hasMoreTokens()) {
58 >            String className = pluginsPackage + "." + st.nextToken() + _suffix;
59 >            _logger.write(toString(), Logger.DEBUG, "Attempting to create plugin: "+className);
60 >            
61 >            // Create an instance of the specified PluginFilter to include
62 >            // within the filterPipe.  Add it to the filterPipeline
63 >            try {
64 >                PluginFilter pf = (PluginFilter)ClassLoader.getSystemClassLoader().loadClass(className).newInstance();
65 >                _filterPipeline.add(pf);
66 >                _logger.write(toString(), Logger.DEBUG, "Added filter: "+className+" ("+pf.getDescription()+")");
67 >            }
68 >            catch (InstantiationException e){
69 >                _logger.write(toString(), Logger.ERROR, "Failed to instantiate "+className+" to the plugin filter pipeline.");
70 >                _logger.write(toString(), Logger.ERROR, e.getMessage());
71 >            }
72 >            catch (Exception e){
73 >                _logger.write(toString(), Logger.ERROR, "Failed to add "+className+" to the plugin filter pipeline.");
74 >                _logger.write(toString(), Logger.ERROR, e.toString());
75 >            }
76 >        }
77 >        _logger.write(toString(), Logger.SYSMSG, "The filter pipeline has been set up with "+_filterPipeline.size()+" plugin filters.");
78 >        
79 >    }
80 >
81 > //---PUBLIC METHODS---
82 >
83 >    /**
84 >     * apply all of the filters in the pipeline to the packet.
85 >     * return true if they all accept the packet.
86 >     * return false if any single filter rejects the packet.
87 >     * return true if there are no filters inthe pipeline.
88 >     */
89 >    public boolean runFilters(XMLPacket packet){
90 >        
91 >        // for each filter in the pipeline...
92 >        ListIterator pluginFilters = _filterPipeline.listIterator(0);
93 >        while (pluginFilters.hasNext()){
94 >            PluginFilter filter = (PluginFilter)pluginFilters.next();
95 >            if (!filter.runFilter(packet)){
96 >                return false;
97 >            }
98 >        }
99 >        
100 >        return true;
101 >    }
102 >
103 >    /**
104 >     * Overrides the {@link java.lang.Object#toString() Object.toString()}
105 >     * method to provide clean logging (every class should have this).
106 >     *
107 >     * This uses the uk.ac.ukc.iscream.util.NameFormat class
108 >     * to format the toString()
109 >     *
110 >     * @return the name of this class and its CVS revision
111 >     */
112 >    public String toString() {
113 >        return FormatName.getName(
114 >            _name,
115 >            getClass().getName(),
116 >            REVISION);
117 >    }
118 >
119 > //---PRIVATE METHODS---
120 >
121 > //---ACCESSOR/MUTATOR METHODS---
122 >
123 > //---ATTRIBUTES---
124 >  
125 >    /**
126 >     * file name suffix for plugin filter classes:
127 >     */
128 >    private final String _suffix = "__Plugin";
129 >    
130 >    /**
131 >     * LinkedList for holding the PluginFilter objects (the pipeline).
132 >     */
133 >    private LinkedList _filterPipeline = new LinkedList();
134 >    
135 >    /**
136 >     * A reference to the single instance of this class
137 >     */
138 >    private static PluginFilterManager _instance;
139 >
140 >    /**
141 >     * This is the friendly identifier of the
142 >     * component this class is running in.
143 >     * eg, a Filter may be called "filter1",
144 >     * If this class does not have an owning
145 >     * component,  a name from the configuration
146 >     * can be placed here.  This name could also
147 >     * be changed to null for utility classes.
148 >     */
149 >    private String _name = FilterMain.NAME;
150 >
151 >    /**
152 >     * This holds a reference to the
153 >     * system logger that is being used.
154 >     */
155 >    private Logger _logger = ReferenceManager.getInstance().getLogger();
156 >    
157 >    /**
158 >     * A reference to the reference manager in use
159 >     */
160 >    private ReferenceManager _refman = ReferenceManager.getInstance();
161 >
162 > //---STATIC ATTRIBUTES---
163 >
164 > }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines