1 16 package org.apache.axis.deployment.wsdd; 17 18 import org.apache.axis.encoding.SerializationContext; 19 import org.apache.axis.utils.Messages; 20 import org.w3c.dom.Element ; 21 import org.w3c.dom.Node ; 22 import org.w3c.dom.NodeList ; 23 24 import javax.xml.namespace.QName ; 25 import java.io.IOException ; 26 import java.io.Serializable ; 27 import java.util.Vector ; 28 29 30 33 public abstract class WSDDElement 34 extends WSDDConstants 35 implements Serializable 36 { 37 private String name; 38 39 42 public WSDDElement() 43 { 44 } 45 46 51 public WSDDElement(Element e) 52 throws WSDDException 53 { 54 validateCandidateElement(e); 55 } 56 57 60 protected abstract QName getElementName(); 61 62 65 private void validateCandidateElement(Element e) 66 throws WSDDException 67 { 68 QName name = getElementName(); 69 70 if ((null == e) || (null == e.getNamespaceURI()) 71 || (null == e.getLocalName()) 72 ||!e.getNamespaceURI().equals(name.getNamespaceURI()) 73 ||!e.getLocalName().equals(name.getLocalPart())) { 74 throw new WSDDException(Messages.getMessage("invalidWSDD00", 75 e.getLocalName(), 76 name.getLocalPart())); 77 } 78 } 79 80 public Element getChildElement(Element e, String name) 81 { 82 Element [] elements = getChildElements(e, name); 83 if (elements.length == 0) 84 return null; 85 return elements[0]; 86 } 87 88 public Element [] getChildElements(Element e, String name) 89 { 90 NodeList nl = e.getChildNodes(); 91 Vector els = new Vector (); 92 93 for (int i = 0; i < nl.getLength(); i++) { 94 Node thisNode = nl.item(i); 95 if (!(thisNode instanceof Element )) 96 continue; 97 98 Element el = (Element )thisNode; 99 if (el.getLocalName().equals(name)) { 100 els.add(el); 101 } 102 } 103 104 Element [] elements = new Element [els.size()]; 105 els.toArray(elements); 106 107 return elements; 108 } 109 110 113 public abstract void writeToContext(SerializationContext context) 114 throws IOException ; 115 116 } 117 | Popular Tags |