1 16 17 package test.wsdl.sequence; 18 19 import org.apache.axis.utils.XMLUtils; 20 import org.w3c.dom.Document ; 21 import org.w3c.dom.Element ; 22 import org.w3c.dom.Node ; 23 import org.w3c.dom.NodeList ; 24 import org.w3c.dom.Text ; 25 26 33 public class SequenceService { 34 private String [] names = new String [] { "zero", 35 "one", 36 "two", 37 "three", 38 "four", 39 "five" }; 40 47 public Element [] testSequence(Element [] elems) throws Exception { 48 Element zero = null; 49 for (int i = 0; i < elems.length; i++) { 50 zero = findTheZero(elems[i]); 51 if (zero != null) 52 break; 53 } 54 55 Document retDoc = XMLUtils.newDocument(); 56 Element [] ret = new Element [1]; 57 ret[0] = retDoc.createElementNS("urn:SequenceTest", 58 "testSequenceResponse"); 59 boolean success = false; 60 61 Element resultElement; 62 63 if (zero != null) { 64 int i = 1; 66 Node sib = zero.getNextSibling(); 67 for (i = 1; i < names.length; i++) { 68 while ((sib != null) && !(sib instanceof Element )) 69 sib = sib.getNextSibling(); 70 71 if ((sib == null) || 72 !(names[i].equals(((Element )sib).getLocalName()))) 73 break; 74 75 sib = sib.getNextSibling(); 76 } 77 if (i == names.length) 78 success = true; 79 } 80 81 resultElement = retDoc.createElementNS(null,"return"); 82 83 String resultStr = "false"; 84 if (success) { 85 resultStr = "true"; 86 } 87 Text text = retDoc.createTextNode(resultStr); 88 resultElement.appendChild(text); 89 90 ret[0].appendChild(resultElement); 91 return ret; 92 } 93 94 99 private Element findTheZero(Element start) { 100 if (names[0].equals(start.getLocalName())) { 101 return start; 102 } 103 NodeList nl = start.getChildNodes(); 104 for (int i = 0; i < nl.getLength(); i++) { 105 Node node = nl.item(i); 106 if (node instanceof Element ) { 107 Element result = findTheZero((Element )node); 108 if (result != null) { 109 return result; 110 } 111 } 112 } 113 return null; 114 } 115 } 116 | Popular Tags |