6 |
|
import java.net.*; |
7 |
|
import java.util.*; |
8 |
|
import uk.ac.ukc.iscream.core.*; |
9 |
+ |
import uk.ac.ukc.iscream.componentmanager.*; |
10 |
|
import uk.ac.ukc.iscream.filter.*; |
11 |
|
import uk.ac.ukc.iscream.util.*; |
12 |
|
|
35 |
|
//---CONSTRUCTORS--- |
36 |
|
|
37 |
|
/** |
38 |
< |
* Class constructor. |
38 |
> |
* Constructs an instance of a FilterThread |
39 |
> |
* |
40 |
> |
* @param queue the Queue this filter is using |
41 |
> |
* @param parent a CORBA reference to our parent filter |
42 |
|
*/ |
43 |
|
public FilterThread(Queue queue, Filter parent){ |
44 |
+ |
// set the Thread name |
45 |
+ |
setName("filter.FilterThread"); |
46 |
+ |
|
47 |
|
_parent = parent; |
48 |
|
_queue = queue; |
49 |
< |
_logger.write(toString(), Logger.DEBUG, "created"); |
49 |
> |
_logger.write(toString(), Logger.SYSINIT, "created"); |
50 |
|
} |
51 |
|
|
52 |
|
//---PUBLIC METHODS--- |
53 |
|
|
54 |
|
/** |
55 |
< |
* Runs the thread |
55 |
> |
* Runs the thread, getting data from the Queue and |
56 |
> |
* sending it on to the parent filter. |
57 |
|
*/ |
58 |
|
public void run(){ |
59 |
+ |
// setup the XMLPacketMaker |
60 |
+ |
XMLPacketMaker xmlPacketMaker = new XMLPacketMaker(); |
61 |
|
// get a queue for ourselves |
62 |
|
int n = _queue.getQueue(); |
63 |
< |
// keep this out here, saves recreating the object |
63 |
> |
// keep these out here, saves recreating the object |
64 |
|
String xml = null; |
65 |
|
while(true) { |
66 |
|
// get a String of xml |
80 |
|
xml = xml.substring(0, xml.length()); |
81 |
|
} |
82 |
|
|
83 |
+ |
// Bundle the XML all on one line (saves space and simplifies |
84 |
+ |
// the protocol between clientinterface and client). |
85 |
+ |
StringTokenizer tokenizer = new StringTokenizer(new String(xml), "\n"); |
86 |
+ |
xml = ""; |
87 |
+ |
while (tokenizer.hasMoreTokens()) { |
88 |
+ |
xml += tokenizer.nextToken(); |
89 |
+ |
} |
90 |
+ |
|
91 |
|
// Use XMLPacketMaker to make an XMLPacket object. |
92 |
< |
XMLPacketMaker xmlPacketMaker = new XMLPacketMaker(xml); |
93 |
< |
XMLPacket packet = xmlPacketMaker.createXMLPacket(); |
94 |
< |
|
95 |
< |
if(packet != null && PluginFilterManager.getInstance().runFilters(packet)) { |
96 |
< |
// packet is not null |
97 |
< |
// packet was not dropped by a plugin |
98 |
< |
// ... best pass it on ! |
92 |
> |
XMLPacket packet = null; |
93 |
> |
try { |
94 |
> |
packet = xmlPacketMaker.createXMLPacket(xml); |
95 |
> |
} catch(InvalidXMLException e) { |
96 |
> |
_logger.write(toString(), Logger.ERROR, "Invalid XML: "+e); |
97 |
> |
// skip the rest of this loop iteration |
98 |
> |
continue; |
99 |
> |
} |
100 |
> |
|
101 |
> |
// XMLPacket is ok, so run filters... |
102 |
> |
if(PluginFilterManager.getInstance().runFilters(packet)) { |
103 |
> |
// and pass it on... |
104 |
|
_parent.receiveXML(xml); |
105 |
|
} |
106 |
|
else { |
107 |
< |
// either we had a null, or a plugin dropped it |
107 |
> |
// ... or filtered it |
108 |
|
_logger.write(toString(), Logger.DEBUG, "An XML packet was sucessfully filtered from the system."); |
109 |
|
} |
110 |
|
} |