01: package org.xdev.base.xssl.text.xml;
02:
03: import java.util.HashMap;
04: import java.util.List;
05:
06: import org.jaxen.jdom.JDOMXPath;
07: import org.jdom.Element;
08:
09: /**
10: * @author hneiper
11: *
12: * To change the template for this generated type comment go to
13: * Window - Preferences - Java - Code Generation - Code and Comments
14: */
15: public class XmlElementTest extends AbstractXmlSearch {
16:
17: public static final int LESS_THAN = 0;
18: public static final int GREATER_THAN = 1;
19: public static final int IS_NULL = 2;
20: public static final int IS_NOT_NULL = 3;
21:
22: /**
23: * @param id
24: */
25: public XmlElementTest(String id) {
26: super (id);
27: // TODO Auto-generated constructor stub
28: }
29:
30: /**
31: * @param id
32: * @param properties
33: */
34: public XmlElementTest(String id, HashMap properties) {
35: super (id, properties);
36: // TODO Auto-generated constructor stub
37: }
38:
39: protected Object searchXml(JDOMXPath xpath, Element elm)
40: throws Exception {
41: Object obj = xpath.evaluate(elm);
42:
43: this .logDebug("xpath object received: " + obj);
44:
45: if (obj instanceof Boolean) {
46:
47: this .setExecutionStatus(((Boolean) obj).booleanValue());
48:
49: } else if (null != obj && "false".equals(obj)) {
50:
51: this .setExecutionStatus(false);
52:
53: } else if (obj != null && obj instanceof List) {
54: List temp = (List) obj;
55:
56: int size = temp.size();
57:
58: int desiredSize = this .getIntegerProperty("eval-arg");
59:
60: switch (this .getIntegerProperty("eval-type")) {
61: case XmlElementTest.LESS_THAN:
62:
63: this .setExecutionStatus(size <= desiredSize);
64:
65: break;
66: case XmlElementTest.GREATER_THAN:
67:
68: this .setExecutionStatus(size >= desiredSize);
69:
70: break;
71: }
72: } else {
73: switch (this .getIntegerProperty("eval-type")) {
74: case XmlElementTest.IS_NULL:
75:
76: this.setExecutionStatus(obj == null);
77:
78: break;
79: case XmlElementTest.IS_NOT_NULL:
80:
81: this.setExecutionStatus(obj != null);
82:
83: break;
84: }
85: }
86:
87: return obj;
88: }
89: }
|