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/FilterThread.java
Revision: 1.14
Committed: Wed Dec 13 13:36:46 2000 UTC (23 years, 5 months ago) by ajm
Branch: MAIN
Changes since 1.13: +49 -12 lines
Log Message:
componenterized the filter and tidied all child classes, no all conform to toString standard

File Contents

# User Rev Content
1 tdb 1.8 //---PACKAGE DECLARATION---
2     package uk.ac.ukc.iscream.filter;
3    
4     //---IMPORTS---
5 pjm2 1.1 import java.io.*;
6     import java.net.*;
7     import java.util.*;
8 pjm2 1.6 import uk.ac.ukc.iscream.core.*;
9 tdb 1.2 import uk.ac.ukc.iscream.filter.*;
10 ajm 1.11 import uk.ac.ukc.iscream.util.*;
11 pjm2 1.1
12 tdb 1.8 /**
13 ajm 1.14 * Handle an incoming packet as a separate thread.
14     * Passes the data through various plugins, then
15     * passes it on to the parent filter.
16 tdb 1.8 *
17 ajm 1.14 * @author $Author: tdb1 $
18     * @version $Id: FilterThread.java,v 1.13 2000/12/06 22:57:45 tdb1 Exp $
19 tdb 1.8 */
20 tdb 1.2 public class FilterThread extends Thread{
21 pjm2 1.1
22 tdb 1.8 //---FINAL ATTRIBUTES---
23    
24     /**
25     * The current CVS revision of this class
26     */
27 ajm 1.14 public final String REVISION = "$Revision: 1.13 $";
28 tdb 1.8
29     //---STATIC METHODS---
30    
31     //---CONSTRUCTORS---
32    
33 ajm 1.14 /**
34     * Class constructor. Obtains the byte[] from a DatagramPacket.
35     */
36 tdb 1.10 public FilterThread(DatagramPacket packet, Filter parent){
37     _parent = parent;
38     _rawPacket = packet.getData();
39 ajm 1.14 _logger.write(toString(), Logger.DEBUG, "created");
40 ajm 1.9
41 pjm2 1.1 }
42    
43 ajm 1.14 /**
44     * Class constructor for passing XML Strings.
45     */
46 tdb 1.10 public FilterThread(String xml, Filter parent){
47     _parent = parent;
48     _rawPacket = xml.getBytes();
49 ajm 1.14 _logger.write(toString(), Logger.DEBUG, "created");
50 pjm2 1.1 }
51 tdb 1.8
52     //---PUBLIC METHODS---
53    
54 ajm 1.14 /**
55     * Runs the thread
56     */
57 pjm2 1.1 public void run(){
58    
59     // Get a string without any null characters in it.
60 tdb 1.10 // -- maybe String.trim() would be better here ?
61     String xml = new String(_rawPacket);
62 pjm2 1.3 if (xml.indexOf(0) != -1) {
63 tdb 1.2 xml = xml.substring(0, xml.indexOf(0));
64     }
65     else {
66     xml = xml.substring(0, xml.length());
67     }
68 ajm 1.9
69 pjm2 1.3 // Use my XMLPacketMaker to make an XMLPacket object.
70 tdb 1.10 XMLPacketMaker xmlPacketMaker = new XMLPacketMaker(xml);
71 pjm2 1.1 XMLPacket packet = xmlPacketMaker.createXMLPacket();
72 tdb 1.13
73     if(packet != null && PluginFilterManager.getInstance().runFilters(packet)) {
74     // packet is not null
75     // packet was not dropped by a plugin
76     // ... best pass it on !
77     _parent.receiveXML(xml);
78     }
79     else {
80     // either we had a null, or a plugin dropped it
81 ajm 1.14 _logger.write(toString(), Logger.DEBUG, "An XML packet was sucessfully filtered from the system.");
82 pjm2 1.1 }
83 pjm2 1.6
84 pjm2 1.1 }
85 tdb 1.8
86     /**
87     * Overrides the {@link java.lang.Object#toString() Object.toString()}
88     * method to provide clean logging (every class should have this).
89     *
90 ajm 1.14 * This uses the uk.ac.ukc.iscream.util.NameFormat class
91     * to format the toString()
92     *
93 tdb 1.8 * @return the name of this class and its CVS revision
94     */
95     public String toString() {
96 ajm 1.14 return FormatName.getName(
97     _name,
98     getClass().getName(),
99     REVISION);
100 tdb 1.8 }
101    
102     //---PRIVATE METHODS---
103    
104     //---ACCESSOR/MUTATOR METHODS---
105    
106     //---ATTRIBUTES---
107    
108 ajm 1.14 /**
109     * Our parent filter
110     */
111 tdb 1.10 Filter _parent;
112 ajm 1.14
113     /**
114     * The raw packet data
115     */
116 tdb 1.10 byte[] _rawPacket;
117 ajm 1.14
118     /**
119     * This is the friendly identifier of the
120     * component this class is running in.
121     * eg, a Filter may be called "filter1",
122     * If this class does not have an owning
123     * component, a name from the configuration
124     * can be placed here. This name could also
125     * be changed to null for utility classes.
126     */
127     private String _name = FilterMain.NAME;
128    
129     /**
130     * This holds a reference to the
131     * system logger that is being used.
132     */
133     private Logger _logger = ReferenceManager.getInstance().getLogger();
134 tdb 1.8
135     //---STATIC ATTRIBUTES---
136    
137 pjm2 1.1 }