ReportHandler.java 2.43 KB
Newer Older
1
2
package eu.simstadt.nf;

3
import org.xml.sax.Attributes;
4
5
6
7
8
9
10
11
12
13
14
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;

/**
 * This SAX handler scans a nF XML status report instance and searches for the nF job id and the status of a
 * nF job.
 * 
 * @author Marcel Bruse
 */
public class ReportHandler extends DefaultHandler {

15
	/** The XML tag which tells you the status of a nF export job. */
16
17
	public static final String STATUS_TAG = "status";
	
18
19
20
21
22
23
	/** The XML tag which tells you the status of a nF import job. */
	public static final String RESULT_STATUS_TAG = "ResultStatus";
	
	/** The XML attribute which tells you the status of a nF import job. */
	public static final String STATUS_ATTRIBUTE = "status";
	
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
	/** The XML tag which holds the id of the nF job. */
	public static final String JOB_ID = "jobId";
	
	/** If there was a problem on the nF server, then this XML tag gives you some hints. */
	public static final String SERVICE_EXCEPTION_TAG = "ServiceException";
	
	/** The id of the status of the nF job. */
	public Integer statusId = null;
	
	/** The id of the nF job. */
	public Integer jobId = null; 
	
	/** If there was any problem, then you will find an exception message here. */
	public String serviceException = null;
	
	/** Scanned string will be stored here temporarily. */
	private String currentString;
	
42
43
44
45
46
47
48
49
	@Override
	public void startElement(String uri, String localName, String qName, Attributes attributes)
			throws SAXException {
		if (qName.equalsIgnoreCase(RESULT_STATUS_TAG)) {
			statusId = Integer.valueOf(attributes.getValue(STATUS_ATTRIBUTE));
		}
	}
	
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
	/**
	 * If a tag has been read, its contents will be tested here. If it contains either a status id, job id or
	 * service exception messege, then the contents will be stored in the appropriate member variable.
	 */
	@Override
	public void endElement(String uri, String localName, String qName) throws SAXException {
		if (qName.equalsIgnoreCase(STATUS_TAG)) {
			statusId = Integer.valueOf(currentString);
		} else if (qName.equalsIgnoreCase(SERVICE_EXCEPTION_TAG)) {
			serviceException = currentString;
		} else if (qName.equalsIgnoreCase(JOB_ID)) {
			jobId = Integer.valueOf(currentString);
		}
	}
	
	/**
	 * The scanner of the XML document.
	 * 
	 * @see DefaultHandler
	 */
	@Override
	public void characters(char[] ch, int start, int length) {
		currentString = new String(ch, start, length);
	}
	
}