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.8
Committed: Wed Nov 29 19:26:00 2000 UTC (23 years, 5 months ago) by tdb
Branch: MAIN
Changes since 1.7: +45 -3 lines
Log Message:
Made changes to fit into the new package structure. Also made all classes, namely
the UDPReader and FilterThread, conform to the Template class specification.

File Contents

# Content
1 //---PACKAGE DECLARATION---
2 package uk.ac.ukc.iscream.filter;
3
4 //---IMPORTS---
5 import java.io.*;
6 import java.net.*;
7 import java.util.*;
8 import uk.ac.ukc.iscream.core.*;
9 import uk.ac.ukc.iscream.filter.*;
10 import uk.ac.ukc.iscream.xml.*;
11
12 /**
13 * Handle an incoming UDP packet as a separate thread.
14 *
15 * @author $Author$
16 * @version $Id$
17 */
18 public class FilterThread extends Thread{
19
20 //---FINAL ATTRIBUTES---
21
22 /**
23 * The current CVS revision of this class
24 */
25 public final String REVISION = "$Revision: 1.1 $";
26
27 //---STATIC METHODS---
28
29 //---CONSTRUCTORS---
30
31 // Class constructor. Obtains the byte[] from a DatagramPacket.
32 public FilterThread(DatagramPacket packet, Filter parent, Logger logger){
33 this.parent = parent;
34 this.rawPacket = packet.getData();
35 this.logger = logger;
36 }
37
38 // Class constructor for passing XML Strings.
39 public FilterThread(String xml, Filter parent, Logger logger){
40 this.parent = parent;
41 this.rawPacket = xml.getBytes();
42 }
43
44 //---PUBLIC METHODS---
45
46 public void run(){
47
48 // Get a string without any null characters in it.
49 String xml = new String(rawPacket);
50 if (xml.indexOf(0) != -1) {
51 xml = xml.substring(0, xml.indexOf(0));
52 }
53 else {
54 xml = xml.substring(0, xml.length());
55 }
56 //System.out.println(xml);
57
58 // Use my XMLPacketMaker to make an XMLPacket object.
59 XMLPacketMaker xmlPacketMaker = new XMLPacketMaker(xml, logger);
60 XMLPacket packet = xmlPacketMaker.createXMLPacket();
61
62 if (packet == null){
63 // A null XML packet was returned - don't pass it on.
64 logger.write(this.toString(), Logger.SYSMSG, "An XML UDP packet was sucessfully filtered from the system.");
65 return;
66 }
67
68 // Now do something with this XMLPacket!!!
69 // .... let's try this...
70 parent.receiveXML(xml);
71
72 }
73
74 /**
75 * Overrides the {@link java.lang.Object#toString() Object.toString()}
76 * method to provide clean logging (every class should have this).
77 *
78 * @return the name of this class and its CVS revision
79 */
80 public String toString() {
81 return this.getClass().getName() + "(" + REVISION.substring(11, REVISION.length() - 2) + ")";
82 }
83
84 //---PRIVATE METHODS---
85
86 //---ACCESSOR/MUTATOR METHODS---
87
88 //---ATTRIBUTES---
89
90 Filter parent;
91 byte[] rawPacket;
92 Logger logger;
93
94 //---STATIC ATTRIBUTES---
95
96 }