1 57 58 package org.apache.wsif.schema; 59 60 import java.io.Serializable ; 61 import java.util.ArrayList ; 62 import java.util.Vector ; 63 64 import javax.xml.namespace.QName ; 65 66 import org.apache.wsif.WSIFConstants; 67 import org.w3c.dom.Element ; 68 import org.w3c.dom.Node ; 69 import org.w3c.dom.NodeList ; 70 71 76 public class ComplexType extends SchemaType implements Serializable { 77 78 static final long serialVersionUID = 1L; 79 80 private boolean isAnArray = false; 81 private String name = ""; 82 private QName typeName = null; 83 private QName arrayType = null; 84 private int arrayDim = 0; 85 private ComplexContent complexContent = null; 86 private static final QName soapEncArray = 87 new QName (WSIFConstants.NS_URI_SOAP_ENC, "Array"); 88 private static final QName soapEncArrayType = 89 new QName (WSIFConstants.NS_URI_SOAP_ENC, "arrayType"); 90 private static final QName wsdlArrayType = 91 new QName (WSIFConstants.NS_URI_WSDL, "arrayType"); 92 ArrayList sequenceElements = new ArrayList (); 93 94 98 ComplexType(Element el, String tns) { 99 typeName = getAttributeQName(el, "name", tns); 100 if (typeName != null) { 101 name = typeName.getLocalPart(); 102 } 103 104 process(el, tns); 105 106 if (name.startsWith("ArrayOf")) { 107 if (complexContent != null) { 108 Restriction res = complexContent.getRestriction(); 109 if (res != null) { 110 QName base = res.getBase(); 111 if (soapEncArray.equals(base)) { 112 Attribute[] atts = res.getAttributes(); 113 if (atts != null && atts.length > 0) { 114 for (int i = 0; i < atts.length; i++) { 115 Attribute a = atts[i]; 116 if (a != null) { 117 QName ref = a.getXMLAttribute("ref"); 118 if (soapEncArrayType.equals(ref)) { 119 QName tempType = 120 a.getXMLAttribute(wsdlArrayType); 121 if (tempType != null) { 122 String ns = 123 tempType.getNamespaceURI(); 124 String lp = tempType.getLocalPart(); 125 int index = lp.lastIndexOf("[]"); 127 while(index != -1) { 128 lp = lp.substring(0, index); 129 arrayDim++; 130 index = lp.lastIndexOf("[]"); 131 } 132 arrayType = new QName (ns, lp); 133 } 134 break; 135 } 136 } 137 } 138 } else { 139 SequenceElement[] sels = res.getSequenceElements(); 140 if (sels != null && sels.length == 1) { 141 SequenceElement sel = sels[0]; 142 QName tempType = sel.getXMLAttribute("type"); 143 if (tempType != null) { 144 String ns = tempType.getNamespaceURI(); 145 String lp = tempType.getLocalPart(); 146 arrayType = new QName (ns, lp); 147 } 148 } 149 } 150 } 151 } 152 isAnArray = true; 153 } 154 } else { 155 } 156 } 157 158 161 public boolean isComplex() { 162 return true; 163 } 164 165 168 public boolean isArray() { 169 return isAnArray; 170 } 171 172 175 public QName getArrayType() { 176 return arrayType; 177 } 178 179 182 public int getArrayDimension() { 183 return arrayDim; 184 } 185 186 189 public QName getTypeName() { 190 return typeName; 191 } 192 193 197 public SequenceElement[] getSequenceElements() { 198 return (SequenceElement[]) sequenceElements.toArray( 199 new SequenceElement[sequenceElements.size()]); 200 } 201 202 private void process(Element el, String tns) { 203 NodeList children = el.getChildNodes(); 204 for (int i = 0; i < children.getLength(); i++) { 205 Node child = children.item(i); 206 if (child.getNodeType() == Node.ELEMENT_NODE) { 207 Element subEl = (Element ) child; 208 String elType = subEl.getLocalName(); 209 if (elType.equals("complexContent")) { 210 complexContent = new ComplexContent(subEl, tns); 211 } else if (elType.equals("sequence")) { 212 parseSequenceElements(subEl, tns); 213 } 214 } 215 } 216 } 217 218 private void parseSequenceElements(Element el, String tns) { 219 NodeList children = el.getChildNodes(); 220 for (int i = 0; i < children.getLength(); i++) { 221 Node child = children.item(i); 222 if (child.getNodeType() == Node.ELEMENT_NODE) { 223 Element subEl = (Element ) child; 224 String elType = subEl.getLocalName(); 225 if (elType.equals("element")) { 226 sequenceElements.add(new SequenceElement(subEl, tns)); 227 } 228 } 229 } 230 } 231 } 232 | Popular Tags |