1 |
|
//---PACKAGE DECLARATION--- |
2 |
< |
package uk.ac.ukc.iscream.xml; |
2 |
> |
package uk.ac.ukc.iscream.util; |
3 |
|
|
4 |
|
//---IMPORTS--- |
5 |
|
import java.io.*; |
32 |
|
//---CONSTRUCTORS--- |
33 |
|
|
34 |
|
// Constructor for accepting XML input. |
35 |
< |
public XMLPacketMaker (String xml, Logger logger) { |
36 |
< |
this.xml = xml; |
37 |
< |
this.logger = logger; |
35 |
> |
public XMLPacketMaker (String xml) { |
36 |
> |
_xml = xml; |
37 |
|
} |
38 |
|
|
39 |
|
//---PUBLIC METHODS--- |
48 |
|
try { |
49 |
|
|
50 |
|
// Parse the input |
51 |
< |
InputSource inputSource = new InputSource(new StringReader(xml)); |
51 |
> |
InputSource inputSource = new InputSource(new StringReader(_xml)); |
52 |
|
SAXParser saxParser = factory.newSAXParser(); |
53 |
|
saxParser.parse(inputSource, new XMLStringParser(packet)); |
54 |
|
|
55 |
|
} |
56 |
|
catch (Exception e) { |
57 |
< |
logger.write(this.toString(), Logger.WARNING, "An invalid XML UDP packet has been detected: "+packet.printAll()); |
58 |
< |
//t.printStackTrace(); |
57 |
> |
_logger.write(this.toString(), Logger.WARNING, e.toString()); |
58 |
> |
_logger.write(this.toString(), Logger.WARNING, "An invalid XML UDP packet has been detected: "+packet.printAll()); |
59 |
|
return null; |
60 |
|
} |
61 |
|
|
66 |
|
* Overrides the {@link java.lang.Object#toString() Object.toString()} |
67 |
|
* method to provide clean logging (every class should have this). |
68 |
|
* |
69 |
+ |
* This uses the uk.ac.ukc.iscream.util.NameFormat class |
70 |
+ |
* to format the toString() |
71 |
+ |
* |
72 |
|
* @return the name of this class and its CVS revision |
73 |
|
*/ |
74 |
|
public String toString() { |
75 |
< |
return this.getClass().getName() + "(" + REVISION.substring(11, REVISION.length() - 2) + ")"; |
75 |
> |
return FormatName.getName( |
76 |
> |
_name, |
77 |
> |
getClass().getName(), |
78 |
> |
REVISION); |
79 |
|
} |
80 |
|
|
81 |
|
//---PRIVATE METHODS--- |
84 |
|
|
85 |
|
//---ATTRIBUTES--- |
86 |
|
|
87 |
< |
String xml; |
88 |
< |
Logger logger; |
87 |
> |
/** |
88 |
> |
* Holds the xml |
89 |
> |
*/ |
90 |
> |
String _xml; |
91 |
> |
|
92 |
> |
/** |
93 |
> |
* This holds a reference to the |
94 |
> |
* system logger that is being used. |
95 |
> |
*/ |
96 |
> |
private Logger _logger = ReferenceManager.getInstance().getLogger(); |
97 |
> |
|
98 |
> |
/** |
99 |
> |
* This is the friendly identifier of the |
100 |
> |
* component this class is running in. |
101 |
> |
* eg, a Filter may be called "filter1", |
102 |
> |
* If this class does not have an owning |
103 |
> |
* component, a name from the configuration |
104 |
> |
* can be placed here. This name could also |
105 |
> |
* be changed to null for utility classes. |
106 |
> |
*/ |
107 |
> |
private String _name = null; |
108 |
|
|
109 |
|
//---STATIC ATTRIBUTES--- |
110 |
|
|