1
2
3
4
5
6 package net.kwfgrid.gwes.uiproxy.jdom;
7
8 import org.jaxen.*;
9 import org.jaxen.jdom.*;
10
11 import org.jdom.*;
12 import net.kwfgrid.gwes.uiproxy.SequenceBuffer;
13 import net.kwfgrid.gwes.uiproxy.BufferException;
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 public abstract class JDOMSequenceBuffer extends SequenceBuffer {
29 public static final String XPATH_SEQUENCE_NUMBER_PROPERTY_KEY = "JDOMSequenceBuffer.xpath_sequenceNumber";
30 public static final String XPATH_SHOULD_HANDLE_PROPERTY_KEY = "JDOMSequenceBuffer.xpath_shouldHandle";
31
32 XPath _xpath_shouldhandle;
33 XPath _xpath_sequencenumber;
34
35
36
37
38
39
40 public JDOMSequenceBuffer(String xpath) throws InstantiationException {
41 _xpath_shouldhandle = null;
42 _xpath_sequencenumber = null;
43 }
44
45 public synchronized void setProperty(String key, String value) throws BufferException {
46 if (XPATH_SEQUENCE_NUMBER_PROPERTY_KEY.equals(key)) {
47 try {
48 _xpath_sequencenumber = DocumentNavigator.getInstance().parseXPath(value);
49 } catch (Exception x) {
50 _exception = new BufferException(this, "Error parsing XPath expression "+value+" to access sequence numbers.", x);
51 }
52 } else if (XPATH_SHOULD_HANDLE_PROPERTY_KEY.equals(key)) {
53 try {
54 _xpath_shouldhandle = DocumentNavigator.getInstance().parseXPath(value);
55 } catch (Exception x) {
56 _exception = new BufferException(this, "Error parsing XPath expression "+value+" to determine message type.", x);
57 }
58 } else {
59 super.setProperty(key, value);
60 }
61 if (_exception!=null) throw _exception;
62 }
63
64
65
66
67
68 protected int getSequenceNumber(Object message) throws JaxenException, NumberFormatException, IllegalStateException {
69 if (_xpath_sequencenumber==null)
70 throw new IllegalStateException("Property JDOMSequenceBuffer.xpath_sequenceNumber not set.");
71
72 Element jdom = (Element)message;
73 String seq = _xpath_sequencenumber.stringValueOf(jdom);
74 return Integer.parseInt(seq);
75 }
76
77
78
79
80
81
82
83 protected boolean shouldHandle(Object message) throws JaxenException, IllegalStateException {
84 if (_xpath_shouldhandle==null)
85 throw new IllegalStateException("Property JDOMSequenceBuffer.xpath_shouldHandle not set.");
86
87 if (message instanceof Element) {
88 return _xpath_shouldhandle.booleanValueOf(message);
89 } else {
90 return false;
91 }
92 }
93 }